-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
PugBladeCompiler.php
67 lines (58 loc) · 1.7 KB
/
PugBladeCompiler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
namespace Bkwld\LaravelPug;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Blade;
use Illuminate\View\Compilers\BladeCompiler;
class PugBladeCompiler extends BladeCompiler implements PugHandlerInterface
{
use PugHandlerTrait;
/**
* Create a new compiler instance.
*
* @param array $pugTarget
* @param Filesystem $files
* @param array $config
* @param string $defaultCachePath
*/
public function __construct(
array $pugTarget,
Filesystem $files,
array $config,
$defaultCachePath = null,
$compiler = null
) {
$this->construct($pugTarget, $files, $config, $defaultCachePath, $compiler);
}
/**
* Copy custom blade directives.
*/
protected function enableBladeDirectives(): void
{
/** @var \Illuminate\View\Compilers\BladeCompiler $blade */
$blade = Blade::getFacadeRoot();
if ($blade && method_exists($blade, 'getCustomDirectives')) {
foreach ($blade->getCustomDirectives() as $name => $directive) {
$this->directive($name, $directive);
}
}
}
/**
* Compile the view at the given path.
*
* @param string $path
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function compile($path = null): void
{
$app = Blade::getFacadeApplication();
if (isset($app['view'])) {
$this->enableBladeDirectives();
}
$this->footer = [];
$compiler = $this->compiler instanceof BladeCompiler ? $this->compiler : $this;
$this->compileWith($path, [$compiler, 'compileString']);
}
}