Skip to content

Commit

Permalink
Merge pull request #974 from hydephp/create-helper-to-get-the-documen…
Browse files Browse the repository at this point in the history
…tation-page-home-route-name

Create helper to get the documentation page home route name
  • Loading branch information
caendesilva committed Feb 11, 2023
2 parents c3febd1 + 392c900 commit 6dd3cd7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
Expand Up @@ -131,7 +131,7 @@ private function searchForLabelInConfig(): ?string
{
return Arr::get(config('hyde.navigation.labels', [
'index' => 'Home',
'docs/index' => 'Docs',
DocumentationPage::homeRouteName() => 'Docs',
]), $this->routeKey);
}

Expand Down
Expand Up @@ -46,6 +46,6 @@ public function getItemsInGroup(?string $group): Collection

protected static function shouldItemBeHidden(NavItem $item): bool
{
return parent::shouldItemBeHidden($item) || $item->getRoute()?->is('docs/index');
return parent::shouldItemBeHidden($item) || $item->getRoute()?->is(DocumentationPage::homeRouteName());
}
}
Expand Up @@ -81,6 +81,6 @@ protected static function dropdownsEnabled(): bool
protected static function shouldItemBeHidden(NavItem $item): bool
{
return parent::shouldItemBeHidden($item) ||
$item->getRoute()?->getPage() instanceof DocumentationPage && ! $item->getRoute()->is('docs/index');
$item->getRoute()?->getPage() instanceof DocumentationPage && ! $item->getRoute()->is(DocumentationPage::homeRouteName());
}
}
7 changes: 6 additions & 1 deletion packages/framework/src/Pages/DocumentationPage.php
Expand Up @@ -26,7 +26,12 @@ class DocumentationPage extends BaseMarkdownPage

public static function home(): ?Route
{
return Route::get(static::$outputDirectory.'/index');
return Route::get(static::homeRouteName());
}

public static function homeRouteName(): string
{
return static::baseRouteKey().'/index';
}

/** @see https://hydephp.com/docs/master/documentation-pages#automatic-edit-page-button */
Expand Down
13 changes: 13 additions & 0 deletions packages/framework/tests/Unit/DocumentationPageTest.php
Expand Up @@ -144,6 +144,19 @@ public function test_home_method_finds_docs_index_for_custom_nested_output_direc
File::deleteDirectory(Hyde::path('foo'));
}

public function test_home_route_name_method_returns_output_directory_slash_index()
{
$this->assertSame('docs/index', DocumentationPage::homeRouteName());
}

public function test_home_route_name_method_returns_customized_output_directory_slash_index()
{
config(['docs.output_directory' => 'foo/bar']);
(new HydeServiceProvider($this->app))->register();

$this->assertSame('foo/bar/index', DocumentationPage::homeRouteName());
}

public function test_has_table_of_contents()
{
$this->assertIsBool(DocumentationPage::hasTableOfContents());
Expand Down

0 comments on commit 6dd3cd7

Please sign in to comment.