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 3131 "patternlab" : {
3232 "config" : [
3333 {
34- "patternExtension" : " twig"
34+ "patternExtension" : " twig" ,
35+ "twigDebug" : false ,
3536 "twigDefaultDateFormat" : " " ,
3637 "twigDefaultIntervalFormat" : " " ,
3738 "twigMacroExt" : " macro"
Original file line number Diff line number Diff line change @@ -23,11 +23,16 @@ class FilesystemLoader extends Loader {
2323 */
2424 public function __construct ($ options = array ()) {
2525
26+ // set-up the loader
27+ $ twigDebug = Config::getOption ("twigDebug " );
2628 $ macroPath = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_macros " ;
2729 $ 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
3033 $ this ->instance = TwigUtil::loadDateFormats ();
34+ $ this ->instance = TwigUtil::loadDebug ();
35+ $ this ->instance = TwigUtil::loadMacros ($ this ->instance , "filesystem " );
3136
3237 }
3338
Original file line number Diff line number Diff line change @@ -26,16 +26,20 @@ class PatternLoader extends Loader {
2626 */
2727 public function __construct ($ options = array ()) {
2828
29- //default var
29+ // set-up the loader
30+ $ twigDebug = Config::getOption ("twigDebug " );
3031 $ patternSourceDir = Config::getOption ("patternSourceDir " );
3132 $ macroPath = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_macros " ;
3233 $ patternPartialLoader = new Twig_Loader_PatternPartialLoader ($ patternSourceDir ,array ("patternPaths " => $ options ["patternPaths " ]));
3334 $ patternStringLoader = new \Twig_Loader_String ();
3435 $ macroLoader = new \Twig_Loader_Filesystem (array ($ macroPath ));
3536 $ 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
3840 $ this ->instance = TwigUtil::loadDateFormats ();
41+ $ this ->instance = TwigUtil::loadDebug ();
42+ $ this ->instance = TwigUtil::loadMacros ($ this ->instance , "pattern " );
3943
4044 }
4145
Original file line number Diff line number Diff line change @@ -23,13 +23,18 @@ class StringLoader extends Loader {
2323 */
2424 public function __construct ($ options = array ()) {
2525
26+ // set-up the loader
27+ $ twigDebug = Config::getOption ("twigDebug " );
2628 $ macroPath = Config::getOption ("sourceDir " ).DIRECTORY_SEPARATOR ."_macros " ;
2729 $ macroLoader = new \Twig_Loader_Filesystem (array ($ macroPath ));
2830 $ stringLoader = new \Twig_Loader_String ();
2931 $ 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
3235 $ this ->instance = TwigUtil::loadDateFormats ();
36+ $ this ->instance = TwigUtil::loadDebug ();
37+ $ this ->instance = TwigUtil::loadMacros ($ this ->instance , "string " );
3338
3439 }
3540
Original file line number Diff line number Diff line change @@ -34,6 +34,23 @@ public static function loadDateFormats($instance) {
3434 }
3535
3636 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+
3754 }
3855
3956 /**
You can’t perform that action at this time.
0 commit comments