Skip to content

Commit

Permalink
Use new class name
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Mar 20, 2024
1 parent eb27714 commit 9bcabd1
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 44 deletions.
10 changes: 5 additions & 5 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ This serves two purposes:
### Added
- Added a new `\Hyde\Framework\Actions\PreBuildTasks\TransferMediaAssets` build task handle media assets transfers for site builds.
- Added a new `ExternalRoute` class to represent external routes.
- Added a new `NavItem::getLink()` method contain the previous `NavItem::getDestination()` logic, to return the link URL.
- Added a new `NavigationItem::getLink()` method contain the previous `NavigationItem::getDestination()` logic, to return the link URL.

### Changed
- Changed how the documentation search is generated, to be an `InMemoryPage` instead of a post-build task.
- Media asset files are now copied using the new build task instead of the deprecated `BuildService::transferMediaAssets()` method.
- Minor: The documentation article component now supports disabling the semantic rendering using a falsy value in https://github.com/hydephp/develop/pull/1566
- Navigation menu items are now no longer filtered by duplicates (meaning two items with the same label can now exist in the same menu) in https://github.com/hydephp/develop/pull/1573
- Breaking: The `NavItem` class now always stores the destination as a `Route` instance.
- Breaking: The `NavItem::getDestination()` method now returns its `Route` instance.
- Breaking: The `NavigationItem` class now always stores the destination as a `Route` instance.
- Breaking: The `NavigationItem::getDestination()` method now returns its `Route` instance.

### Deprecated
- for soon-to-be removed features.
Expand Down Expand Up @@ -63,11 +63,11 @@ For more information, see https://github.com/hydephp/develop/pull/1498.

### Navigation item changes

The `NavItem::getDestination()` method now returns its `Route` instance. This allows for deferring the route evaluation.
The `NavigationItem::getDestination()` method now returns its `Route` instance. This allows for deferring the route evaluation.

If you have previously used this method directly and expected a string to be returned, you may need to adapt your code to handle the new return type.

If you want to retain the previous state where a string is always returned, you can use the new `NavItem::getLink()` method instead, which will resolve the route immediately.
If you want to retain the previous state where a string is always returned, you can use the new `NavigationItem::getLink()` method instead, which will resolve the route immediately.

### HTML ID changes

Expand Down
2 changes: 1 addition & 1 deletion config/hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
// To get started quickly, you can uncomment the defaults here.
// See the documentation link above for more information.
'custom' => [
// NavItem::forLink('https://github.com/hydephp/hyde', 'GitHub', 200),
// NavigationItem::forLink('https://github.com/hydephp/hyde', 'GitHub', 200),
],

// How should pages in subdirectories be displayed in the menu?
Expand Down
12 changes: 6 additions & 6 deletions docs/digging-deeper/navigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ To remove items from being automatically added, simply add the page's route key

### Adding Custom Navigation Menu Links

You can easily add custom navigation menu links similar to how we add Authors. Simply add a `NavItem` model to the `navigation.custom` array.
You can easily add custom navigation menu links similar to how we add Authors. Simply add a `NavigationItem` model to the `navigation.custom` array.

When linking to an external site, you should use the `NavItem::forLink()` method facade. The first two arguments are the
When linking to an external site, you should use the `NavigationItem::forLink()` method facade. The first two arguments are the
destination and label, both required. The third argument is the priority, which is optional, and defaults to `500`.

