-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathStyleGuideControllerProvider.php
More file actions
77 lines (66 loc) · 1.88 KB
/
Copy pathStyleGuideControllerProvider.php
File metadata and controls
77 lines (66 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* @file StyleGuideControllerProvider.php
*/
namespace PatternKit;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Mni\FrontYAML\Parser;
/**
* Class StyleGuideControllerProvider
*
* @package PatternKit
*/
class StyleGuideControllerProvider implements ControllerProviderInterface
{
/**
* Creates a new controller based on the default route.
*
* @param \Silex\Application $app
*
* @return mixed
*/
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
$controllers->get(
'/',
function ($pattern) use ($app) {
return $this->renderer($app, $pattern);
}
)->value('pattern', "index")->bind('styleguide-home');
$controllers->get(
'/{pattern}',
function ($pattern) use ($app) {
return $this->renderer($app, $pattern);
}
)->bind('styleguide');
return $controllers;
}
/**
* Renders the style guide requested.
*
* @param Application $app
* Reference to the application object.
* @param string $pattern
* The pattern of interest.
*
* @return mixed
* Rendered output.
*/
public function renderer(Application $app, $pattern)
{
$sg_path = get_asset_path($pattern, 'sg');
$sg_file = file_get_contents('file://'.realpath($sg_path));
$parser = new Parser();
$sg_data = $parser->parse($sg_file);
if (isset($app['config'])) {
$data["app_config"] = $app['config'];
}
$data['secondary_nav'] = getDocNav($pattern);
$data['nav'] = getNav($pattern);
$data['sg_yaml'] = $sg_data->getYAML();
$data['sg_content'] = $sg_data->getContent();
return $app['twig']->render("display-sg.twig", $data);
}
}