Skip to content

Commit

Permalink
Merge pull request #22 from tightenco/aw-markdown-fix
Browse files Browse the repository at this point in the history
Inject markdown content as variable instead of rendering flat into Blade template, resolves #21
  • Loading branch information
adamwathan committed Mar 9, 2016
2 parents b2f14a7 + 794afca commit 9f510d7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Handlers/MarkdownHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ public function render($file, $data)
{
$document = $this->parseFile($file);

$bladeContent = $this->compileToBlade($document);
$data = array_merge($data, $document->getYAML(), [
'__jigsawMarkdownContent' => $document->getContent()
]);

$data = array_merge($data, $document->getYAML());
$bladeContent = $this->compileToBlade($document->getYAML()['extends'], $document->getYAML()['section']);

return $this->temporaryFilesystem->put($bladeContent, function ($path) use ($data) {
return $this->viewFactory->file($path, $data)->render();
Expand All @@ -51,14 +53,12 @@ private function parseFile($file)
return $this->parser->parse($file->getContents());
}

private function compileToBlade($document)
private function compileToBlade($extends, $section)
{
$frontmatter = $document->getYAML();

return collect([
sprintf("@extends('%s')", $frontmatter['extends']),
sprintf("@section('%s')", $frontmatter['section']),
$document->getContent(),
sprintf("@extends('%s')", $extends),
sprintf("@section('%s')", $section),
'{!! $__jigsawMarkdownContent !!}',
'@endsection',
])->implode("\n");
}
Expand Down

0 comments on commit 9f510d7

Please sign in to comment.