Skip to content

Commit 5f3b60f

Browse files
authored
Merge pull request #934 from hydephp/display-different-message-for-dynamic-pages-in-route-list-command
Display different message for dynamic pages in route list command
2 parents 85764fb + db49b82 commit 5f3b60f

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

packages/framework/src/Console/Commands/RouteListCommand.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Hyde\Console\Concerns\Command;
88
use Hyde\Hyde;
9+
use Hyde\Pages\Contracts\DynamicPage;
910

1011
/**
1112
* Hyde command to display the list of site routes.
@@ -39,7 +40,7 @@ protected function getRoutes(): array
3940
foreach (Hyde::routes() as $route) {
4041
$routes[] = [
4142
$this->formatPageType($route->getPageClass()),
42-
$this->formatSourcePath($route->getSourcePath()),
43+
$this->formatSourcePath($route->getSourcePath(), $route->getPageClass()),
4344
$this->formatOutputPath($route->getOutputPath()),
4445
$route->getRouteKey(),
4546
];
@@ -53,8 +54,12 @@ protected function formatPageType(string $class): string
5354
return str_starts_with($class, 'Hyde') ? class_basename($class) : $class;
5455
}
5556

56-
protected function formatSourcePath(string $path): string
57+
protected function formatSourcePath(string $path, string $class): string
5758
{
59+
if (is_a($class, DynamicPage::class, true)) {
60+
return '<fg=yellow>dynamic</>';
61+
}
62+
5863
return $this->clickablePathLink(static::createClickableFilepath(Hyde::path($path)), $path);
5964
}
6065

packages/framework/tests/Feature/Commands/RouteListCommandTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Hyde\Framework\Testing\Feature\Commands;
66

7+
use Hyde\Hyde;
8+
use Hyde\Pages\VirtualPage;
9+
use Hyde\Support\Models\Route;
710
use Hyde\Testing\TestCase;
811

912
/**
@@ -36,4 +39,31 @@ public function testClickableLinks()
3639
$this->artisan('route:list')
3740
->assertExitCode(0);
3841
}
42+
43+
public function testWithDynamicPages()
44+
{
45+
Hyde::routes()->put('foo', new Route(new VirtualPage('foo')));
46+
47+
$this->artisan('route:list')
48+
->expectsTable(['Page Type', 'Source File', 'Output File', 'Route Key'], [
49+
[
50+
'BladePage',
51+
'_pages/404.blade.php',
52+
'_site/404.html',
53+
'404',
54+
],
55+
[
56+
'BladePage',
57+
'_pages/index.blade.php',
58+
'_site/index.html',
59+
'index',
60+
],
61+
[
62+
'VirtualPage',
63+
'<fg=yellow>dynamic</>',
64+
'_site/foo.html',
65+
'foo',
66+
],
67+
])->assertExitCode(0);
68+
}
3969
}

0 commit comments

Comments
 (0)