Skip to content

Commit

Permalink
Extract helper to generate documentation sidebar group name in class
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Nov 27, 2023
1 parent 48e02b8 commit d657e6d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@foreach ($sidebar->getGroups() as $group)
<li class="sidebar-group" role="listitem" @if($collapsible) x-data="{ groupOpen: {{ $sidebar->isGroupActive($group) ? 'true' : 'false' }} }" @endif>
<header class="sidebar-group-header p-2 px-4 -ml-2 flex justify-between items-center @if($collapsible) group hover:bg-black/10 @endif" @if($collapsible) @click="groupOpen = ! groupOpen" @endif>
<h4 class="sidebar-group-heading text-base font-semibold @if($collapsible) cursor-pointer dark:group-hover:text-white @endif">{{ Hyde::makeTitle($group) }}</h4>
<h4 class="sidebar-group-heading text-base font-semibold @if($collapsible) cursor-pointer dark:group-hover:text-white @endif">{{ $sidebar->makeGroupTitle($group) }}</h4>
@if($collapsible)
@include('hyde::components.docs.sidebar-group-toggle-button')
@endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Hyde\Framework\Features\Navigation;

use Hyde\Hyde;
use Hyde\Foundation\Facades\Routes;
use Hyde\Pages\DocumentationPage;
use Hyde\Support\Facades\Render;
Expand Down Expand Up @@ -56,6 +57,11 @@ public function isGroupActive(string $group): bool
|| $this->isPageIndexPage() && $this->shouldIndexPageBeActive($group);
}

public function makeGroupTitle(string $group): string
{
return Hyde::makeTitle($group);
}

protected function canAddRoute(Route $route): bool
{
return parent::canAddRoute($route) && ! $route->is(DocumentationPage::homeRouteName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,14 @@ public function test_automatic_index_page_group_expansion_respects_custom_naviga
$this->assertTrue(DocumentationSidebar::create()->isGroupActive('baz'));
}

public function test_make_group_title_turns_group_key_into_title()
{
$this->assertSame('Hello World', DocumentationSidebar::create()->makeGroupTitle('hello world'));
$this->assertSame('Hello World', DocumentationSidebar::create()->makeGroupTitle('hello-world'));
$this->assertSame('Hello World', DocumentationSidebar::create()->makeGroupTitle('hello_world'));
$this->assertSame('Hello World', DocumentationSidebar::create()->makeGroupTitle('helloWorld'));
}

public function test_can_have_multiple_grouped_pages_with_the_same_name_labels()
{
$this->makePage('foo', ['navigation.group' => 'foo', 'navigation.label' => 'Foo']);
Expand Down

0 comments on commit d657e6d

Please sign in to comment.