File tree Expand file tree Collapse file tree 5 files changed +40
-8
lines changed
src/PatternLab/PatternEngine/Twig Expand file tree Collapse file tree 5 files changed +40
-8
lines changed Original file line number Diff line number Diff line change 31
31
"patternlab" : {
32
32
"config" : [
33
33
{
34
- "patternExtension" : " twig"
34
+ "patternExtension" : " twig" ,
35
+ "twigDebug" : false ,
35
36
"twigDefaultDateFormat" : " " ,
36
37
"twigDefaultIntervalFormat" : " " ,
37
38
"twigMacroExt" : " macro"
Original file line number Diff line number Diff line change @@ -23,11 +23,16 @@ class FilesystemLoader extends Loader {
23
23
*/
24
24
public function __construct ($ options = array ()) {
25
25
26
+ // set-up the loader
27
+ $ twigDebug = Config::getOption ("twigDebug " );
26
28
$ macroPath = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_macros " ;
27
29
$ twigLoader = new \Twig_Loader_Filesystem (array ($ options ["templatePath " ],$ options ["partialsPath " ],$ macroPath ));
28
- $ this ->instance = new \Twig_Environment ($ twigLoader );
29
- $ this ->instance = TwigUtil::loadMacros ($ this ->instance , "filesystem " );
30
+ $ this ->instance = new \Twig_Environment ($ twigLoader , array ("debug " => $ twigDebug ));
31
+
32
+ // customize the loader
30
33
$ this ->instance = TwigUtil::loadDateFormats ();
34
+ $ this ->instance = TwigUtil::loadDebug ();
35
+ $ this ->instance = TwigUtil::loadMacros ($ this ->instance , "filesystem " );
31
36
32
37
}
33
38
Original file line number Diff line number Diff line change @@ -26,16 +26,20 @@ class PatternLoader extends Loader {
26
26
*/
27
27
public function __construct ($ options = array ()) {
28
28
29
- //default var
29
+ // set-up the loader
30
+ $ twigDebug = Config::getOption ("twigDebug " );
30
31
$ patternSourceDir = Config::getOption ("patternSourceDir " );
31
32
$ macroPath = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_macros " ;
32
33
$ patternPartialLoader = new Twig_Loader_PatternPartialLoader ($ patternSourceDir ,array ("patternPaths " => $ options ["patternPaths " ]));
33
34
$ patternStringLoader = new \Twig_Loader_String ();
34
35
$ macroLoader = new \Twig_Loader_Filesystem (array ($ macroPath ));
35
36
$ twigLoader = new \Twig_Loader_Chain (array ($ patternPartialLoader , $ macroLoader , $ patternStringLoader ));
36
- $ this ->instance = new \Twig_Environment ($ twigLoader );
37
- $ this ->instance = TwigUtil::loadMacros ($ this ->instance , "pattern " );
37
+ $ this ->instance = new \Twig_Environment ($ twigLoader , array ("debug " => $ twigDebug ));
38
+
39
+ // customize the loader
38
40
$ this ->instance = TwigUtil::loadDateFormats ();
41
+ $ this ->instance = TwigUtil::loadDebug ();
42
+ $ this ->instance = TwigUtil::loadMacros ($ this ->instance , "pattern " );
39
43
40
44
}
41
45
Original file line number Diff line number Diff line change @@ -23,13 +23,18 @@ class StringLoader extends Loader {
23
23
*/
24
24
public function __construct ($ options = array ()) {
25
25
26
+ // set-up the loader
27
+ $ twigDebug = Config::getOption ("twigDebug " );
26
28
$ macroPath = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_macros " ;
27
29
$ macroLoader = new \Twig_Loader_Filesystem (array ($ macroPath ));
28
30
$ stringLoader = new \Twig_Loader_String ();
29
31
$ twigLoader = new \Twig_Loader_Chain (array ($ macroLoader , $ stringLoader ));
30
- $ this ->instance = new \Twig_Environment ($ twigLoader );
31
- $ this ->instance = TwigUtil::loadMacros ($ this ->instance , "string " );
32
+ $ this ->instance = new \Twig_Environment ($ twigLoader , array ("debug " => $ twigDebug ));
33
+
34
+ // customize the loader
32
35
$ this ->instance = TwigUtil::loadDateFormats ();
36
+ $ this ->instance = TwigUtil::loadDebug ();
37
+ $ this ->instance = TwigUtil::loadMacros ($ this ->instance , "string " );
33
38
34
39
}
35
40
Original file line number Diff line number Diff line change @@ -34,6 +34,23 @@ public static function loadDateFormats($instance) {
34
34
}
35
35
36
36
return $ instance ;
37
+
38
+ }
39
+
40
+ /**
41
+ * Enable the debug options for Twig
42
+ * @param {Instance} an instance of the twig engine
43
+ *
44
+ * @return {Instance} an instance of the twig engine
45
+ */
46
+ public static function loadDebug ($ instance ) {
47
+
48
+ if (Config::getOption ("twigDebug " )) {
49
+ $ twig ->addExtension (new Twig_Extension_Debug ());
50
+ }
51
+
52
+ return $ instance ;
53
+
37
54
}
38
55
39
56
/**
You can’t perform that action at this time.
0 commit comments