Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
feature(pages): initial work
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangjchandler committed Oct 9, 2020
1 parent 6f43ee5 commit e545530
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/nebula.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@
// new UserDashboard,
],

'pages' => [
// new CustomPage,
],

];
46 changes: 46 additions & 0 deletions resources/views/components/layouts/shell.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ class="flex items-center justify-center w-10 h-10 bg-gray-800 rounded-lg">
@endforeach

</ul>

@if($pages = config('nebula.pages'))
<ul class="px-2 my-4 space-y-1">

<li>
<p class="flex items-center h-8 px-2 text-xs font-medium text-gray-300 uppercase">
{{ __('Pages') }}
</p>
</li>

@foreach ($pages as $page)
<li>
<a class="flex items-center h-10 px-2 text-sm font-medium text-gray-300 capitalize rounded-lg"
href="{{ route('nebula.pages.index', $page->name()) }}">
{{ svg("heroicon-o-{$page->icon()}", ['class' => 'w-5 h-5 mr-2 text-gray-400']) }}
{{ $page->name() }}
</a>
</li>
@endforeach

</ul>
@endif
</nav>
</aside>

Expand Down Expand Up @@ -114,6 +136,30 @@ class="flex items-center justify-center w-10 h-10 bg-gray-800 rounded-lg">

</ul>

@if ($pages = config('nebula.pages'))
<ul class="px-2 my-4 space-y-1">

<li>
<p class="flex items-center h-8 px-2 text-xs font-medium text-gray-300 uppercase">
{{ __('Pages') }}
</p>
</li>

@foreach ($pages as $page)
<li>

<a class="flex items-center h-10 px-2 text-sm font-medium text-gray-300 capitalize rounded-lg"
href="{{ route('nebula.pages.index', $page->name()) }}">
{{ svg("heroicon-o-{$page->icon()}", ['class' => 'w-5 h-5 mr-2 text-gray-400']) }}
{{ $page->pluralName() }}
</a>

</li>
@endforeach

</ul>
@endif

</aside>

<main class="z-10 flex-1 overflow-hidden bg-gray-100 shadow lg:rounded-l-lg">
Expand Down
7 changes: 7 additions & 0 deletions resources/views/pages/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<x-nebula::layouts.shell :title="$page->singularName()">

<div class="mb-8 space-y-4">
{{ $page->display() }}
</div>

</x-nebula::layouts.shell>
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Support\Facades\Route;
use Larsklopstra\Nebula\Http\Controllers\DashboardController;
use Larsklopstra\Nebula\Http\Controllers\PageController;
use Larsklopstra\Nebula\Http\Controllers\ResourceController;
use Larsklopstra\Nebula\Http\Controllers\StartController;

Expand All @@ -23,3 +24,5 @@

Route::delete('/{resource}/{item}', [ResourceController::class, 'destroy'])->name('destroy');
});

Route::get('/page/{page}', [PageController::class, 'index'])->name('pages.index');
70 changes: 70 additions & 0 deletions src/Contracts/NebulaPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace Larsklopstra\Nebula\Contracts;

use Exception;
use Illuminate\Support\Str;
use Illuminate\Support\Stringable;

abstract class NebulaPage
{
/**
* Specifies which icon should be used.
*
* @return string
*/
public function icon()
{
return 'tag';
}

/**
* Returns the name of the page.
*
* @return Stringable
*/
public function name()
{
return Str::of(class_basename($this))
->replaceLast('Page', '')
->kebab()
->lower()
->plural();
}

/**
* Returns the page singular name.
*
* @return Stringable
*/
public function singularName()
{
return Str::of($this->name())
->replace('-', '')
->singular();
}

/**
* Returns the page its plural name.
*
* @return string
*/
public function pluralName()
{
return Str::plural($this->singularName());
}

/**
* Outputs the page.
*
* @return
*/
public function display()
{
if (! method_exists($this, 'render')) {
throw new Exception('No `render` method defined on '.get_class($this));
}

return app()->call([$this, 'render']);
}
}
15 changes: 15 additions & 0 deletions src/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Larsklopstra\Nebula\Http\Controllers;

use Larsklopstra\Nebula\Contracts\NebulaPage;

class PageController
{
public function index(NebulaPage $page)
{
return view('nebula::pages.index', [
'page' => $page,
]);
}
}
24 changes: 24 additions & 0 deletions src/NebulaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function boot(): void
$this->resourceResolver();
$this->itemResolver();
$this->dashboardResolver();
$this->pageResolver();

if ($this->app->runningInConsole()) {
$this->publishes([
Expand Down Expand Up @@ -118,4 +119,27 @@ public function itemResolver(): void
->firstOrFail();
});
}

public function pageResolver(): void
{
Route::bind('page', function ($value) {
$pages = config('nebula.pages', []);

if (empty($pages)) {
throw new Exception('No pages set in the nebula config.');
}

foreach ($pages as $page) {
$pageExists = Str::of($page->name())
->lower()
->is($value);

if ($pageExists) {
return $page;
}
}

throw new Exception("Page {$page} not found.");
});
}
}

0 comments on commit e545530

Please sign in to comment.