Passed
Push — master ( 25efb9...c70e91 )
by Caen
04:09 queued 12s
created

BladePage   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A compile() 0 3 1
A getBladeView() 0 3 1
A toArray() 0 4 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Pages;
6
7
use Hyde\Markdown\Models\FrontMatter;
8
use Hyde\Pages\Concerns\HydePage;
9
use Illuminate\Support\Facades\View;
10
use function array_merge;
11
12
/**
13
 * Page class for Blade pages.
14
 *
15
 * Blade pages are stored in the _pages directory and using the .blade.php extension.
16
 * They will be compiled using the Laravel Blade engine the _site/ directory.
17
 *
18
 * @see https://hydephp.com/docs/master/static-pages#creating-blade-pages
19
 * @see https://laravel.com/docs/master/blade
20
 */
21
class BladePage extends HydePage
22
{
23
    public static string $sourceDirectory = '_pages';
24
    public static string $outputDirectory = '';
25
    public static string $fileExtension = '.blade.php';
26
27
    /**
28
     * The name of the Blade View to compile. Commonly stored in _pages/{$identifier}.blade.php.
29
     */
30
    public string $view;
31
32
    public function __construct(string $view = '', FrontMatter|array $matter = [])
33
    {
34
        parent::__construct($view, $matter);
35
        $this->view = $view;
36
    }
37
38
    /** @inheritDoc */
39
    public function getBladeView(): string
40
    {
41
        return $this->view;
42
    }
43
44
    /** @inheritDoc */
45
    public function compile(): string
46
    {
47
        return View::make($this->getBladeView())->render();
48
    }
49
50
    public function toArray(): array
51
    {
52
        return array_merge(parent::toArray(), [
53
            'view' => $this->view,
54
        ]);
55
    }
56
}
57