```php
Expand Down Expand Up @@ -314,14 +314,14 @@ use Hyde\Framework\Features\Navigation\BaseNavigationMenu;
Within the `BaseNavigationMenu` class, you will find the main logic for how the menus are generated,
while the child implementations contain the extra logic tailored for their specific use cases.

All the navigation menus store the menu items in their `$items` array containing instances of the `NavItem` class.
All the navigation menus store the menu items in their `$items` array containing instances of the `NavigationItem` class.

The `NavItem` class is a simple class that contains the label and URL of the menu item and is used to represent each item in the menu.
Dropdowns are represented by `DropdownNavItem` instances, which extend the `NavItem` class and contain an array of additional `NavItem` instances.
The `NavigationItem` class is a simple class that contains the label and URL of the menu item and is used to represent each item in the menu.
Dropdowns are represented by `DropdownNavigationItem` instances, which extend the `NavigationItem` class and contain an array of additional `NavigationItem` instances.

```php
use Hyde\Framework\Features\Navigation\NavigationItem;
use Hyde\Framework\Features\Navigation\DropdownNavItem;
use Hyde\Framework\Features\Navigation\DropdownNavigationItem;
```

## The Navigation API
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/config/hyde.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
// To get started quickly, you can uncomment the defaults here.
// See the documentation link above for more information.
'custom' => [
// NavItem::forLink('https://github.com/hydephp/hyde', 'GitHub', 200),
// NavigationItem::forLink('https://github.com/hydephp/hyde', 'GitHub', 200),
],

// How should pages in subdirectories be displayed in the menu?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function hasGroups(): bool
*
* For index pages, this will also return true for the first group in the menu, unless the index page has a specific group set.
*
* We have this logic here because not all NavItem instances belong to sidebars, and we need data from both.
* We have this logic here because not all NavigationItem instances belong to sidebars, and we need data from both.
*/
public function isGroupActive(string $group): bool
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*
* You have a few options to construct a navigation menu item:
* 1. You can supply a Route directly and explicit properties to the constructor
* 2. You can use NavItem::fromRoute() to use data from the route
* 3. You can use NavItem::forLink() for an external or un-routed link
* 2. You can use NavigationItem::fromRoute() to use data from the route
* 3. You can use NavigationItem::forLink() for an external or un-routed link
*/
class NavigationItem implements Stringable
{
Expand Down Expand Up @@ -145,7 +145,7 @@ public function getGroupKey(): ?string
}

/**
* Check if the NavItem instance is the current page being rendered.
* Check if the NavigationItem instance is the current page being rendered.
*/
public function isActive(): bool
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,7 @@ protected function sidebar(?array $withPages = null): AssertableNavigationMenu
}
}

class TestNavItem
class TestNavigationItem
{
public readonly string $label;
public readonly ?string $group;
Expand Down Expand Up @@ -1319,12 +1319,12 @@ public function __construct(TestCase $test, $sidebar = false)
/** A simplified serialized format for comparisons */
public function state(): array
{
return $this->items->map(function (NavigationItem $item): TestNavItem {
return new TestNavItem($item->getLabel(), $item->getGroupKey(), $item->getPriority(), $item instanceof NavigationGroupItem ? $item->getItems() : []);
return $this->items->map(function (NavigationItem $item): TestNavigationItem {
return new TestNavigationItem($item->getLabel(), $item->getGroupKey(), $item->getPriority(), $item instanceof NavigationGroupItem ? $item->getItems() : []);
})->toArray();
}

public function getState(int $index): ?TestNavItem
public function getState(int $index): ?TestNavigationItem
{
return $this->state()[$index] ?? null;
}
Expand All @@ -1345,7 +1345,7 @@ public function assertEquals(array $expected, bool $strict = false): static
$item = ['label' => $item];
}

foreach (TestNavItem::properties() as $property) {
foreach (TestNavigationItem::properties() as $property) {
if ($this->getState($index) !== null) {
if (isset($item[$property])) {
$a = $item[$property];
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/tests/Feature/NavigationMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testConstructor()
$this->assertInstanceOf(MainNavigationMenu::class, $this->createNavigationMenu());
}

public function testGenerateMethodCreatesCollectionOfNavItems()
public function testGenerateMethodCreatesCollectionOfNavigationItems()
{
$this->assertInstanceOf(Collection::class, $this->createNavigationMenu()->getItems());
$this->assertContainsOnlyInstancesOf(NavigationItem::class, $this->createNavigationMenu()->getItems());
Expand Down
10 changes: 5 additions & 5 deletions packages/framework/tests/Unit/NavGroupItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testDestinationIsAlwaysNull()

public function testCanConstructWithChildren()
{
$children = $this->createNavItems();
$children = $this->createNavigationItems();
$item = new NavigationGroupItem('Foo', $children);

$this->assertCount(2, $item->getItems());
Expand All @@ -55,7 +55,7 @@ public function testCanConstructWithChildren()

public function testCanConstructWithChildrenWithoutRoute()
{
$children = $this->createNavItems();
$children = $this->createNavigationItems();
$item = new NavigationGroupItem('Foo', $children);

$this->assertCount(2, $item->getItems());
Expand All @@ -64,7 +64,7 @@ public function testCanConstructWithChildrenWithoutRoute()

public function testGetItems()
{
$children = $this->createNavItems();
$children = $this->createNavigationItems();
$item = new NavigationGroupItem('Foo', $children);

$this->assertSame($children, $item->getItems());
Expand Down Expand Up @@ -94,7 +94,7 @@ public function testAddChildMethodReturnsSelf()
public function testCanAddMultipleItemsToDropdown()
{
$group = new NavigationGroupItem('Foo');
$items = $this->createNavItems();
$items = $this->createNavigationItems();

$this->assertSame($items, $group->addItems($items)->getItems());
}
Expand Down Expand Up @@ -197,7 +197,7 @@ public function testForLink()
$this->assertSame(NavigationItem::class, $item::class);
}

protected function createNavItems(): array
protected function createNavigationItems(): array
{
return [
new NavigationItem(new Route(new InMemoryPage('foo')), 'Foo'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
/**
* @covers \Hyde\Framework\Features\Navigation\NavigationItem
*
* @see \Hyde\Framework\Testing\Unit\NavItemTest
* @see \Hyde\Framework\Testing\Unit\NavigationItemTest
*/
class NavItemIsActiveHelperTest extends UnitTestCase
class NavigationItemIsActiveHelperTest extends UnitTestCase
{
public static function setUpBeforeClass(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
use Mockery;

/**
* This unit test covers the basics of the NavItem class.
* This unit test covers the basics of the NavigationItem class.
* For the full feature test, see the MainNavigationMenuTest class.
*
* @covers \Hyde\Framework\Features\Navigation\NavigationItem
*
* @see \Hyde\Framework\Testing\Unit\NavItemIsActiveHelperTest
* @see \Hyde\Framework\Testing\Unit\NavigationItemIsActiveHelperTest
*/
class NavItemTest extends UnitTestCase
class NavigationItemTest extends UnitTestCase
{
public static function setUpBeforeClass(): void
{
Expand Down Expand Up @@ -79,33 +79,33 @@ public function testPassingUnknownRouteKeyToConstructorUsesExternalRoute()
public function testGetDestination()
{
$route = new Route(new InMemoryPage('foo'));
$navItem = new NavigationItem($route, 'Page', 500);
$NavigationItem = new NavigationItem($route, 'Page', 500);

$this->assertSame($route, $navItem->getRoute());
$this->assertSame($route, $NavigationItem->getRoute());
}

public function testGetLink()
{
$navItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500);
$this->assertSame('foo.html', $navItem->getUrl());
$NavigationItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500);
$this->assertSame('foo.html', $NavigationItem->getUrl());
}

public function testGetLabel()
{
$navItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500);
$this->assertSame('Page', $navItem->getLabel());
$NavigationItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500);
$this->assertSame('Page', $NavigationItem->getLabel());
}

public function testGetPriority()
{
$navItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500);
$this->assertSame(500, $navItem->getPriority());
$NavigationItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500);
$this->assertSame(500, $NavigationItem->getPriority());
}

public function testGetGroup()
{
$navItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500);
$this->assertNull($navItem->getGroupKey());
$NavigationItem = new NavigationItem(new Route(new InMemoryPage('foo')), 'Page', 500);
$this->assertNull($NavigationItem->getGroupKey());
}

public function testFromRoute()
Expand Down Expand Up @@ -176,7 +176,7 @@ public function testForRouteWithCustomPriority()
$this->assertSame(100, NavigationItem::forRoute(Routes::get('index'), 'foo', 100)->getPriority());
}

public function testRouteBasedNavItemDestinationsAreResolvedRelatively()
public function testRouteBasedNavigationItemDestinationsAreResolvedRelatively()
{
Render::swap(Mockery::mock(RenderData::class, [
'getRoute' => new Route(new InMemoryPage('foo')),
Expand Down

0 comments on commit 9bcabd1

Please sign in to comment.