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()) {
66
66
67
67
// add the paths to the filesystem loader if the paths existed
68
68
if (count ($ filesystemLoaderPaths ) > 0 ) {
69
- $ loaders [] = new \Twig_Loader_Filesystem ($ filesystemLoaderPaths );
69
+ $ filesystemLoader = new \Twig_Loader_Filesystem ($ filesystemLoaderPaths );
70
+ $ loaders [] = TwigUtil::addPaths ($ filesystemLoader , $ patternSourceDir );
70
71
}
71
72
72
73
$ loaders [] = new \Twig_Loader_String ();
Original file line number Diff line number Diff line change 18
18
19
19
class TwigUtil {
20
20
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
+ }
21
41
/**
22
42
* Load custom date formats for Twig
23
43
* @param {Instance} an instance of the twig engine
You can’t perform that action at this time.
0 commit comments