File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
src/PatternLab/PatternEngine/Twig Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,8 @@ public function __construct($options = array()) {
6666
6767 // add the paths to the filesystem loader if the paths existed
6868 if (count ($ filesystemLoaderPaths ) > 0 ) {
69- $ loaders [] = new \Twig_Loader_Filesystem ($ filesystemLoaderPaths );
69+ $ filesystemLoader = new \Twig_Loader_Filesystem ($ filesystemLoaderPaths );
70+ $ loaders [] = TwigUtil::addPaths ($ filesystemLoader , $ patternSourceDir );
7071 }
7172
7273 $ loaders [] = new \Twig_Loader_String ();
Original file line number Diff line number Diff line change 1818
1919class TwigUtil {
2020
21+ /**
22+ * Registering each directory under `_patterns/` as a namespace. For example, `_patterns/00-atoms/` as `@atoms`
23+ * @param {Instance} an instance of the filesystem Loader
24+ * @param {String} the path to the pattern directory
25+ *
26+ * @return {Instance} an instance of the filesystem Loader
27+ */
28+ public static function addPaths ($ filesystemLoader , $ patternSourceDir ) {
29+
30+ $ finder = new Finder ();
31+ $ finder ->directories ()->depth (0 )->in ($ patternSourceDir );
32+ foreach ($ finder as $ file ) {
33+ $ patternBits = explode ("- " ,$ file ->getRelativePathName (),2 );
34+ $ patternTypePath = (((int )$ patternBits [0 ] != 0 ) || ($ patternBits [0 ] == '00 ' )) ? $ patternBits [1 ] : $ pattern ;
35+ $ filesystemLoader ->addPath ($ file ->getPathName (), $ patternTypePath );
36+ }
37+
38+ return $ filesystemLoader ;
39+
40+ }
2141 /**
2242 * Load custom date formats for Twig
2343 * @param {Instance} an instance of the twig engine
You can’t perform that action at this time.
0 commit comments