Skip to content

Commit

Permalink
- allow front matter on any Blade template
Browse files Browse the repository at this point in the history
  • Loading branch information
horuskol committed Aug 13, 2023
1 parent b95c52c commit 21a6c94
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/Blade/DefaultEngine.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace SavvyWombat\Caxton\Blade;

use Illuminate\Contracts\View\Engine;
use Illuminate\View\Engines\CompilerEngine;
use Illuminate\View\ViewException;
use League\CommonMark\Exception\CommonMarkException;
use SavvyWombat\Caxton\Markdown\MarkdownConverter;

class DefaultEngine implements Engine
{
public function __construct(
protected CompilerEngine $blade,
protected MarkdownConverter $markdown,
) {
//
}

/**
* @param string $path
* @param array $data
* @return string
* @throws ViewException
* @throws CommonMarkException
*/
public function get($path, array $data = []): string
{
return $this->markdown->extractContent($this->blade->get($path, $data));
}
}
2 changes: 1 addition & 1 deletion src/Blade/ViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function __construct()

$compilerEngine = new CompilerEngine($bladeCompiler);

$viewResolver->register('blade', fn() => $compilerEngine);
$viewResolver->register('blade', fn() => new DefaultEngine($compilerEngine, new MarkdownConverter()));
$viewResolver->register('markdown', fn() => new MarkdownEngine($compilerEngine, new MarkdownConverter()));

$viewFinder = new FileViewFinder(
Expand Down

0 comments on commit 21a6c94

Please sign in to comment.