Skip to content

Commit

Permalink
Merge single use trait HasTableOfContents into DocumentationPage class
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Aug 26, 2022
1 parent 8b63044 commit de05d03
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
20 changes: 0 additions & 20 deletions packages/framework/src/Concerns/HasTableOfContents.php

This file was deleted.

11 changes: 9 additions & 2 deletions packages/framework/src/Models/Pages/DocumentationPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Hyde\Framework\Models\Pages;

use Hyde\Framework\Actions\GeneratesSidebarTableOfContents;
use Hyde\Framework\Concerns\FrontMatter\Schemas\DocumentationPageSchema;
use Hyde\Framework\Concerns\HasTableOfContents;
use Hyde\Framework\Contracts\AbstractMarkdownPage;
use Hyde\Framework\Contracts\RouteContract;
use Hyde\Framework\Models\FrontMatter;
Expand All @@ -13,7 +13,6 @@
class DocumentationPage extends AbstractMarkdownPage
{
use DocumentationPageSchema;
use HasTableOfContents;

public static string $sourceDirectory = '_docs';
public static string $outputDirectory = 'docs';
Expand Down Expand Up @@ -52,4 +51,12 @@ public static function hasTableOfContents(): bool
{
return config('docs.table_of_contents.enabled', true);
}

/**
* Generate Table of Contents as HTML from a Markdown document body.
*/
public function getTableOfContents(): string
{
return (new GeneratesSidebarTableOfContents($this->markdown))->execute();
}
}
13 changes: 7 additions & 6 deletions packages/framework/tests/Unit/HasTableOfContentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

namespace Hyde\Framework\Testing\Unit;

use Hyde\Framework\Concerns\HasTableOfContents;
use Hyde\Framework\Models\Markdown;
use Hyde\Framework\Models\Pages\DocumentationPage;
use Hyde\Testing\TestCase;

/**
* Class HasTableOfContentsTest.
*
* @covers \Hyde\Framework\Concerns\HasTableOfContents
* @covers \Hyde\Framework\Models\Pages\DocumentationPage
*
* @see \Hyde\Framework\Testing\Feature\Actions\GeneratesSidebarTableOfContentsTest
*/
class HasTableOfContentsTest extends TestCase
{
use HasTableOfContents;

public function testConstructorCreatesTableOfContentsString()
{
$this->markdown = '## Title';
$this->assertEquals('<ul class="table-of-contents"><li><a href="#title">Title</a></li></ul>', str_replace("\n", '', $this->getTableOfContents()));
$page = new DocumentationPage();

$page->markdown = new Markdown('## Title');
$this->assertEquals('<ul class="table-of-contents"><li><a href="#title">Title</a></li></ul>', str_replace("\n", '', $page->getTableOfContents()));
}
}

0 comments on commit de05d03

Please sign in to comment.