Skip to content

Commit

Permalink
Rename NavigationItem method getUrl to getLink
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Mar 24, 2024
1 parent 1b94a90 commit 37c51c2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
: 'active bg-black/5 dark:bg-black/10' => $item->isActive()
]) role="listitem">
@if($item->isActive())
<a href="{{ $item->getUrl() }}" aria-current="true" @class([$grouped
<a href="{{ $item->getLink() }}" aria-current="true" @class([$grouped
? '-ml-8 pl-4 py-1 px-2 block text-indigo-600 dark:text-indigo-400 dark:font-medium border-l-[0.325rem] border-indigo-500 transition-colors duration-300 ease-in-out hover:bg-black/10'
: '-ml-4 p-2 block hover:bg-black/5 dark:hover:bg-black/10 text-indigo-600 dark:text-indigo-400 dark:font-medium border-l-[0.325rem] border-indigo-500 transition-colors duration-300 ease-in-out'
])>
Expand All @@ -16,7 +16,7 @@
{!! $page->getTableOfContents() !!}
@endif
@else
<a href="{{ $item->getUrl() }}" @class([$grouped
<a href="{{ $item->getLink() }}" @class([$grouped
? '-ml-8 pl-4 py-1 px-2 block border-l-[0.325rem] border-transparent transition-colors duration-300 ease-in-out hover:bg-black/10'
: 'block -ml-4 p-2 border-l-[0.325rem] border-transparent hover:bg-black/5 dark:hover:bg-black/10'
])>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function create(Route|string $destination, ?string $label = null,
*/
public function __toString(): string
{
return $this->getUrl();
return $this->getLink();
}

/**
Expand All @@ -94,10 +94,8 @@ public function getPage(): ?HydePage

/**
* Resolve the destination link of the navigation item.
*
* @deprecated May be renamed to getLink() in the future to better match its usage, and to match the Route class.
*/
public function getUrl(): string
public function getLink(): string
{
return $this->destination->getLink();
}
Expand Down Expand Up @@ -136,7 +134,7 @@ public function getGroupKey(): ?string
*/
public function isActive(): bool
{
return Hyde::currentRoute()->getLink() === $this->getUrl();
return Hyde::currentRoute()->getLink() === $this->getLink();
}

/** @return ($group is null ? null : string) */
Expand Down
12 changes: 6 additions & 6 deletions packages/framework/tests/Unit/NavigationItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ public function testPassingUrlToConstructorSetsRouteToNull()
{
$item = new NavigationItem('https://example.com', 'Home');
$this->assertNull($item->getPage());
$this->assertSame('https://example.com', $item->getUrl());
$this->assertSame('https://example.com', $item->getLink());
}

public function testPassingUnknownRouteKeyToConstructorSetsRouteToNull()
{
$item = new NavigationItem('foo', 'Home');
$this->assertNull($item->getPage());
$this->assertSame('foo', $item->getUrl());
$this->assertSame('foo', $item->getLink());
}

public function testCanGetPage()
Expand All @@ -99,7 +99,7 @@ public function testGetPageRoute()
public function testGetLink()
{
$NavigationItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500);
$this->assertSame('foo.html', $NavigationItem->getUrl());
$this->assertSame('foo.html', $NavigationItem->getLink());
}

public function testGetLabel()
Expand Down Expand Up @@ -142,7 +142,7 @@ public function testCreateWithLink()
$item = NavigationItem::create('foo', 'bar');

$this->assertNull($item->getPage());
$this->assertSame('foo', $item->getUrl());
$this->assertSame('foo', $item->getLink());
$this->assertSame('bar', $item->getLabel());
$this->assertSame(500, $item->getPriority());
}
Expand All @@ -161,7 +161,7 @@ public function testCreate()
$this->assertSame('foo', $item->getLabel());
$this->assertSame(999, $item->getPriority());
$this->assertEquals($route, $item->getPage()->getRoute());
$this->assertSame('404.html', $item->getUrl());
$this->assertSame('404.html', $item->getLink());
$this->assertSame('404.html', (string) $item);
$this->assertNull($item->getGroupKey());
}
Expand All @@ -175,7 +175,7 @@ public function testForIndexRoute()
$this->assertSame('Home', $item->getLabel());
$this->assertSame(0, $item->getPriority());
$this->assertEquals($route, $item->getPage()->getRoute());
$this->assertSame('index.html', $item->getUrl());
$this->assertSame('index.html', $item->getLink());
$this->assertSame('index.html', (string) $item);
$this->assertNull($item->getGroupKey());
}
Expand Down

0 comments on commit 37c51c2

Please sign in to comment.