Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions config/docs.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
// When using a grouped sidebar, should the groups be collapsible?
'collapsible' => true,

// Should the sidebar footer be shown? You can also set this to a string
// of Markdown to show in the footer. Set to `false` to disable.
'footer' => true,
// A string of Markdown to show in the footer. Set to `false` to disable.
'footer' => '[Back to home page](../)',

/*
|--------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
<p>
@if(is_bool($sidebar->getFooter())))
<a href="{{ Hyde::relativeLink('index.html') }}">Back to home page</a>
@else
{{ Hyde::markdown($sidebar->getFooter()) }}
@endif
</p>
{{ Hyde::markdown($sidebar->getFooter()) }}
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,25 @@ public function __construct(Arrayable|array $items = [])
parent::__construct($items);
}

public function getFooter(): bool|string
public function getFooter(): ?string
{
return Config::get('docs.sidebar.footer', true);
}

public function getFooterText(): ?string
{
$option = Config::get('docs.sidebar.footer', true);
$option = Config::get('docs.sidebar.footer', '[Back to home page](../)');

if (is_string($option)) {
return $option;
}

if ($option === true) {
/** @deprecated Backwards compatibility */
return '[Back to home page](../)';
}

return null;
}

public function hasFooter(): bool
{
if (is_string(Config::get('docs.sidebar.footer', true))) {
return true;
}

return Config::getBool('docs.sidebar.footer', true);
return $this->getFooter() !== null;
}

public function isCollapsible(): bool
Expand Down
9 changes: 5 additions & 4 deletions packages/framework/tests/Feature/SidebarViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testBaseSidebar()
->assertSeeHtml('<ul id="sidebar-items" role="list"')
->assertSeeHtml('<nav id="sidebar-navigation"')
->assertSeeHtml('<footer id="sidebar-footer"')
->assertSeeHtml('<a href="index.html">Back to home page</a>')
->assertSeeHtml('<a href="../">Back to home page</a>')
->assertSeeHtml('<span class="sr-only">Toggle dark theme</span>')
->assertDontSee('<a href="docs/index.html">')
->assertDontSee('<li class="sidebar-item')
Expand All @@ -53,9 +53,10 @@ public function testBaseSidebarWithoutFooter()
{
config(['docs.sidebar.footer' => false]);

$this->renderComponent(view('hyde::components.docs.sidebar'));

$this->assertViewWasNotRendered(view('hyde::components.docs.sidebar-footer-text'));
$this->renderComponent(view('hyde::components.docs.sidebar'))
->assertDontSee('<footer id="sidebar-footer"')
->assertDontSee('Back to home page')
->allGood();
}

public function testBaseSidebarWithCustomFooterText()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testSidebarFooterTextViewWithDefaultConfig()
{
$view = $this->test(view('hyde::components.docs.sidebar-footer-text', $this->withSidebar()));

$view->assertSeeHtml('<a href="index.html">Back to home page</a>');
$view->assertSeeHtml('<a href="../">Back to home page</a>');
}

public function testSidebarFooterTextViewWhenConfigOptionIsTrue()
Expand All @@ -26,7 +26,7 @@ public function testSidebarFooterTextViewWhenConfigOptionIsTrue()

$view = $this->test(view('hyde::components.docs.sidebar-footer-text', $this->withSidebar()));

$view->assertSeeHtml('<a href="index.html">Back to home page</a>');
$view->assertSeeHtml('<a href="../">Back to home page</a>');
}

public function testSidebarFooterTextViewWhenConfigOptionIsMarkdownString()
Expand All @@ -38,13 +38,6 @@ public function testSidebarFooterTextViewWhenConfigOptionIsMarkdownString()
$view->assertSeeText('Your Markdown String Here');
}

public function testSidebarFooterTextViewWhenConfigOptionIsFalse()
{
// This state is handled earlier in the component by the sidebar component so we don't need to test it here.

$this->assertTrue(true);
}

protected function withSidebar(): array
{
return ['sidebar' => new DocumentationSidebar()];
Expand Down
33 changes: 6 additions & 27 deletions packages/framework/tests/Unit/DocumentationSidebarUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ public function testGetMethodResolvesInstanceFromServiceContainer()
$this->assertSame($instance, DocumentationSidebar::get());
}

public function testGetFooterReturnsTrueByDefault()
public function testGetFooterReturnsBackLinkByDefault()
{
self::mockConfig();

$this->assertTrue((new DocumentationSidebar())->getFooter());
$this->assertSame('[Back to home page](../)', (new DocumentationSidebar())->getFooter());
}

public function testGetFooterReturnsStringWhenConfigIsString()
Expand All @@ -136,39 +136,18 @@ public function testGetFooterReturnsStringWhenConfigIsString()
$this->assertSame('Some footer content', (new DocumentationSidebar())->getFooter());
}

public function testGetFooterReturnsTrueWhenConfigIsTrue()
public function testGetFooterReturnsBackLinkWhenConfigIsTrue()
{
self::mockConfig(['docs.sidebar.footer' => true]);

$this->assertTrue((new DocumentationSidebar())->getFooter());
$this->assertSame('[Back to home page](../)', (new DocumentationSidebar())->getFooter());
}

public function testGetFooterReturnsFalseWhenConfigIsFalse()
public function testGetFooterReturnsNullWhenConfigIsFalse()
{
self::mockConfig(['docs.sidebar.footer' => false]);

$this->assertFalse((new DocumentationSidebar())->getFooter());
}

public function testGetFooterTextReturnsStringWhenConfigIsString()
{
self::mockConfig(['docs.sidebar.footer' => 'Some footer content']);

$this->assertSame('Some footer content', (new DocumentationSidebar())->getFooterText());
}

public function testGetFooterTextReturnsNullWhenConfigIsTrue()
{
self::mockConfig(['docs.sidebar.footer' => true]);

$this->assertNull((new DocumentationSidebar())->getFooterText());
}

public function testGetFooterTextReturnsNullWhenConfigIsFalse()
{
self::mockConfig(['docs.sidebar.footer' => false]);

$this->assertNull((new DocumentationSidebar())->getFooterText());
$this->assertNull((new DocumentationSidebar())->getFooter());
}

public function testIsCollapsibleReturnsTrueByDefault()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function testRelativeLinksAcrossPagesRetainsIntegrity()
'<link rel="stylesheet" href="../media/app.css">',
'<a href="../docs/index.html">',
'<a href="../docs/docs.html"',
'<a href="../index.html">Back to home page</a>',
'<a href="../">Back to home page</a>',
]);
}
}