Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| MarkdownPageParser | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| execute | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Hyde\Framework\Models\Parsers; |
| 4 | |
| 5 | use Hyde\Framework\Contracts\AbstractPageParser; |
| 6 | use Hyde\Framework\Hyde; |
| 7 | use Hyde\Framework\Models\MarkdownPage; |
| 8 | use Hyde\Framework\Services\MarkdownFileService; |
| 9 | |
| 10 | /** |
| 11 | * Parses a Markdown file into a MarkdownPage object using the MarkdownDocument intermediary. |
| 12 | */ |
| 13 | class MarkdownPageParser extends AbstractPageParser |
| 14 | { |
| 15 | protected string $pageModel = MarkdownPage::class; |
| 16 | protected string $slug; |
| 17 | |
| 18 | public string $title; |
| 19 | public string $body; |
| 20 | |
| 21 | public function execute(): void |
| 22 | { |
| 23 | $document = (new MarkdownFileService( |
| 24 | Hyde::getMarkdownPagePath("/$this->slug.md") |
| 25 | ))->get(); |
| 26 | |
| 27 | $this->title = $document->findTitleForDocument(); |
| 28 | |
| 29 | $this->body = $document->body; |
| 30 | } |
| 31 | |
| 32 | public function get(): MarkdownPage |
| 33 | { |
| 34 | return new MarkdownPage( |
| 35 | matter: [], |
| 36 | body: $this->body, |
| 37 | title: $this->title, |
| 38 | slug: $this->slug |
| 39 | ); |
| 40 | } |
| 41 | } |