Skip to content

Turbo-charge Markdown Docs by Enabling Pattern Engine Templates To Be Used #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/PatternLab/PatternData/Rules/DocumentationRule.php
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
use \PatternLab\PatternData;
use \PatternLab\Parsers\Documentation;
use \PatternLab\Timer;
use \PatternLab\Data;

class DocumentationRule extends \PatternLab\PatternData\Rule {

@@ -49,7 +50,6 @@ public function run($depth, $ext, $path, $pathName, $name) {

// parse data
$text = file_get_contents($patternSourceDir.DIRECTORY_SEPARATOR.$pathName);
list($yaml,$markdown) = Documentation::parse($text);

// grab the title and unset it from the yaml so it doesn't get duped in the meta
if (isset($yaml["title"])) {
@@ -73,6 +73,20 @@ public function run($depth, $ext, $path, $pathName, $name) {

$category = ($patternSubtypeDoc) ? "patternSubtype" : "pattern";
$patternStoreKey = ($patternSubtypeDoc) ? $docPartial."-plsubtype" : $docPartial;

//Setup the Pattern Loader so we can pre-render template markup used in our markdown files, prior to being rendered in Markdown.
$patternEngineBasePath = \PatternLab\PatternEngine::getInstance()->getBasePath();
$patternLoaderClass = $patternEngineBasePath."\Loaders\PatternLoader";
$patternLoader = new $patternLoaderClass($options);

//Setup the default pattern data.
$data = Data::getPatternSpecificData($patternStoreKey);

//Render the markdown content as a pattern, piping in the pattern-specific data from above.
$text = $patternLoader->render(array("pattern" => $text, "data" => $data));

//Finally parse the resulting content as normal markup; continue as usual.
list($yaml,$markdown) = Documentation::parse($text);

$patternStoreData = array("category" => $category,
"desc" => trim($markdown),