Skip to content

Commit

Permalink
Merge pull request #917 from hydephp/remove-PublishableView-system
Browse files Browse the repository at this point in the history
Remove PublishableView system and refactor it to use the publish command
  • Loading branch information
caendesilva committed Feb 4, 2023
2 parents 24a60c6 + bccaf0e commit 330ee8d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 243 deletions.
52 changes: 38 additions & 14 deletions packages/framework/src/Console/Commands/PublishHomepageCommand.php
Expand Up @@ -5,16 +5,21 @@
namespace Hyde\Console\Commands;

use Hyde\Console\Concerns\AsksToRebuildSite;
use Hyde\Framework\Features\Templates\Homepages;
use Hyde\Framework\Features\Templates\PublishableContract;
use Hyde\Console\Concerns\Command;
use Hyde\Framework\Services\ChecksumService;
use Hyde\Hyde;
use Illuminate\Support\Collection;
use LaravelZero\Framework\Commands\Command;
use Illuminate\Support\Facades\Artisan;
use function array_key_exists;
use function file_exists;
use function str_replace;
use function strstr;

/**
* Publish one of the default homepages.
*
* @todo Refactor to use vendor:publish and to use code similar to {@see \Hyde\Console\Commands\PublishViewsCommand}
*
* @deprecated May be replaced by vendor:publish in the future.
* @see \Hyde\Framework\Testing\Feature\Commands\PublishHomepageCommandTest
*/
Expand All @@ -29,29 +34,48 @@ class PublishHomepageCommand extends Command
/** @var string */
protected $description = 'Publish one of the default homepages to index.blade.php.';

protected array $options = [
'welcome'=> [
'name' => 'Welcome',
'description' => 'The default welcome page.',
'group' => 'hyde-welcome-page',
],
'posts'=> [
'name' => 'Posts Feed',
'description' => 'A feed of your latest posts. Perfect for a blog site!',
'group' => 'hyde-posts-page',
],
'blank'=> [
'name' => 'Blank Starter',
'description' => 'A blank Blade template with just the base layout.',
'group' => 'hyde-blank-page',
],
];

public function handle(): int
{
$selected = $this->parseSelection();

if (! Homepages::exists($selected)) {
$this->error("Homepage $selected does not exist.");

return 404;
}

if (! $this->canExistingFileBeOverwritten()) {
$this->error('A modified index.blade.php file already exists. Use --force to overwrite.');

return 409;
}

Homepages::get($selected)->publish(true);
$tagExists = array_key_exists($selected, $this->options);

Artisan::call('vendor:publish', [
'--tag' => $this->options[$selected]['group'] ?? $selected,
'--force' => true, // Todo add force state dynamically depending on existing file state
], ! $tagExists ? $this->output : null);

$this->line("<info>Published page</info> [<comment>$selected</comment>]");
if ($tagExists) {
$this->infoComment("Published page [$selected]");

$this->askToRebuildSite();
$this->askToRebuildSite();
}

return Command::SUCCESS;
return $tagExists ? Command::SUCCESS : 404;
}

protected function parseSelection(): string
Expand All @@ -77,7 +101,7 @@ protected function formatPublishableChoices(): array

protected function getTemplateOptions(): Collection
{
return Homepages::options()->map(fn (PublishableContract $page): array => $page::toArray());
return new Collection($this->options);
}

protected function parseChoiceIntoKey(string $choice): string
Expand Down
68 changes: 0 additions & 68 deletions packages/framework/src/Framework/Features/Templates/Homepages.php

This file was deleted.

This file was deleted.

This file was deleted.

8 changes: 8 additions & 0 deletions packages/framework/src/Framework/HydeServiceProvider.php
Expand Up @@ -95,6 +95,14 @@ public function boot(): void
Hyde::vendorPath('resources/views/homepages/welcome.blade.php') => Hyde::path('_pages/index.blade.php'),
], 'hyde-welcome-page');

$this->publishes([
Hyde::vendorPath('resources/views/homepages/post-feed.blade.php') => Hyde::path('_pages/index.blade.php'),
], 'hyde-posts-page');

$this->publishes([
Hyde::vendorPath('resources/views/homepages/blank.blade.php') => Hyde::path('_pages/index.blade.php'),
], 'hyde-blank-page');

Blade::component('link', LinkComponent::class);

HydeKernel::getInstance()->readyToBoot();
Expand Down
Expand Up @@ -10,8 +10,6 @@

/**
* @covers \Hyde\Console\Commands\PublishHomepageCommand
* @covers \Hyde\Framework\Features\Templates\Homepages
* @covers \Hyde\Framework\Features\Templates\PublishableView
* @covers \Hyde\Console\Concerns\AsksToRebuildSite
*/
class PublishHomepageCommandTest extends TestCase
Expand Down
76 changes: 0 additions & 76 deletions packages/framework/tests/Unit/PublishableViewTest.php

This file was deleted.

0 comments on commit 330ee8d

Please sign in to comment.