Skip to content

Commit 9bbf4f4

Browse files
authored
Merge pull request #430 from hydephp/organize-and-restructure-code
Merge single use trait HasTableOfContents into DocumentationPage class
2 parents 9f91a20 + de05d03 commit 9bbf4f4

File tree

3 files changed

+16
-28
lines changed

3 files changed

+16
-28
lines changed

packages/framework/src/Concerns/HasTableOfContents.php

-20
This file was deleted.

packages/framework/src/Models/Pages/DocumentationPage.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Hyde\Framework\Models\Pages;
44

5+
use Hyde\Framework\Actions\GeneratesSidebarTableOfContents;
56
use Hyde\Framework\Concerns\FrontMatter\Schemas\DocumentationPageSchema;
6-
use Hyde\Framework\Concerns\HasTableOfContents;
77
use Hyde\Framework\Contracts\AbstractMarkdownPage;
88
use Hyde\Framework\Contracts\RouteContract;
99
use Hyde\Framework\Models\FrontMatter;
@@ -13,7 +13,6 @@
1313
class DocumentationPage extends AbstractMarkdownPage
1414
{
1515
use DocumentationPageSchema;
16-
use HasTableOfContents;
1716

1817
public static string $sourceDirectory = '_docs';
1918
public static string $outputDirectory = 'docs';
@@ -52,4 +51,12 @@ public static function hasTableOfContents(): bool
5251
{
5352
return config('docs.table_of_contents.enabled', true);
5453
}
54+
55+
/**
56+
* Generate Table of Contents as HTML from a Markdown document body.
57+
*/
58+
public function getTableOfContents(): string
59+
{
60+
return (new GeneratesSidebarTableOfContents($this->markdown))->execute();
61+
}
5562
}

packages/framework/tests/Unit/HasTableOfContentsTest.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,24 @@
22

33
namespace Hyde\Framework\Testing\Unit;
44

5-
use Hyde\Framework\Concerns\HasTableOfContents;
5+
use Hyde\Framework\Models\Markdown;
6+
use Hyde\Framework\Models\Pages\DocumentationPage;
67
use Hyde\Testing\TestCase;
78

89
/**
910
* Class HasTableOfContentsTest.
1011
*
11-
* @covers \Hyde\Framework\Concerns\HasTableOfContents
12+
* @covers \Hyde\Framework\Models\Pages\DocumentationPage
1213
*
1314
* @see \Hyde\Framework\Testing\Feature\Actions\GeneratesSidebarTableOfContentsTest
1415
*/
1516
class HasTableOfContentsTest extends TestCase
1617
{
17-
use HasTableOfContents;
18-
1918
public function testConstructorCreatesTableOfContentsString()
2019
{
21-
$this->markdown = '## Title';
22-
$this->assertEquals('<ul class="table-of-contents"><li><a href="#title">Title</a></li></ul>', str_replace("\n", '', $this->getTableOfContents()));
20+
$page = new DocumentationPage();
21+
22+
$page->markdown = new Markdown('## Title');
23+
$this->assertEquals('<ul class="table-of-contents"><li><a href="#title">Title</a></li></ul>', str_replace("\n", '', $page->getTableOfContents()));
2324
}
2425
}

0 commit comments

Comments
 (0)