1616use \PatternLab \PatternData ;
1717use \PatternLab \Parsers \Documentation ;
1818use \PatternLab \Timer ;
19+ use \PatternLab \Data ;
20+ use \PatternLab \PatternData \Exporters \PatternPathSrcExporter ;
21+ use \PatternLab \PatternEngine ;
1922
2023class DocumentationRule extends \PatternLab \PatternData \Rule {
2124
@@ -49,8 +52,7 @@ public function run($depth, $ext, $path, $pathName, $name) {
4952
5053 // parse data
5154 $ text = file_get_contents ($ patternSourceDir .DIRECTORY_SEPARATOR .$ pathName );
52- list ($ yaml ,$ markdown ) = Documentation::parse ($ text );
53-
55+
5456 // grab the title and unset it from the yaml so it doesn't get duped in the meta
5557 if (isset ($ yaml ["title " ])) {
5658 $ title = $ yaml ["title " ];
@@ -73,7 +75,34 @@ public function run($depth, $ext, $path, $pathName, $name) {
7375
7476 $ category = ($ patternSubtypeDoc ) ? "patternSubtype " : "pattern " ;
7577 $ patternStoreKey = ($ patternSubtypeDoc ) ? $ docPartial ."-plsubtype " : $ docPartial ;
76-
78+
79+ /**
80+ * Setup the Pattern Loader so we can pre-render template markup used
81+ * in our markdown files, prior to any markup getting parsed.
82+ * Taken from Builder.php
83+ */
84+ $ ppdExporter = new PatternPathSrcExporter ();
85+ $ patternPathSrc = $ ppdExporter ->run ();
86+ $ options = array ();
87+ $ options ["patternPaths " ] = $ patternPathSrc ;
88+ $ patternEngineBasePath = PatternEngine::getInstance ()->getBasePath ();
89+ $ patternLoaderClass = $ patternEngineBasePath . "\Loaders\PatternLoader " ;
90+ $ patternLoader = new $ patternLoaderClass ($ options );
91+
92+
93+ // Setup the default pattern data.
94+ $ data = Data::getPatternSpecificData ($ patternStoreKey );
95+
96+ // Render the markdown content as a pattern, piping in the pattern-specific data from above.
97+ $ text = $ patternLoader ->render (array (
98+ "pattern " => $ text ,
99+ "data " => $ data
100+ ));
101+
102+ // Finally parse the resulting content as normal markup; continue as usual.
103+ list ($ yaml ,$ markdown ) = Documentation::parse ($ text );
104+
105+
77106 $ patternStoreData = array ("category " => $ category ,
78107 "desc " => trim ($ markdown ),
79108 "descExists " => true ,
0 commit comments