From c165bea0eb5b41b86e8c01ab67a5f7492101df42 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:22:34 +0100 Subject: [PATCH 01/84] Assert the correct template was published --- .../tests/Feature/CreatesNewPublicationTypeTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/publications/tests/Feature/CreatesNewPublicationTypeTest.php b/packages/publications/tests/Feature/CreatesNewPublicationTypeTest.php index 3bc15d9907d..4cc9e53b40a 100644 --- a/packages/publications/tests/Feature/CreatesNewPublicationTypeTest.php +++ b/packages/publications/tests/Feature/CreatesNewPublicationTypeTest.php @@ -88,5 +88,12 @@ public function test_it_creates_list_and_detail_pages() $this->assertFileExists(Hyde::path('test-publication/detail.blade.php')); $this->assertFileExists(Hyde::path('test-publication/list.blade.php')); + + $this->assertFileEquals(__DIR__.'/../../resources/views/publication_detail.blade.php', + Hyde::path('test-publication/detail.blade.php') + ); + $this->assertFileEquals(__DIR__.'/../../resources/views/publication_list.blade.php', + Hyde::path('test-publication/list.blade.php') + ); } } From 96149920a21fee5ef4a5b2ff8bc77a72475f3b1a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:22:43 +0100 Subject: [PATCH 02/84] Remove unnecessary qualifier --- .../tests/Feature/CreatesNewPublicationTypeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/tests/Feature/CreatesNewPublicationTypeTest.php b/packages/publications/tests/Feature/CreatesNewPublicationTypeTest.php index 4cc9e53b40a..21493cff872 100644 --- a/packages/publications/tests/Feature/CreatesNewPublicationTypeTest.php +++ b/packages/publications/tests/Feature/CreatesNewPublicationTypeTest.php @@ -79,7 +79,7 @@ public function test_create_with_default_parameters() public function test_it_creates_list_and_detail_pages() { - $creator = new \Hyde\Publications\Actions\CreatesNewPublicationType( + $creator = new CreatesNewPublicationType( 'Test Publication', new Collection(), 'canonical', From 989b35fcd09322b202aa6c0adc6423f5cbbb6f00 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:24:00 +0100 Subject: [PATCH 03/84] Update publication type creator to use the paginated view when enabled --- .../src/Actions/CreatesNewPublicationType.php | 12 ++++++++++- .../Feature/CreatesNewPublicationTypeTest.php | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/packages/publications/src/Actions/CreatesNewPublicationType.php b/packages/publications/src/Actions/CreatesNewPublicationType.php index e652ef4c529..c6cd7988eaa 100644 --- a/packages/publications/src/Actions/CreatesNewPublicationType.php +++ b/packages/publications/src/Actions/CreatesNewPublicationType.php @@ -55,11 +55,21 @@ protected function createDetailTemplate(): void protected function createListTemplate(): void { - $this->savePublicationFile('list.blade.php', '/../publications/resources/views/publication_list.blade.php'); + if ($this->usesPagination()) { + $name = 'publication_paginated_list'; + } else { + $name = 'publication_list'; + } + $this->savePublicationFile('list.blade.php', '/../publications/resources/views/'.$name.'.blade.php'); } protected function savePublicationFile(string $filename, string $viewPath): void { copy(Hyde::vendorPath($viewPath), Hyde::path("$this->directoryName/$filename")); } + + protected function usesPagination(): bool + { + return $this->pageSize > 0; + } } diff --git a/packages/publications/tests/Feature/CreatesNewPublicationTypeTest.php b/packages/publications/tests/Feature/CreatesNewPublicationTypeTest.php index 21493cff872..fccab4a62e2 100644 --- a/packages/publications/tests/Feature/CreatesNewPublicationTypeTest.php +++ b/packages/publications/tests/Feature/CreatesNewPublicationTypeTest.php @@ -96,4 +96,25 @@ public function test_it_creates_list_and_detail_pages() Hyde::path('test-publication/list.blade.php') ); } + + public function test_it_uses_the_paginated_list_view_when_pagination_is_enabled() + { + $creator = new CreatesNewPublicationType( + 'Test Publication', + new Collection(), + 'canonical', + pageSize: 10, + ); + $creator->create(); + + $this->assertFileExists(Hyde::path('test-publication/detail.blade.php')); + $this->assertFileExists(Hyde::path('test-publication/list.blade.php')); + + $this->assertFileEquals(__DIR__.'/../../resources/views/publication_detail.blade.php', + Hyde::path('test-publication/detail.blade.php') + ); + $this->assertFileEquals(__DIR__.'/../../resources/views/publication_paginated_list.blade.php', + Hyde::path('test-publication/list.blade.php') + ); + } } From 72a7be5fd669377aa9a8da0c4da1ad83d9c08b91 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:27:47 +0100 Subject: [PATCH 04/84] Simplify 'if' --- .../publications/src/Actions/CreatesNewPublicationType.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/publications/src/Actions/CreatesNewPublicationType.php b/packages/publications/src/Actions/CreatesNewPublicationType.php index c6cd7988eaa..fa359dcf140 100644 --- a/packages/publications/src/Actions/CreatesNewPublicationType.php +++ b/packages/publications/src/Actions/CreatesNewPublicationType.php @@ -55,11 +55,7 @@ protected function createDetailTemplate(): void protected function createListTemplate(): void { - if ($this->usesPagination()) { - $name = 'publication_paginated_list'; - } else { - $name = 'publication_list'; - } + $name = $this->usesPagination() ? 'publication_paginated_list' : 'publication_list'; $this->savePublicationFile('list.blade.php', '/../publications/resources/views/'.$name.'.blade.php'); } From ffe4abe1e955378b955c68785bee016f05819f45 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:27:58 +0100 Subject: [PATCH 05/84] Inline variable --- .../publications/src/Actions/CreatesNewPublicationType.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/publications/src/Actions/CreatesNewPublicationType.php b/packages/publications/src/Actions/CreatesNewPublicationType.php index fa359dcf140..63917ee704d 100644 --- a/packages/publications/src/Actions/CreatesNewPublicationType.php +++ b/packages/publications/src/Actions/CreatesNewPublicationType.php @@ -55,8 +55,7 @@ protected function createDetailTemplate(): void protected function createListTemplate(): void { - $name = $this->usesPagination() ? 'publication_paginated_list' : 'publication_list'; - $this->savePublicationFile('list.blade.php', '/../publications/resources/views/'.$name.'.blade.php'); + $this->savePublicationFile('list.blade.php', '/../publications/resources/views/'.($this->usesPagination() ? 'publication_paginated_list' : 'publication_list').'.blade.php'); } protected function savePublicationFile(string $filename, string $viewPath): void From fa2d88cfc86fda877e7d2ffc327e712a9c21a1df Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:28:11 +0100 Subject: [PATCH 06/84] Convert concatenation to 'sprintf()' call --- .../publications/src/Actions/CreatesNewPublicationType.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/publications/src/Actions/CreatesNewPublicationType.php b/packages/publications/src/Actions/CreatesNewPublicationType.php index 63917ee704d..f8b15937d68 100644 --- a/packages/publications/src/Actions/CreatesNewPublicationType.php +++ b/packages/publications/src/Actions/CreatesNewPublicationType.php @@ -55,7 +55,9 @@ protected function createDetailTemplate(): void protected function createListTemplate(): void { - $this->savePublicationFile('list.blade.php', '/../publications/resources/views/'.($this->usesPagination() ? 'publication_paginated_list' : 'publication_list').'.blade.php'); + $this->savePublicationFile('list.blade.php', sprintf("/../publications/resources/views/%s.blade.php", + $this->usesPagination() ? 'publication_paginated_list' : 'publication_list' + )); } protected function savePublicationFile(string $filename, string $viewPath): void From 75cbf10c5e94061ddb7d1f3118e069f4492bf0ac Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:28:46 +0100 Subject: [PATCH 07/84] Move common parts to the helper method --- .../publications/src/Actions/CreatesNewPublicationType.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/publications/src/Actions/CreatesNewPublicationType.php b/packages/publications/src/Actions/CreatesNewPublicationType.php index f8b15937d68..8819135b529 100644 --- a/packages/publications/src/Actions/CreatesNewPublicationType.php +++ b/packages/publications/src/Actions/CreatesNewPublicationType.php @@ -50,19 +50,19 @@ protected function handleCreate(): void protected function createDetailTemplate(): void { - $this->savePublicationFile('detail.blade.php', '/../publications/resources/views/publication_detail.blade.php'); + $this->savePublicationFile('detail.blade.php', 'publication_detail.blade.php'); } protected function createListTemplate(): void { - $this->savePublicationFile('list.blade.php', sprintf("/../publications/resources/views/%s.blade.php", + $this->savePublicationFile('list.blade.php', sprintf("%s.blade.php", $this->usesPagination() ? 'publication_paginated_list' : 'publication_list' )); } protected function savePublicationFile(string $filename, string $viewPath): void { - copy(Hyde::vendorPath($viewPath), Hyde::path("$this->directoryName/$filename")); + copy(Hyde::vendorPath("/../publications/resources/views/$viewPath"), Hyde::path("$this->directoryName/$filename")); } protected function usesPagination(): bool From 534ff2fb68328b82a46e5fdcb8f5bc7c29e11da9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:29:28 +0100 Subject: [PATCH 08/84] Move common parts to the helper method --- .../publications/src/Actions/CreatesNewPublicationType.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/publications/src/Actions/CreatesNewPublicationType.php b/packages/publications/src/Actions/CreatesNewPublicationType.php index 8819135b529..e486e27bbb1 100644 --- a/packages/publications/src/Actions/CreatesNewPublicationType.php +++ b/packages/publications/src/Actions/CreatesNewPublicationType.php @@ -50,19 +50,19 @@ protected function handleCreate(): void protected function createDetailTemplate(): void { - $this->savePublicationFile('detail.blade.php', 'publication_detail.blade.php'); + $this->savePublicationFile('detail.blade.php', 'publication_detail'); } protected function createListTemplate(): void { - $this->savePublicationFile('list.blade.php', sprintf("%s.blade.php", + $this->savePublicationFile('list.blade.php', sprintf("%s", $this->usesPagination() ? 'publication_paginated_list' : 'publication_list' )); } protected function savePublicationFile(string $filename, string $viewPath): void { - copy(Hyde::vendorPath("/../publications/resources/views/$viewPath"), Hyde::path("$this->directoryName/$filename")); + copy(Hyde::vendorPath("/../publications/resources/views/$viewPath.blade.php"), Hyde::path("$this->directoryName/$filename")); } protected function usesPagination(): bool From bfe9863df950531b11ddb4bacf27ad3232a66499 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:30:26 +0100 Subject: [PATCH 09/84] Convert 'sprintf()' call to a scalar value --- .../publications/src/Actions/CreatesNewPublicationType.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/publications/src/Actions/CreatesNewPublicationType.php b/packages/publications/src/Actions/CreatesNewPublicationType.php index e486e27bbb1..8bcd5d66bf5 100644 --- a/packages/publications/src/Actions/CreatesNewPublicationType.php +++ b/packages/publications/src/Actions/CreatesNewPublicationType.php @@ -55,9 +55,9 @@ protected function createDetailTemplate(): void protected function createListTemplate(): void { - $this->savePublicationFile('list.blade.php', sprintf("%s", + $this->savePublicationFile('list.blade.php', $this->usesPagination() ? 'publication_paginated_list' : 'publication_list' - )); + ); } protected function savePublicationFile(string $filename, string $viewPath): void From 4cbebf3852abafbb3115557e40a6c65ec2c1aa10 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:31:08 +0100 Subject: [PATCH 10/84] Join comma-separated values into a single line --- .../publications/src/Actions/CreatesNewPublicationType.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/publications/src/Actions/CreatesNewPublicationType.php b/packages/publications/src/Actions/CreatesNewPublicationType.php index 8bcd5d66bf5..9544a1fec64 100644 --- a/packages/publications/src/Actions/CreatesNewPublicationType.php +++ b/packages/publications/src/Actions/CreatesNewPublicationType.php @@ -55,9 +55,7 @@ protected function createDetailTemplate(): void protected function createListTemplate(): void { - $this->savePublicationFile('list.blade.php', - $this->usesPagination() ? 'publication_paginated_list' : 'publication_list' - ); + $this->savePublicationFile('list.blade.php', $this->usesPagination() ? 'publication_paginated_list' : 'publication_list'); } protected function savePublicationFile(string $filename, string $viewPath): void From a56e6076562a121c9ce40985bf1463f0f609af15 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:31:26 +0100 Subject: [PATCH 11/84] Move common parts to the helper method --- .../publications/src/Actions/CreatesNewPublicationType.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/publications/src/Actions/CreatesNewPublicationType.php b/packages/publications/src/Actions/CreatesNewPublicationType.php index 9544a1fec64..be25c820ab6 100644 --- a/packages/publications/src/Actions/CreatesNewPublicationType.php +++ b/packages/publications/src/Actions/CreatesNewPublicationType.php @@ -50,17 +50,17 @@ protected function handleCreate(): void protected function createDetailTemplate(): void { - $this->savePublicationFile('detail.blade.php', 'publication_detail'); + $this->savePublicationFile('detail', 'publication_detail'); } protected function createListTemplate(): void { - $this->savePublicationFile('list.blade.php', $this->usesPagination() ? 'publication_paginated_list' : 'publication_list'); + $this->savePublicationFile('list', $this->usesPagination() ? 'publication_paginated_list' : 'publication_list'); } protected function savePublicationFile(string $filename, string $viewPath): void { - copy(Hyde::vendorPath("/../publications/resources/views/$viewPath.blade.php"), Hyde::path("$this->directoryName/$filename")); + copy(Hyde::vendorPath("/../publications/resources/views/$viewPath.blade.php"), Hyde::path("$this->directoryName/$filename.blade.php")); } protected function usesPagination(): bool From 35d4a45cb7f8a196fd974ee382e8ede4fe2f83e1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:31:53 +0100 Subject: [PATCH 12/84] Update helper method parameter name --- .../publications/src/Actions/CreatesNewPublicationType.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/publications/src/Actions/CreatesNewPublicationType.php b/packages/publications/src/Actions/CreatesNewPublicationType.php index be25c820ab6..ed044230dd2 100644 --- a/packages/publications/src/Actions/CreatesNewPublicationType.php +++ b/packages/publications/src/Actions/CreatesNewPublicationType.php @@ -58,9 +58,9 @@ protected function createListTemplate(): void $this->savePublicationFile('list', $this->usesPagination() ? 'publication_paginated_list' : 'publication_list'); } - protected function savePublicationFile(string $filename, string $viewPath): void + protected function savePublicationFile(string $filename, string $viewName): void { - copy(Hyde::vendorPath("/../publications/resources/views/$viewPath.blade.php"), Hyde::path("$this->directoryName/$filename.blade.php")); + copy(Hyde::vendorPath("/../publications/resources/views/$viewName.blade.php"), Hyde::path("$this->directoryName/$filename.blade.php")); } protected function usesPagination(): bool From 44648cea9d4e5b60c42e95d15bdd000c11c03b14 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:32:50 +0100 Subject: [PATCH 13/84] Split comma-separated values into multiple lines --- .../publications/src/Actions/CreatesNewPublicationType.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/publications/src/Actions/CreatesNewPublicationType.php b/packages/publications/src/Actions/CreatesNewPublicationType.php index ed044230dd2..bf61b218170 100644 --- a/packages/publications/src/Actions/CreatesNewPublicationType.php +++ b/packages/publications/src/Actions/CreatesNewPublicationType.php @@ -60,7 +60,10 @@ protected function createListTemplate(): void protected function savePublicationFile(string $filename, string $viewName): void { - copy(Hyde::vendorPath("/../publications/resources/views/$viewName.blade.php"), Hyde::path("$this->directoryName/$filename.blade.php")); + copy( + Hyde::vendorPath("/../publications/resources/views/$viewName.blade.php"), + Hyde::path("$this->directoryName/$filename.blade.php") + ); } protected function usesPagination(): bool From 807fda393870f1008a99b36dd00d423588049a4f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:32:53 +0100 Subject: [PATCH 14/84] Revert "Split comma-separated values into multiple lines" This reverts commit 44648cea9d4e5b60c42e95d15bdd000c11c03b14. --- .../publications/src/Actions/CreatesNewPublicationType.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/publications/src/Actions/CreatesNewPublicationType.php b/packages/publications/src/Actions/CreatesNewPublicationType.php index bf61b218170..ed044230dd2 100644 --- a/packages/publications/src/Actions/CreatesNewPublicationType.php +++ b/packages/publications/src/Actions/CreatesNewPublicationType.php @@ -60,10 +60,7 @@ protected function createListTemplate(): void protected function savePublicationFile(string $filename, string $viewName): void { - copy( - Hyde::vendorPath("/../publications/resources/views/$viewName.blade.php"), - Hyde::path("$this->directoryName/$filename.blade.php") - ); + copy(Hyde::vendorPath("/../publications/resources/views/$viewName.blade.php"), Hyde::path("$this->directoryName/$filename.blade.php")); } protected function usesPagination(): bool From 3eb7536c276f624ded4e52db0b8102e51002b296 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:33:22 +0100 Subject: [PATCH 15/84] Rename local helper method --- .../publications/src/Actions/CreatesNewPublicationType.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/publications/src/Actions/CreatesNewPublicationType.php b/packages/publications/src/Actions/CreatesNewPublicationType.php index ed044230dd2..b06c8839d18 100644 --- a/packages/publications/src/Actions/CreatesNewPublicationType.php +++ b/packages/publications/src/Actions/CreatesNewPublicationType.php @@ -50,15 +50,15 @@ protected function handleCreate(): void protected function createDetailTemplate(): void { - $this->savePublicationFile('detail', 'publication_detail'); + $this->publishPublicationFile('detail', 'publication_detail'); } protected function createListTemplate(): void { - $this->savePublicationFile('list', $this->usesPagination() ? 'publication_paginated_list' : 'publication_list'); + $this->publishPublicationFile('list', $this->usesPagination() ? 'publication_paginated_list' : 'publication_list'); } - protected function savePublicationFile(string $filename, string $viewName): void + protected function publishPublicationFile(string $filename, string $viewName): void { copy(Hyde::vendorPath("/../publications/resources/views/$viewName.blade.php"), Hyde::path("$this->directoryName/$filename.blade.php")); } From d36dd2704f6334583c19092b6dc0b56a4c52be4e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:41:17 +0100 Subject: [PATCH 16/84] Switch around tests with mismatched names --- ...StaticSiteBuilderPublicationModuleTest.php | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/publications/tests/Feature/StaticSiteBuilderPublicationModuleTest.php b/packages/publications/tests/Feature/StaticSiteBuilderPublicationModuleTest.php index a761ce0e9f3..cff672e118a 100644 --- a/packages/publications/tests/Feature/StaticSiteBuilderPublicationModuleTest.php +++ b/packages/publications/tests/Feature/StaticSiteBuilderPublicationModuleTest.php @@ -124,12 +124,13 @@ public function testCompilingWithPublicationTypeThatUsesTheVendorViews() public function testCompilingWithPublicationTypeThatUsesThePublishedPaginatedViews() { + $this->markTestSkipped('https://github.com/hydephp/develop/pull/685/files#r1064151223'); + $this->directory('test-publication'); - (new CreatesNewPublicationType('Test Publication', collect([])))->create(); + (new CreatesNewPublicationType('Test Publication', collect([]), pageSize: 10))->create(); $type = PublicationType::get('test-publication'); - $type->listTemplate = 'hyde-publications::publication_paginated_list'; $type->pageSize = 2; $type->save(); @@ -161,9 +162,33 @@ public function testCompilingWithPublicationTypeThatUsesThePaginatedVendorViews( $this->directory('test-publication'); (new CreatesNewPublicationType('Test Publication', collect([])))->create(); - // TODO assert the paginated template was published once we implement that - $this->markTestIncomplete(); + $type = PublicationType::get('test-publication'); + $type->listTemplate = 'hyde-publications::publication_paginated_list'; + $type->pageSize = 2; + $type->save(); + + foreach (range(1, 5) as $i) { + $this->file("test-publication/publication-$i.md", "## Test publication $i"); + } + + $this->artisan('build')->assertSuccessful(); + + $this->assertSame([ + 'index.html', + 'page-1.html', + 'page-2.html', + 'page-3.html', + 'publication-1.html', + 'publication-2.html', + 'publication-3.html', + 'publication-4.html', + 'publication-5.html', + ], $this->getFilenamesInDirectory('_site/test-publication')); + + // TODO test that the pagination links are correct + + $this->resetSite(); } protected function getAllFields(): Collection From f28119af9ecebc0fa25af02e9f67bccbd667dc3c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:52:26 +0100 Subject: [PATCH 17/84] Update virtual page class to support compiling anonymous Blade files --- packages/framework/src/Pages/VirtualPage.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Pages/VirtualPage.php b/packages/framework/src/Pages/VirtualPage.php index 45a1ef5c393..6f5e57396e2 100644 --- a/packages/framework/src/Pages/VirtualPage.php +++ b/packages/framework/src/Pages/VirtualPage.php @@ -4,11 +4,14 @@ namespace Hyde\Pages; +use Hyde\Framework\Actions\AnonymousViewCompiler; use Hyde\Markdown\Models\FrontMatter; use Hyde\Pages\Concerns\HydePage; use Hyde\Pages\Contracts\DynamicPage; use Illuminate\Support\Facades\View; +use function str_ends_with; + /** * A virtual page is a page that does not have a source file. * @@ -70,7 +73,10 @@ public function getBladeView(): string public function compile(): string { if (! $this->contents && $this->view) { - // TODO This needs to support Blade files if we're gonna use it for pagination. + if (str_ends_with($this->view, '.blade.php')) { + return AnonymousViewCompiler::call($this->view, $this->matter->toArray()); + } + return View::make($this->getBladeView(), $this->matter->toArray())->render(); } From 2c147e29f72637699e204ff3978be4fd8afea687 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:58:35 +0100 Subject: [PATCH 18/84] Update virtual page class to support custom closure compiling --- packages/framework/src/Pages/VirtualPage.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Pages/VirtualPage.php b/packages/framework/src/Pages/VirtualPage.php index 6f5e57396e2..0892184a675 100644 --- a/packages/framework/src/Pages/VirtualPage.php +++ b/packages/framework/src/Pages/VirtualPage.php @@ -4,6 +4,7 @@ namespace Hyde\Pages; +use Closure; use Hyde\Framework\Actions\AnonymousViewCompiler; use Hyde\Markdown\Models\FrontMatter; use Hyde\Pages\Concerns\HydePage; @@ -31,6 +32,8 @@ class VirtualPage extends HydePage implements DynamicPage protected string $contents; protected string $view; + protected Closure $compiler; + public static function make(string $identifier = '', FrontMatter|array $matter = [], string $contents = '', string $view = ''): static { return new static($identifier, $matter, $contents, $view); @@ -51,13 +54,19 @@ public static function make(string $identifier = '', FrontMatter|array $matter = * this will be passed to the view. * @param string $contents The contents of the page. This will be saved as-is to the output file. * @param string $view The view key for the view to use to render the page contents. + * @param Closure|null $compiler Additionally, you can instead pass a closure to control the compiling completely. + * The closure accepts the page instance, and must return a string (which will be saved as the page's contents). */ - public function __construct(string $identifier, FrontMatter|array $matter = [], string $contents = '', string $view = '') + public function __construct(string $identifier, FrontMatter|array $matter = [], string $contents = '', string $view = '', Closure $compiler = null) { parent::__construct($identifier, $matter); $this->contents = $contents; $this->view = $view; + + if ($compiler) { + $this->compiler = $compiler; + } } public function getContents(): string @@ -72,6 +81,10 @@ public function getBladeView(): string public function compile(): string { + if (isset($this->compiler)) { + return ($this->compiler)($this); + } + if (! $this->contents && $this->view) { if (str_ends_with($this->view, '.blade.php')) { return AnonymousViewCompiler::call($this->view, $this->matter->toArray()); From 5c8ff4dc5c8da4d35cde5a382417f91c96b74877 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:59:05 +0100 Subject: [PATCH 19/84] Pass custom compile function to paginated listing pages --- packages/publications/src/PublicationsExtension.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/publications/src/PublicationsExtension.php b/packages/publications/src/PublicationsExtension.php index bb7e9219bc8..9da24f25319 100644 --- a/packages/publications/src/PublicationsExtension.php +++ b/packages/publications/src/PublicationsExtension.php @@ -6,6 +6,7 @@ use Hyde\Foundation\Concerns\HydeExtension; use Hyde\Foundation\PageCollection; +use Hyde\Framework\Actions\AnonymousViewCompiler; use Hyde\Pages\VirtualPage; use Hyde\Publications\Models\PublicationListPage; use Hyde\Publications\Models\PublicationPage; @@ -73,7 +74,9 @@ protected static function generatePublicationPaginatedListingPagesForType(Public $listingPage = new VirtualPage("{$type->getDirectory()}/page-$page", [ 'publicationType' => $type, 'paginatorPage' => $page, 'title' => $type->name.' - Page '.$page, - ], view: $type->listTemplate); + ], compiler: function (VirtualPage $page) use ($type): string { + return AnonymousViewCompiler::call("{$type->getDirectory()}/$type->listTemplate", $page->matter->toArray()); + }); $instance->put($listingPage->getSourcePath(), $listingPage); } } From abb1699440f606c3d08a2700d89f8f9dde13e712 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 16:59:49 +0100 Subject: [PATCH 20/84] Paginated listing views can now be compiled --- .../tests/Feature/StaticSiteBuilderPublicationModuleTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/publications/tests/Feature/StaticSiteBuilderPublicationModuleTest.php b/packages/publications/tests/Feature/StaticSiteBuilderPublicationModuleTest.php index cff672e118a..af11f287aa7 100644 --- a/packages/publications/tests/Feature/StaticSiteBuilderPublicationModuleTest.php +++ b/packages/publications/tests/Feature/StaticSiteBuilderPublicationModuleTest.php @@ -124,8 +124,6 @@ public function testCompilingWithPublicationTypeThatUsesTheVendorViews() public function testCompilingWithPublicationTypeThatUsesThePublishedPaginatedViews() { - $this->markTestSkipped('https://github.com/hydephp/develop/pull/685/files#r1064151223'); - $this->directory('test-publication'); (new CreatesNewPublicationType('Test Publication', collect([]), pageSize: 10))->create(); From 93b5e40b2de0bbe934ac31ceafded52b870e54a3 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 12 Jan 2023 16:00:04 +0000 Subject: [PATCH 21/84] Apply fixes from StyleCI --- packages/framework/src/Pages/VirtualPage.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Pages/VirtualPage.php b/packages/framework/src/Pages/VirtualPage.php index 0892184a675..345c9793759 100644 --- a/packages/framework/src/Pages/VirtualPage.php +++ b/packages/framework/src/Pages/VirtualPage.php @@ -10,7 +10,6 @@ use Hyde\Pages\Concerns\HydePage; use Hyde\Pages\Contracts\DynamicPage; use Illuminate\Support\Facades\View; - use function str_ends_with; /** @@ -54,8 +53,8 @@ public static function make(string $identifier = '', FrontMatter|array $matter = * this will be passed to the view. * @param string $contents The contents of the page. This will be saved as-is to the output file. * @param string $view The view key for the view to use to render the page contents. - * @param Closure|null $compiler Additionally, you can instead pass a closure to control the compiling completely. - * The closure accepts the page instance, and must return a string (which will be saved as the page's contents). + * @param Closure|null $compiler Additionally, you can instead pass a closure to control the compiling completely. + * The closure accepts the page instance, and must return a string (which will be saved as the page's contents). */ public function __construct(string $identifier, FrontMatter|array $matter = [], string $contents = '', string $view = '', Closure $compiler = null) { From d4a1e3521ec2c87928fdffa0b131e1f9c2e0c833 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 17:13:19 +0100 Subject: [PATCH 22/84] Revert "Pass custom compile function to paginated listing pages" This reverts commit 5c8ff4dc5c8da4d35cde5a382417f91c96b74877. --- packages/publications/src/PublicationsExtension.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/publications/src/PublicationsExtension.php b/packages/publications/src/PublicationsExtension.php index 9da24f25319..bb7e9219bc8 100644 --- a/packages/publications/src/PublicationsExtension.php +++ b/packages/publications/src/PublicationsExtension.php @@ -6,7 +6,6 @@ use Hyde\Foundation\Concerns\HydeExtension; use Hyde\Foundation\PageCollection; -use Hyde\Framework\Actions\AnonymousViewCompiler; use Hyde\Pages\VirtualPage; use Hyde\Publications\Models\PublicationListPage; use Hyde\Publications\Models\PublicationPage; @@ -74,9 +73,7 @@ protected static function generatePublicationPaginatedListingPagesForType(Public $listingPage = new VirtualPage("{$type->getDirectory()}/page-$page", [ 'publicationType' => $type, 'paginatorPage' => $page, 'title' => $type->name.' - Page '.$page, - ], compiler: function (VirtualPage $page) use ($type): string { - return AnonymousViewCompiler::call("{$type->getDirectory()}/$type->listTemplate", $page->matter->toArray()); - }); + ], view: $type->listTemplate); $instance->put($listingPage->getSourcePath(), $listingPage); } } From 13e1026f676f5c2893c18cb59b2a554a4ee9754e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 17:15:20 +0100 Subject: [PATCH 23/84] Prepend directory prefix for paginated listing pages when needed Solving the right problem helps... --- packages/publications/src/PublicationsExtension.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/publications/src/PublicationsExtension.php b/packages/publications/src/PublicationsExtension.php index bb7e9219bc8..c2154d3d43b 100644 --- a/packages/publications/src/PublicationsExtension.php +++ b/packages/publications/src/PublicationsExtension.php @@ -11,6 +11,7 @@ use Hyde\Publications\Models\PublicationPage; use Hyde\Publications\Models\PublicationType; use function range; +use function str_ends_with; /** * @see \Hyde\Publications\Testing\Feature\PublicationsExtensionTest @@ -70,10 +71,14 @@ protected static function generatePublicationPaginatedListingPagesForType(Public foreach (range(1, $paginator->totalPages()) as $page) { $paginator->setCurrentPage($page); + $listTemplate = $type->listTemplate; + if (str_ends_with($listTemplate, '.blade.php')) { + $listTemplate = "{$type->getDirectory()}/$listTemplate"; + } $listingPage = new VirtualPage("{$type->getDirectory()}/page-$page", [ 'publicationType' => $type, 'paginatorPage' => $page, 'title' => $type->name.' - Page '.$page, - ], view: $type->listTemplate); + ], view: $listTemplate); $instance->put($listingPage->getSourcePath(), $listingPage); } } From c4df021188825196040515d11fb51f5ed48451f8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 22:14:13 +0100 Subject: [PATCH 24/84] Set default page size of creator action to nought to match constructor --- packages/publications/src/Actions/CreatesNewPublicationType.php | 2 +- .../tests/Feature/CreatesNewPublicationTypeTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/publications/src/Actions/CreatesNewPublicationType.php b/packages/publications/src/Actions/CreatesNewPublicationType.php index b06c8839d18..b44c2861142 100644 --- a/packages/publications/src/Actions/CreatesNewPublicationType.php +++ b/packages/publications/src/Actions/CreatesNewPublicationType.php @@ -40,7 +40,7 @@ protected function handleCreate(): void 'list.blade.php', $this->sortField ?? '__createdAt', $this->sortAscending ?? true, - $this->pageSize ?? 25, + $this->pageSize ?? 0, $this->fields->toArray() ))->save($this->outputPath); diff --git a/packages/publications/tests/Feature/CreatesNewPublicationTypeTest.php b/packages/publications/tests/Feature/CreatesNewPublicationTypeTest.php index fccab4a62e2..a9fa791bad4 100644 --- a/packages/publications/tests/Feature/CreatesNewPublicationTypeTest.php +++ b/packages/publications/tests/Feature/CreatesNewPublicationTypeTest.php @@ -70,7 +70,7 @@ public function test_create_with_default_parameters() "listTemplate": "list.blade.php", "sortField": "__createdAt", "sortAscending": true, - "pageSize": 25, + "pageSize": 0, "fields": [] } JSON, file_get_contents(Hyde::path('test-publication/schema.json')) From 6acde59dc3669aae4dfd7dfef3c84c7e63983c2e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 12 Jan 2023 22:18:42 +0100 Subject: [PATCH 25/84] Set default page size of command to nought to match constructor --- .../publications/src/Commands/MakePublicationTypeCommand.php | 2 +- .../tests/Feature/MakePublicationTypeCommandTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 246367d67f5..6b9fde11354 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -215,7 +215,7 @@ protected function getPageSize(): int return (int) $this->askWithValidation('pageSize', 'Enter the page size (0 for no limit)', ['required', 'integer', 'between:0,100'], - 25 + 0 ); } diff --git a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php index 1dd31105aef..bdd218c7839 100644 --- a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php +++ b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php @@ -183,7 +183,7 @@ public function testWithTagFieldInput() "listTemplate": "list.blade.php", "sortField": "__createdAt", "sortAscending": true, - "pageSize": 25, + "pageSize": 0, "fields": [ { "type": "datetime", From 6f304998f6f1e833d84e89fc07ec9ccba8d66a2b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 11:53:07 +0100 Subject: [PATCH 26/84] Inline deprecated helper method --- .../Commands/MakePublicationTypeCommand.php | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 6b9fde11354..661254717e1 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -49,7 +49,15 @@ public function safeHandle(): int $this->fields = $this->captureFieldsDefinitions(); - [$sortField, $sortAscending, $pageSize] = ($this->getPaginationSettings()); + if ($this->option('use-defaults') || !$this->confirm('Would you like to enable pagination?')) { + $paginationSettings = [null, null, null]; + } else { + $this->info("Okay, let's set up pagination! Tip: You can just hit enter to accept the default values."); + + $paginationSettings = [$this->getSortField(), $this->getSortDirection(), $this->getPageSize()]; + } + + [$sortField, $sortAscending, $pageSize] = ($paginationSettings); $canonicalField = $this->getCanonicalField(); @@ -186,18 +194,6 @@ protected function addCreatedAtMetaField(): void $this->fields->add(new PublicationFieldDefinition(PublicationFieldTypes::Datetime, '__createdAt')); } - /** @deprecated Since the pagination settings object is deprecated we should just inline these */ - protected function getPaginationSettings(): array - { - if ($this->option('use-defaults') || ! $this->confirm('Would you like to enable pagination?')) { - return [null, null, null]; - } - - $this->info("Okay, let's set up pagination! Tip: You can just hit enter to accept the default values."); - - return [$this->getSortField(), $this->getSortDirection(), $this->getPageSize()]; - } - protected function getSortField(): string { return $this->choice('Choose the default field you wish to sort by', $this->fields->pluck('name')->toArray(), 0); From b633729e291a88cbac0855c451f439b45e0ad822 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 13 Jan 2023 10:53:23 +0000 Subject: [PATCH 27/84] Apply fixes from StyleCI --- .../publications/src/Commands/MakePublicationTypeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 661254717e1..2eb728fe709 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -49,7 +49,7 @@ public function safeHandle(): int $this->fields = $this->captureFieldsDefinitions(); - if ($this->option('use-defaults') || !$this->confirm('Would you like to enable pagination?')) { + if ($this->option('use-defaults') || ! $this->confirm('Would you like to enable pagination?')) { $paginationSettings = [null, null, null]; } else { $this->info("Okay, let's set up pagination! Tip: You can just hit enter to accept the default values."); From 9c24ce3095af3c1f0aff5b3067db3dbabed3f2b8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 11:57:44 +0100 Subject: [PATCH 28/84] Update question message --- .../publications/src/Commands/MakePublicationTypeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 2eb728fe709..aa4965f9588 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -209,7 +209,7 @@ protected function getSortDirection(): bool protected function getPageSize(): int { return (int) $this->askWithValidation('pageSize', - 'Enter the page size (0 for no limit)', + 'Enter the list (index) page size (any value above 0 will enable pagination)', ['required', 'integer', 'between:0,100'], 0 ); From 54e05ec1716ee3f2e1a7e23bb85b54652c4489d8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 11:58:48 +0100 Subject: [PATCH 29/84] Add temporary markers --- .../publications/src/Commands/MakePublicationTypeCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index aa4965f9588..f8942a05b2c 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -32,7 +32,7 @@ class MakePublicationTypeCommand extends ValidatingCommand /** @var string */ protected $signature = 'make:publicationType {name? : The name of the publication type to create} - {--use-defaults : Select the default options wherever possible}'; + {--use-defaults : Select the default options wherever possible}'; // Deprecated /** @var string */ protected $description = 'Create a new publication type definition'; @@ -209,6 +209,7 @@ protected function getSortDirection(): bool protected function getPageSize(): int { return (int) $this->askWithValidation('pageSize', + // Todo href pagination to the docs? // how many items should be shown on the listing page? 'Enter the list (index) page size (any value above 0 will enable pagination)', ['required', 'integer', 'between:0,100'], 0 From 323e94e37feee5e7a16262d799e0754638c3006b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 11:59:14 +0100 Subject: [PATCH 30/84] Remove question regarding enablement of pagination --- .../publications/src/Commands/MakePublicationTypeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index f8942a05b2c..b25fdc5fb1f 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -49,7 +49,7 @@ public function safeHandle(): int $this->fields = $this->captureFieldsDefinitions(); - if ($this->option('use-defaults') || ! $this->confirm('Would you like to enable pagination?')) { + if ($this->option('use-defaults')) { $paginationSettings = [null, null, null]; } else { $this->info("Okay, let's set up pagination! Tip: You can just hit enter to accept the default values."); From 8d46d83ebc69e98e21984eb6c6b5c96345611512 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 11:59:34 +0100 Subject: [PATCH 31/84] Remove info output --- .../publications/src/Commands/MakePublicationTypeCommand.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index b25fdc5fb1f..da9bffd1514 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -52,8 +52,6 @@ public function safeHandle(): int if ($this->option('use-defaults')) { $paginationSettings = [null, null, null]; } else { - $this->info("Okay, let's set up pagination! Tip: You can just hit enter to accept the default values."); - $paginationSettings = [$this->getSortField(), $this->getSortDirection(), $this->getPageSize()]; } From a170f1c31aa85bea2cceffbff3406d2de62cf4e8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 12:01:17 +0100 Subject: [PATCH 32/84] Inline array list syntax --- .../src/Commands/MakePublicationTypeCommand.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index da9bffd1514..e82ecb7ba34 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -50,13 +50,15 @@ public function safeHandle(): int $this->fields = $this->captureFieldsDefinitions(); if ($this->option('use-defaults')) { - $paginationSettings = [null, null, null]; + $sortField = null; + $sortAscending = null; + $pageSize = null; } else { - $paginationSettings = [$this->getSortField(), $this->getSortDirection(), $this->getPageSize()]; + $sortField = $this->getSortField(); + $sortAscending = $this->getSortDirection(); + $pageSize = $this->getPageSize(); } - [$sortField, $sortAscending, $pageSize] = ($paginationSettings); - $canonicalField = $this->getCanonicalField(); $creator = new CreatesNewPublicationType($title, $this->fields, $canonicalField->name, $sortField, $sortAscending, $pageSize); From 8908a1baf7f630c7016c4e880656b61f46f51d9a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 12:03:00 +0100 Subject: [PATCH 33/84] Simplify if --- .../src/Commands/MakePublicationTypeCommand.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index e82ecb7ba34..6f45a08edef 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -49,15 +49,9 @@ public function safeHandle(): int $this->fields = $this->captureFieldsDefinitions(); - if ($this->option('use-defaults')) { - $sortField = null; - $sortAscending = null; - $pageSize = null; - } else { - $sortField = $this->getSortField(); - $sortAscending = $this->getSortDirection(); - $pageSize = $this->getPageSize(); - } + $sortField = $this->option('use-defaults') ? null : $this->getSortField(); + $sortAscending = $this->option('use-defaults') ? null : $this->getSortDirection(); + $pageSize = $this->option('use-defaults') ? null : $this->getPageSize(); $canonicalField = $this->getCanonicalField(); From 38f6da5e57f852381b17bc99edd11f42ef7d9c16 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 12:04:59 +0100 Subject: [PATCH 34/84] Update question messages Remove the word default from messages as that implies that it at some point is changed, which is not the case. --- .../publications/src/Commands/MakePublicationTypeCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 6f45a08edef..9940ddd0a05 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -190,14 +190,14 @@ protected function addCreatedAtMetaField(): void protected function getSortField(): string { - return $this->choice('Choose the default field you wish to sort by', $this->fields->pluck('name')->toArray(), 0); + return $this->choice('Choose the field you wish to sort by', $this->fields->pluck('name')->toArray(), 0); } protected function getSortDirection(): bool { $options = ['Ascending' => true, 'Descending' => false]; - return $options[$this->choice('Choose the default sort direction', array_keys($options), 'Ascending')]; + return $options[$this->choice('Choose the sort direction', array_keys($options), 'Ascending')]; } protected function getPageSize(): int From 1b5d77a5d797e724b5fcd1fc57027900666f5205 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 12:17:24 +0100 Subject: [PATCH 35/84] Update MakePublicationTypeCommandTest.php --- .../MakePublicationTypeCommandTest.php | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php index bdd218c7839..671e1a92c43 100644 --- a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php +++ b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php @@ -50,16 +50,15 @@ public function test_command_creates_publication_type() 'Tag', ], true) ->expectsConfirmation('Field #1 added! Add another field?') - ->expectsConfirmation('Would you like to enable pagination?', 'yes') - ->expectsChoice('Choose the default field you wish to sort by', '__createdAt', [ + ->expectsChoice('Choose the field you wish to sort by', '__createdAt', [ '__createdAt', 'publication-title', ]) - ->expectsChoice('Choose the default sort direction', 'Ascending', [ + ->expectsChoice('Choose the sort direction', 'Ascending', [ 'Ascending', 'Descending', ]) - ->expectsQuestion('Enter the page size (0 for no limit)', 10) + ->expectsQuestion('Enter the list (index) page size (any value above 0 will enable pagination)', 10) ->expectsChoice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', 'publication-title', [ '__createdAt', 'publication-title', @@ -113,6 +112,7 @@ public function test_with_default_values() public function test_with_multiple_fields_of_the_same_name() { $this->artisan('make:publicationType "Test Publication"') + ->expectsQuestion('Enter name for field #1', 'foo') ->expectsChoice('Enter type for field #1', 'String', PublicationFieldTypes::names()) @@ -125,12 +125,16 @@ public function test_with_multiple_fields_of_the_same_name() ->expectsConfirmation('Field #2 added! Add another field?') - ->expectsConfirmation('Would you like to enable pagination?') + ->expectsChoice('Choose the field you wish to sort by', '__createdAt', ['__createdAt', 'foo', 'bar']) + ->expectsChoice('Choose the sort direction', 'Ascending', ['Ascending', 'Descending']) + ->expectsQuestion('Enter the list (index) page size (any value above 0 will enable pagination)', 0) + ->expectsChoice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', 'foo', [ '__createdAt', 'bar', 'foo', ]) + ->assertExitCode(0); } @@ -235,7 +239,11 @@ public function testWithTagFieldInputButNoTagsCanPromptToCreateTags() ->expectsOutput("Okay, we're back on track!") ->expectsChoice('Enter tag group for field #1', 'foo', ['foo'], true) ->expectsConfirmation('Field #1 added! Add another field?') - ->expectsConfirmation('Would you like to enable pagination?') + + ->expectsChoice('Choose the field you wish to sort by', '__createdAt', ['__createdAt', 'my-tag']) + ->expectsChoice('Choose the sort direction', 'Ascending', ['Ascending', 'Descending']) + ->expectsQuestion('Enter the list (index) page size (any value above 0 will enable pagination)', 0) + ->expectsChoice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', '__createdAt', ['__createdAt']) ->doesntExpectOutput('Error: Can not create a tag field without any tag groups defined in tags.json') ->assertSuccessful(); From 62c1dbedb8d360d77fdfaddb82281da3ade32c72 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 12:23:07 +0100 Subject: [PATCH 36/84] Remove todo --- .../publications/src/Commands/MakePublicationTypeCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 9940ddd0a05..7ac38d576f2 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -203,7 +203,6 @@ protected function getSortDirection(): bool protected function getPageSize(): int { return (int) $this->askWithValidation('pageSize', - // Todo href pagination to the docs? // how many items should be shown on the listing page? 'Enter the list (index) page size (any value above 0 will enable pagination)', ['required', 'integer', 'between:0,100'], 0 From c28beee16b8c44ee56b43bea75bd44ce96ef8432 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 12:23:13 +0100 Subject: [PATCH 37/84] Update question message --- .../publications/src/Commands/MakePublicationTypeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 7ac38d576f2..0584385d358 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -203,7 +203,7 @@ protected function getSortDirection(): bool protected function getPageSize(): int { return (int) $this->askWithValidation('pageSize', - 'Enter the list (index) page size (any value above 0 will enable pagination)', + 'How many links should be shown on the listing page? (any value above 0 will enable pagination)', ['required', 'integer', 'between:0,100'], 0 ); From 935519badfff8ef8f756ecb0bd2ce5052dce40c1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 12:23:21 +0100 Subject: [PATCH 38/84] Add console link to the docs --- .../publications/src/Commands/MakePublicationTypeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 0584385d358..3b85027ee60 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -203,7 +203,7 @@ protected function getSortDirection(): bool protected function getPageSize(): int { return (int) $this->askWithValidation('pageSize', - 'How many links should be shown on the listing page? (any value above 0 will enable pagination)', + 'How many links should be shown on the listing page? (any value above 0 will enable pagination)', ['required', 'integer', 'between:0,100'], 0 ); From fbcfb12909929afbafbe2a9f4b8d1cc776a6efcf Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 12:28:34 +0100 Subject: [PATCH 39/84] Update MakePublicationTypeCommandTest.php --- .../tests/Feature/MakePublicationTypeCommandTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php index 671e1a92c43..76de1553fa3 100644 --- a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php +++ b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php @@ -58,7 +58,7 @@ public function test_command_creates_publication_type() 'Ascending', 'Descending', ]) - ->expectsQuestion('Enter the list (index) page size (any value above 0 will enable pagination)', 10) + ->expectsQuestion('How many links should be shown on the listing page? (any value above 0 will enable pagination)', 10) ->expectsChoice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', 'publication-title', [ '__createdAt', 'publication-title', @@ -127,7 +127,7 @@ public function test_with_multiple_fields_of_the_same_name() ->expectsChoice('Choose the field you wish to sort by', '__createdAt', ['__createdAt', 'foo', 'bar']) ->expectsChoice('Choose the sort direction', 'Ascending', ['Ascending', 'Descending']) - ->expectsQuestion('Enter the list (index) page size (any value above 0 will enable pagination)', 0) + ->expectsQuestion('How many links should be shown on the listing page? (any value above 0 will enable pagination)', 0) ->expectsChoice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', 'foo', [ '__createdAt', @@ -242,7 +242,7 @@ public function testWithTagFieldInputButNoTagsCanPromptToCreateTags() ->expectsChoice('Choose the field you wish to sort by', '__createdAt', ['__createdAt', 'my-tag']) ->expectsChoice('Choose the sort direction', 'Ascending', ['Ascending', 'Descending']) - ->expectsQuestion('Enter the list (index) page size (any value above 0 will enable pagination)', 0) + ->expectsQuestion('How many links should be shown on the listing page? (any value above 0 will enable pagination)', 0) ->expectsChoice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', '__createdAt', ['__createdAt']) ->doesntExpectOutput('Error: Can not create a tag field without any tag groups defined in tags.json') From d631d6531b9a0acf8912ae206bcf17cd53c6be8c Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 12:31:12 +0100 Subject: [PATCH 40/84] Extract testing constants for impossibly long messages --- .../Feature/MakePublicationTypeCommandTest.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php index 76de1553fa3..f71b2c7f57b 100644 --- a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php +++ b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php @@ -18,6 +18,9 @@ */ class MakePublicationTypeCommandTest extends TestCase { + protected const selectPageSizeQuestion = 'How many links should be shown on the listing page? (any value above 0 will enable pagination)'; + protected const selectCanonicalNameQuestion = 'Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)'; + protected function setUp(): void { parent::setUp(); @@ -58,8 +61,8 @@ public function test_command_creates_publication_type() 'Ascending', 'Descending', ]) - ->expectsQuestion('How many links should be shown on the listing page? (any value above 0 will enable pagination)', 10) - ->expectsChoice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', 'publication-title', [ + ->expectsQuestion(self::selectPageSizeQuestion, 10) + ->expectsChoice(self::selectCanonicalNameQuestion, 'publication-title', [ '__createdAt', 'publication-title', ]) @@ -127,9 +130,9 @@ public function test_with_multiple_fields_of_the_same_name() ->expectsChoice('Choose the field you wish to sort by', '__createdAt', ['__createdAt', 'foo', 'bar']) ->expectsChoice('Choose the sort direction', 'Ascending', ['Ascending', 'Descending']) - ->expectsQuestion('How many links should be shown on the listing page? (any value above 0 will enable pagination)', 0) + ->expectsQuestion(self::selectPageSizeQuestion, 0) - ->expectsChoice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', 'foo', [ + ->expectsChoice(self::selectCanonicalNameQuestion, 'foo', [ '__createdAt', 'bar', 'foo', @@ -242,9 +245,9 @@ public function testWithTagFieldInputButNoTagsCanPromptToCreateTags() ->expectsChoice('Choose the field you wish to sort by', '__createdAt', ['__createdAt', 'my-tag']) ->expectsChoice('Choose the sort direction', 'Ascending', ['Ascending', 'Descending']) - ->expectsQuestion('How many links should be shown on the listing page? (any value above 0 will enable pagination)', 0) + ->expectsQuestion(self::selectPageSizeQuestion, 0) - ->expectsChoice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', '__createdAt', ['__createdAt']) + ->expectsChoice(self::selectCanonicalNameQuestion, '__createdAt', ['__createdAt']) ->doesntExpectOutput('Error: Can not create a tag field without any tag groups defined in tags.json') ->assertSuccessful(); From 46453912b3c959bc594ef03a72457c024b843a1f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 12:35:30 +0100 Subject: [PATCH 41/84] Move up canonical field question --- .../Commands/MakePublicationTypeCommand.php | 4 ++-- .../MakePublicationTypeCommandTest.php | 23 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 3b85027ee60..519b4532a03 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -49,12 +49,12 @@ public function safeHandle(): int $this->fields = $this->captureFieldsDefinitions(); + $canonicalField = $this->getCanonicalField(); + $sortField = $this->option('use-defaults') ? null : $this->getSortField(); $sortAscending = $this->option('use-defaults') ? null : $this->getSortDirection(); $pageSize = $this->option('use-defaults') ? null : $this->getPageSize(); - $canonicalField = $this->getCanonicalField(); - $creator = new CreatesNewPublicationType($title, $this->fields, $canonicalField->name, $sortField, $sortAscending, $pageSize); $this->output->writeln("Saving publication data to [{$creator->getOutputPath()}]"); $creator->create(); diff --git a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php index f71b2c7f57b..8c388cfb60e 100644 --- a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php +++ b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php @@ -53,6 +53,12 @@ public function test_command_creates_publication_type() 'Tag', ], true) ->expectsConfirmation('Field #1 added! Add another field?') + + ->expectsChoice(self::selectCanonicalNameQuestion, 'publication-title', [ + '__createdAt', + 'publication-title', + ]) + ->expectsChoice('Choose the field you wish to sort by', '__createdAt', [ '__createdAt', 'publication-title', @@ -62,10 +68,7 @@ public function test_command_creates_publication_type() 'Descending', ]) ->expectsQuestion(self::selectPageSizeQuestion, 10) - ->expectsChoice(self::selectCanonicalNameQuestion, 'publication-title', [ - '__createdAt', - 'publication-title', - ]) + ->expectsOutputToContain('Creating a new Publication Type!') ->expectsOutput('Saving publication data to [test-publication/schema.json]') ->expectsOutput('Publication type created successfully!') @@ -128,16 +131,17 @@ public function test_with_multiple_fields_of_the_same_name() ->expectsConfirmation('Field #2 added! Add another field?') - ->expectsChoice('Choose the field you wish to sort by', '__createdAt', ['__createdAt', 'foo', 'bar']) - ->expectsChoice('Choose the sort direction', 'Ascending', ['Ascending', 'Descending']) - ->expectsQuestion(self::selectPageSizeQuestion, 0) - ->expectsChoice(self::selectCanonicalNameQuestion, 'foo', [ '__createdAt', 'bar', 'foo', ]) + ->expectsChoice('Choose the field you wish to sort by', '__createdAt', ['__createdAt', 'foo', 'bar']) + ->expectsChoice('Choose the sort direction', 'Ascending', ['Ascending', 'Descending']) + ->expectsQuestion(self::selectPageSizeQuestion, 0) + + ->assertExitCode(0); } @@ -243,11 +247,12 @@ public function testWithTagFieldInputButNoTagsCanPromptToCreateTags() ->expectsChoice('Enter tag group for field #1', 'foo', ['foo'], true) ->expectsConfirmation('Field #1 added! Add another field?') + ->expectsChoice(self::selectCanonicalNameQuestion, '__createdAt', ['__createdAt']) + ->expectsChoice('Choose the field you wish to sort by', '__createdAt', ['__createdAt', 'my-tag']) ->expectsChoice('Choose the sort direction', 'Ascending', ['Ascending', 'Descending']) ->expectsQuestion(self::selectPageSizeQuestion, 0) - ->expectsChoice(self::selectCanonicalNameQuestion, '__createdAt', ['__createdAt']) ->doesntExpectOutput('Error: Can not create a tag field without any tag groups defined in tags.json') ->assertSuccessful(); From 40a4c7b53c341fcccef8533b32ee970e43e0ead9 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 12:43:28 +0100 Subject: [PATCH 42/84] Grey out question helper messages --- .../publications/src/Commands/MakePublicationTypeCommand.php | 4 ++-- .../tests/Feature/MakePublicationTypeCommandTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 519b4532a03..c35afee66cc 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -164,7 +164,7 @@ protected function getCanonicalField(): PublicationFieldDefinition $options = $selectableFields->pluck('name'); - $selected = $this->choice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', + $selected = $this->choice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', $options->toArray(), $options->first() ); @@ -203,7 +203,7 @@ protected function getSortDirection(): bool protected function getPageSize(): int { return (int) $this->askWithValidation('pageSize', - 'How many links should be shown on the listing page? (any value above 0 will enable pagination)', + 'How many links should be shown on the listing page? (any value above 0 will enable pagination)', ['required', 'integer', 'between:0,100'], 0 ); diff --git a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php index 8c388cfb60e..4264ef69274 100644 --- a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php +++ b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php @@ -18,8 +18,8 @@ */ class MakePublicationTypeCommandTest extends TestCase { - protected const selectPageSizeQuestion = 'How many links should be shown on the listing page? (any value above 0 will enable pagination)'; - protected const selectCanonicalNameQuestion = 'Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)'; + protected const selectPageSizeQuestion = 'How many links should be shown on the listing page? (any value above 0 will enable pagination)'; + protected const selectCanonicalNameQuestion = 'Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)'; protected function setUp(): void { From 58bb8e664fc576ccf5fde2287e16e4d6a2d0706c Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 13 Jan 2023 11:43:40 +0000 Subject: [PATCH 43/84] Apply fixes from StyleCI --- .../tests/Feature/MakePublicationTypeCommandTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php index 4264ef69274..71207ee30b5 100644 --- a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php +++ b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php @@ -141,7 +141,6 @@ public function test_with_multiple_fields_of_the_same_name() ->expectsChoice('Choose the sort direction', 'Ascending', ['Ascending', 'Descending']) ->expectsQuestion(self::selectPageSizeQuestion, 0) - ->assertExitCode(0); } From be0ed0716b5be84903a4b4c9ca4cd1f79d727727 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:00:45 +0100 Subject: [PATCH 44/84] Remove the --use-defaults option to reduce complexity --- .../Commands/MakePublicationTypeCommand.php | 19 +++++-------------- .../MakePublicationTypeCommandTest.php | 6 +++--- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index c35afee66cc..b6c260ae96c 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -31,8 +31,7 @@ class MakePublicationTypeCommand extends ValidatingCommand { /** @var string */ protected $signature = 'make:publicationType - {name? : The name of the publication type to create} - {--use-defaults : Select the default options wherever possible}'; // Deprecated + {name? : The name of the publication type to create}'; /** @var string */ protected $description = 'Create a new publication type definition'; @@ -51,9 +50,9 @@ public function safeHandle(): int $canonicalField = $this->getCanonicalField(); - $sortField = $this->option('use-defaults') ? null : $this->getSortField(); - $sortAscending = $this->option('use-defaults') ? null : $this->getSortDirection(); - $pageSize = $this->option('use-defaults') ? null : $this->getPageSize(); + $sortField = $this->getSortField(); + $sortAscending = $this->getSortDirection(); + $pageSize = $this->getPageSize(); $creator = new CreatesNewPublicationType($title, $this->fields, $canonicalField->name, $sortField, $sortAscending, $pageSize); $this->output->writeln("Saving publication data to [{$creator->getOutputPath()}]"); @@ -86,11 +85,7 @@ protected function captureFieldsDefinitions(): Collection do { $this->fields->add($this->captureFieldDefinition()); - if ($this->option('use-defaults') === true) { - $addAnother = false; - } else { - $addAnother = $this->confirm("Field #{$this->getCount(-1)} added! Add another field?"); - } + $addAnother = $this->confirm("Field #{$this->getCount(-1)} added! Add another field?"); } while ($addAnother); return $this->fields; @@ -158,10 +153,6 @@ protected function getCanonicalField(): PublicationFieldDefinition return ! in_array($field->type, PublicationFieldTypes::canonicable()); }); - if ($this->option('use-defaults')) { - return $selectableFields->first(); - } - $options = $selectableFields->pluck('name'); $selected = $this->choice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', diff --git a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php index 71207ee30b5..46ecead036f 100644 --- a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php +++ b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php @@ -106,7 +106,7 @@ public function test_command_creates_publication_type() public function test_with_default_values() { - $this->artisan('make:publicationType --use-defaults') + $this->artisan('make:publicationType') ->expectsQuestion('Publication type name', 'Test Publication') ->expectsQuestion('Enter name for field #1', 'foo') ->expectsChoice('Enter type for field #1', 'String', PublicationFieldTypes::names()) @@ -176,7 +176,7 @@ public function testWithTagFieldInput() 'bar' => ['foo', 'baz'], ])->save(); - $this->artisan('make:publicationType "Test Publication" --use-defaults') + $this->artisan('make:publicationType "Test Publication"') ->expectsQuestion('Enter name for field #1', 'MyTag') ->expectsChoice('Enter type for field #1', 'Tag', ['String', 'Datetime', 'Boolean', 'Integer', 'Float', 'Image', 'Array', 'Text', 'Url', 'Tag']) @@ -217,7 +217,7 @@ public function testWithTagFieldInputButNoTags() config(['app.throw_on_console_exception' => false]); $this->directory('test-publication'); - $this->artisan('make:publicationType "Test Publication" --use-defaults') + $this->artisan('make:publicationType "Test Publication"') ->expectsQuestion('Enter name for field #1', 'MyTag') ->expectsChoice('Enter type for field #1', 'Tag', ['String', 'Datetime', 'Boolean', 'Integer', 'Float', 'Image', 'Array', 'Text', 'Url', 'Tag'], true) From abe5dde884ebc6450b646e481183440cf8780300 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:07:48 +0100 Subject: [PATCH 45/84] Return placeholder to support non-interactive inputs --- .../publications/src/Commands/MakePublicationTypeCommand.php | 4 ++++ .../tests/Feature/MakePublicationTypeCommandTest.php | 5 +---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index b6c260ae96c..43c4d86242f 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -112,6 +112,10 @@ protected function captureFieldDefinition(): PublicationFieldDefinition protected function getFieldName(?string $message = null): string { + if (!$this->input->isInteractive()) { + return 'Example Field'; + } + $selected = Str::kebab(trim($this->askWithValidation('name', $message ?? "Enter name for field #{$this->getCount()}", ['required']))); if ($this->checkIfFieldIsDuplicate($selected)) { diff --git a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php index 46ecead036f..ea892f7beab 100644 --- a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php +++ b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php @@ -106,10 +106,7 @@ public function test_command_creates_publication_type() public function test_with_default_values() { - $this->artisan('make:publicationType') - ->expectsQuestion('Publication type name', 'Test Publication') - ->expectsQuestion('Enter name for field #1', 'foo') - ->expectsChoice('Enter type for field #1', 'String', PublicationFieldTypes::names()) + $this->artisan('make:publicationType "Test Publication" --no-interaction') ->expectsOutput('Saving publication data to [test-publication/schema.json]') ->expectsOutput('Publication type created successfully!') ->assertExitCode(0); From 69625a9d23b7bd92729042e56130a7380e16da03 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:19:03 +0100 Subject: [PATCH 46/84] Bypass entire method when not interactive --- .../src/Commands/MakePublicationTypeCommand.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 43c4d86242f..350aebbf873 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -77,6 +77,12 @@ protected function validateStorageDirectory(string $directoryName): void protected function captureFieldsDefinitions(): Collection { + if (!$this->input->isInteractive()) { + $this->fields = Collection::make(); + $this->fields->add(new PublicationFieldDefinition(PublicationFieldTypes::String, 'Example Field')); + return $this->fields; + } + $this->line('You now need to define the fields in your publication type:'); $this->fields = Collection::make(); @@ -112,10 +118,6 @@ protected function captureFieldDefinition(): PublicationFieldDefinition protected function getFieldName(?string $message = null): string { - if (!$this->input->isInteractive()) { - return 'Example Field'; - } - $selected = Str::kebab(trim($this->askWithValidation('name', $message ?? "Enter name for field #{$this->getCount()}", ['required']))); if ($this->checkIfFieldIsDuplicate($selected)) { From 8c0a7ca5de28cf77036f0c682718710dcf8b1fb8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:20:19 +0100 Subject: [PATCH 47/84] The default value should be string to match actual returned type --- .../publications/src/Commands/MakePublicationTypeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 350aebbf873..beb132233e6 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -202,7 +202,7 @@ protected function getPageSize(): int return (int) $this->askWithValidation('pageSize', 'How many links should be shown on the listing page? (any value above 0 will enable pagination)', ['required', 'integer', 'between:0,100'], - 0 + '0' ); } From 0a15afaa89dd9ec251e0f672e47a449ecfb304a5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:22:29 +0100 Subject: [PATCH 48/84] Add method overrides to support non-interactive prompts --- .../Commands/MakePublicationTypeCommand.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index beb132233e6..5565cb7d095 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -210,4 +210,31 @@ protected function getCount(int $offset = 0): int { return $this->fields->count() + $offset; } + + public function choice($question, array $choices, $default = null, $attempts = null, $multiple = false) + { + if ($this->input->isInteractive()) { + return parent::choice($question, $choices, $default, $attempts, $multiple); + } + + return $choices[$default] ?? $default; + } + + public function confirm($question, $default = false) + { + if ($this->input->isInteractive()) { + return parent::confirm($question, $default); + } + + return $default; + } + + public function askWithValidation(string $name, string $question, array $rules = [], mixed $default = null, int $retryCount = 0): string + { + if ($this->input->isInteractive()) { + return parent::askWithValidation($name, $question, $rules, $default, $retryCount); + } + + return $default; + } } From 426cb6989654950bb92f2b9c0cef4084eb680a75 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:23:09 +0100 Subject: [PATCH 49/84] Revert "Add method overrides to support non-interactive prompts" as the fix only changes behaviour during testing This reverts commit 0a15afaa89dd9ec251e0f672e47a449ecfb304a5 as the fix only changes behaviour during testing. During actual usage, non-interactive prompts work fine. --- .../Commands/MakePublicationTypeCommand.php | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 5565cb7d095..beb132233e6 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -210,31 +210,4 @@ protected function getCount(int $offset = 0): int { return $this->fields->count() + $offset; } - - public function choice($question, array $choices, $default = null, $attempts = null, $multiple = false) - { - if ($this->input->isInteractive()) { - return parent::choice($question, $choices, $default, $attempts, $multiple); - } - - return $choices[$default] ?? $default; - } - - public function confirm($question, $default = false) - { - if ($this->input->isInteractive()) { - return parent::confirm($question, $default); - } - - return $default; - } - - public function askWithValidation(string $name, string $question, array $rules = [], mixed $default = null, int $retryCount = 0): string - { - if ($this->input->isInteractive()) { - return parent::askWithValidation($name, $question, $rules, $default, $retryCount); - } - - return $default; - } } From 3ae7ebb6dba9655d8bef4eadc66fbd9a3df64bf1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:27:41 +0100 Subject: [PATCH 50/84] Disable output mocking due to presumed vendor bug --- .../tests/Feature/MakePublicationTypeCommandTest.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php index ea892f7beab..334dc9781a3 100644 --- a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php +++ b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php @@ -106,10 +106,12 @@ public function test_command_creates_publication_type() public function test_with_default_values() { - $this->artisan('make:publicationType "Test Publication" --no-interaction') - ->expectsOutput('Saving publication data to [test-publication/schema.json]') - ->expectsOutput('Publication type created successfully!') - ->assertExitCode(0); + // When running this command with the no-interaction flag in an actual console, no questions are asked. + // However, when running it in a test, the questions are still asked, presumably due to a vendor bug. + + $this->withoutMockingConsoleOutput(); + + $this->assertSame(0, $this->artisan('make:publicationType "Test Publication" --no-interaction')); } public function test_with_multiple_fields_of_the_same_name() From 3e616ef80b124b5cbea9e8da8af52e7279b4b0e3 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 13 Jan 2023 12:28:10 +0000 Subject: [PATCH 51/84] Apply fixes from StyleCI --- .../publications/src/Commands/MakePublicationTypeCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index beb132233e6..3f22c300971 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -77,9 +77,10 @@ protected function validateStorageDirectory(string $directoryName): void protected function captureFieldsDefinitions(): Collection { - if (!$this->input->isInteractive()) { + if (! $this->input->isInteractive()) { $this->fields = Collection::make(); $this->fields->add(new PublicationFieldDefinition(PublicationFieldTypes::String, 'Example Field')); + return $this->fields; } From c49cd62fb8b0804ac5aed49e4f3a40a70752169a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:30:06 +0100 Subject: [PATCH 52/84] Revert type change --- .../publications/src/Commands/MakePublicationTypeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 3f22c300971..58a58cd8460 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -203,7 +203,7 @@ protected function getPageSize(): int return (int) $this->askWithValidation('pageSize', 'How many links should be shown on the listing page? (any value above 0 will enable pagination)', ['required', 'integer', 'between:0,100'], - '0' + 0 ); } From 53c0243d9591e5756b303b7d9909450bb30a0f6e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:33:35 +0100 Subject: [PATCH 53/84] Update MakePublicationTypeCommandTest.php --- .../tests/Feature/MakePublicationTypeCommandTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php index 334dc9781a3..4a6a15e5963 100644 --- a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php +++ b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php @@ -180,6 +180,13 @@ public function testWithTagFieldInput() ->expectsChoice('Enter type for field #1', 'Tag', ['String', 'Datetime', 'Boolean', 'Integer', 'Float', 'Image', 'Array', 'Text', 'Url', 'Tag']) ->expectsChoice('Enter tag group for field #1', 'foo', ['bar', 'foo'], true) + + ->expectsConfirmation('Field #1 added! Add another field?') + ->expectsChoice(self::selectCanonicalNameQuestion, '__createdAt', ['__createdAt']) + ->expectsChoice('Choose the field you wish to sort by', '__createdAt', ['__createdAt', 'my-tag']) + ->expectsChoice('Choose the sort direction', 'Ascending', ['Ascending', 'Descending']) + ->expectsQuestion(self::selectPageSizeQuestion, 0) + ->assertSuccessful(); $this->assertFileExists(Hyde::path('test-publication/schema.json')); From ea24df032288b8dc46da79eef3d16dacd4c01e78 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:33:41 +0100 Subject: [PATCH 54/84] Add todo --- .../publications/src/Commands/MakePublicationTypeCommand.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 58a58cd8460..79ada0f4f4a 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -188,6 +188,8 @@ protected function addCreatedAtMetaField(): void protected function getSortField(): string { + // todo non-canonicable fields should not be allowed to be used for sorting + return $this->choice('Choose the field you wish to sort by', $this->fields->pluck('name')->toArray(), 0); } From 2bd619967c3a3e96034c712935e1b15e0c431e5f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:36:06 +0100 Subject: [PATCH 55/84] Non-canonicable fields should not be allowed to be used for sorting --- .../src/Commands/MakePublicationTypeCommand.php | 8 ++++++-- .../tests/Feature/MakePublicationTypeCommandTest.php | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 79ada0f4f4a..d9acfc27415 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -188,9 +188,13 @@ protected function addCreatedAtMetaField(): void protected function getSortField(): string { - // todo non-canonicable fields should not be allowed to be used for sorting + $selectableFields = $this->fields->reject(function (PublicationFieldDefinition $field): bool { + return ! in_array($field->type, PublicationFieldTypes::canonicable()); + }); + + $options = $selectableFields->pluck('name')->toArray(); - return $this->choice('Choose the field you wish to sort by', $this->fields->pluck('name')->toArray(), 0); + return $this->choice('Choose the field you wish to sort by', $options, 0); } protected function getSortDirection(): bool diff --git a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php index 4a6a15e5963..9dddce08dd0 100644 --- a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php +++ b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php @@ -183,7 +183,7 @@ public function testWithTagFieldInput() ->expectsConfirmation('Field #1 added! Add another field?') ->expectsChoice(self::selectCanonicalNameQuestion, '__createdAt', ['__createdAt']) - ->expectsChoice('Choose the field you wish to sort by', '__createdAt', ['__createdAt', 'my-tag']) + ->expectsChoice('Choose the field you wish to sort by', '__createdAt', ['__createdAt']) ->expectsChoice('Choose the sort direction', 'Ascending', ['Ascending', 'Descending']) ->expectsQuestion(self::selectPageSizeQuestion, 0) @@ -254,7 +254,7 @@ public function testWithTagFieldInputButNoTagsCanPromptToCreateTags() ->expectsChoice(self::selectCanonicalNameQuestion, '__createdAt', ['__createdAt']) - ->expectsChoice('Choose the field you wish to sort by', '__createdAt', ['__createdAt', 'my-tag']) + ->expectsChoice('Choose the field you wish to sort by', '__createdAt', ['__createdAt']) ->expectsChoice('Choose the sort direction', 'Ascending', ['Ascending', 'Descending']) ->expectsQuestion(self::selectPageSizeQuestion, 0) From edd586f1ee46f73c7d7314852a7349dc70c10236 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:37:25 +0100 Subject: [PATCH 56/84] Reorder methods to match usage flow --- .../Commands/MakePublicationTypeCommand.php | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index d9acfc27415..04f6d029f62 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -170,22 +170,6 @@ protected function getCanonicalField(): PublicationFieldDefinition return $this->fields->firstWhere('name', $selected); } - protected function checkIfFieldIsDuplicate($name): bool - { - if ($this->fields->where('name', $name)->count() > 0) { - $this->error("Field name [$name] already exists!"); - - return true; - } - - return false; - } - - protected function addCreatedAtMetaField(): void - { - $this->fields->add(new PublicationFieldDefinition(PublicationFieldTypes::Datetime, '__createdAt')); - } - protected function getSortField(): string { $selectableFields = $this->fields->reject(function (PublicationFieldDefinition $field): bool { @@ -213,6 +197,22 @@ protected function getPageSize(): int ); } + protected function checkIfFieldIsDuplicate($name): bool + { + if ($this->fields->where('name', $name)->count() > 0) { + $this->error("Field name [$name] already exists!"); + + return true; + } + + return false; + } + + protected function addCreatedAtMetaField(): void + { + $this->fields->add(new PublicationFieldDefinition(PublicationFieldTypes::Datetime, '__createdAt')); + } + protected function getCount(int $offset = 0): int { return $this->fields->count() + $offset; From a792b5bb8671ca603d8b8bfee7221d9c927178c4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:39:50 +0100 Subject: [PATCH 57/84] Add assertions on the generated default file --- .../MakePublicationTypeCommandTest.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php index 9dddce08dd0..f90c3565cd2 100644 --- a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php +++ b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php @@ -112,6 +112,31 @@ public function test_with_default_values() $this->withoutMockingConsoleOutput(); $this->assertSame(0, $this->artisan('make:publicationType "Test Publication" --no-interaction')); + + $this->assertFileExists(Hyde::path('test-publication/schema.json')); + $this->assertEquals( + <<<'JSON' + { + "name": "Test Publication", + "canonicalField": "example-field", + "detailTemplate": "detail.blade.php", + "listTemplate": "list.blade.php", + "sortField": "example-field", + "sortAscending": true, + "pageSize": 0, + "fields": [ + { + "type": "string", + "name": "example-field" + } + ] + } + JSON, + file_get_contents(Hyde::path('test-publication/schema.json')) + ); + + $this->assertFileExists(Hyde::path('test-publication/detail.blade.php')); + $this->assertFileExists(Hyde::path('test-publication/list.blade.php')); } public function test_with_multiple_fields_of_the_same_name() From 24d757eb7b475c72ac740da4d78c6c964fe8d518 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:42:05 +0100 Subject: [PATCH 58/84] Change helper method to void as that changes nothing --- .../src/Commands/MakePublicationTypeCommand.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 04f6d029f62..be77631e23f 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -46,7 +46,7 @@ public function safeHandle(): int $this->validateStorageDirectory(Str::slug($title)); - $this->fields = $this->captureFieldsDefinitions(); + $this->captureFieldsDefinitions(); $canonicalField = $this->getCanonicalField(); @@ -75,13 +75,13 @@ protected function validateStorageDirectory(string $directoryName): void } } - protected function captureFieldsDefinitions(): Collection + protected function captureFieldsDefinitions(): void { if (! $this->input->isInteractive()) { $this->fields = Collection::make(); $this->fields->add(new PublicationFieldDefinition(PublicationFieldTypes::String, 'Example Field')); - return $this->fields; + return; } $this->line('You now need to define the fields in your publication type:'); @@ -94,8 +94,6 @@ protected function captureFieldsDefinitions(): Collection $addAnother = $this->confirm("Field #{$this->getCount(-1)} added! Add another field?"); } while ($addAnother); - - return $this->fields; } protected function captureFieldDefinition(): PublicationFieldDefinition From 544c742a94dc4f8d83e34d02fb20f20d367fa19e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:42:32 +0100 Subject: [PATCH 59/84] Inline local variable --- .../publications/src/Commands/MakePublicationTypeCommand.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index be77631e23f..7220181ab96 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -174,9 +174,7 @@ protected function getSortField(): string return ! in_array($field->type, PublicationFieldTypes::canonicable()); }); - $options = $selectableFields->pluck('name')->toArray(); - - return $this->choice('Choose the field you wish to sort by', $options, 0); + return $this->choice('Choose the field you wish to sort by', $selectableFields->pluck('name')->toArray(), 0); } protected function getSortDirection(): bool From a6a89b85ed6f681b1a920e72b8a37c3c9208f19b Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:43:10 +0100 Subject: [PATCH 60/84] Extract method for repeated code --- .../src/Commands/MakePublicationTypeCommand.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 7220181ab96..3cd35ba809f 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -154,9 +154,7 @@ protected function getTagGroup(): string protected function getCanonicalField(): PublicationFieldDefinition { - $selectableFields = $this->fields->reject(function (PublicationFieldDefinition $field): bool { - return ! in_array($field->type, PublicationFieldTypes::canonicable()); - }); + $selectableFields = $this->availableFieldsWithoutCanonicalTypes(); $options = $selectableFields->pluck('name'); @@ -170,9 +168,7 @@ protected function getCanonicalField(): PublicationFieldDefinition protected function getSortField(): string { - $selectableFields = $this->fields->reject(function (PublicationFieldDefinition $field): bool { - return ! in_array($field->type, PublicationFieldTypes::canonicable()); - }); + $selectableFields = $this->availableFieldsWithoutCanonicalTypes(); return $this->choice('Choose the field you wish to sort by', $selectableFields->pluck('name')->toArray(), 0); } @@ -213,4 +209,11 @@ protected function getCount(int $offset = 0): int { return $this->fields->count() + $offset; } + + protected function availableFieldsWithoutCanonicalTypes(): Collection + { + return $this->fields->reject(function (PublicationFieldDefinition $field): bool { + return !in_array($field->type, PublicationFieldTypes::canonicable()); + }); + } } From e283557bd81c786df0ea5369e378856fc2820d66 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:46:27 +0100 Subject: [PATCH 61/84] Remove the __createdAt meta field from generated JSON --- .../src/Commands/MakePublicationTypeCommand.php | 4 ++++ .../tests/Feature/MakePublicationTypeCommandTest.php | 8 -------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 3cd35ba809f..530b1d9d772 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -54,6 +54,10 @@ public function safeHandle(): int $sortAscending = $this->getSortDirection(); $pageSize = $this->getPageSize(); + if ($this->fields->first()->name === '__createdAt') { + $this->fields->shift(); + } + $creator = new CreatesNewPublicationType($title, $this->fields, $canonicalField->name, $sortField, $sortAscending, $pageSize); $this->output->writeln("Saving publication data to [{$creator->getOutputPath()}]"); $creator->create(); diff --git a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php index f90c3565cd2..ba631a15d44 100644 --- a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php +++ b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php @@ -86,10 +86,6 @@ public function test_command_creates_publication_type() "sortAscending": true, "pageSize": 10, "fields": [ - { - "type": "datetime", - "name": "__createdAt" - }, { "type": "string", "name": "publication-title" @@ -226,10 +222,6 @@ public function testWithTagFieldInput() "sortAscending": true, "pageSize": 0, "fields": [ - { - "type": "datetime", - "name": "__createdAt" - }, { "type": "tag", "name": "my-tag", From 6783f0a57ee0fa98f8c9cf47b5e8a03c47aecf7d Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 13 Jan 2023 12:46:42 +0000 Subject: [PATCH 62/84] Apply fixes from StyleCI --- .../publications/src/Commands/MakePublicationTypeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 530b1d9d772..80310d0683d 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -217,7 +217,7 @@ protected function getCount(int $offset = 0): int protected function availableFieldsWithoutCanonicalTypes(): Collection { return $this->fields->reject(function (PublicationFieldDefinition $field): bool { - return !in_array($field->type, PublicationFieldTypes::canonicable()); + return ! in_array($field->type, PublicationFieldTypes::canonicable()); }); } } From 3f9f9a0541e686a38beb7783ea4cf17de179553d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:51:53 +0100 Subject: [PATCH 63/84] Assert the proper templates were published --- .../tests/Feature/MakePublicationTypeCommandTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php index ba631a15d44..1ff0c001b99 100644 --- a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php +++ b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php @@ -98,6 +98,8 @@ public function test_command_creates_publication_type() $this->assertFileExists(Hyde::path('test-publication/detail.blade.php')); $this->assertFileExists(Hyde::path('test-publication/list.blade.php')); + + $this->assertStringContainsString('paginator', file_get_contents(Hyde::path('test-publication/list.blade.php'))); } public function test_with_default_values() @@ -133,6 +135,8 @@ public function test_with_default_values() $this->assertFileExists(Hyde::path('test-publication/detail.blade.php')); $this->assertFileExists(Hyde::path('test-publication/list.blade.php')); + + $this->assertStringNotContainsString('paginator', file_get_contents(Hyde::path('test-publication/list.blade.php'))); } public function test_with_multiple_fields_of_the_same_name() From 8f392ccc8977b37969e6c31a02f186df00506747 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:56:14 +0100 Subject: [PATCH 64/84] Format code and clean up presentation --- .../src/Commands/MakePublicationTypeCommand.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 80310d0683d..2fb28c34bb4 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -14,6 +14,7 @@ use Illuminate\Support\Collection; use Illuminate\Support\Str; use InvalidArgumentException; +use function in_array; use function is_dir; use function is_file; use LaravelZero\Framework\Commands\Command; @@ -30,11 +31,10 @@ class MakePublicationTypeCommand extends ValidatingCommand { /** @var string */ - protected $signature = 'make:publicationType - {name? : The name of the publication type to create}'; + protected $signature = 'make:publicationType {name? : The name of the publication type to create}'; /** @var string */ - protected $description = 'Create a new publication type definition'; + protected $description = 'Create a new publication type'; protected Collection $fields; @@ -43,13 +43,11 @@ public function safeHandle(): int $this->title('Creating a new Publication Type!'); $title = $this->getTitle(); - $this->validateStorageDirectory(Str::slug($title)); $this->captureFieldsDefinitions(); $canonicalField = $this->getCanonicalField(); - $sortField = $this->getSortField(); $sortAscending = $this->getSortDirection(); $pageSize = $this->getPageSize(); @@ -88,7 +86,7 @@ protected function captureFieldsDefinitions(): void return; } - $this->line('You now need to define the fields in your publication type:'); + $this->line('Now please define the fields for your publication type:'); $this->fields = Collection::make(); $this->addCreatedAtMetaField(); From 3c85dfea3f8fe164eab072a25fabe80cf724bd52 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 13:59:02 +0100 Subject: [PATCH 65/84] Refactor code semantics --- .../src/Commands/MakePublicationTypeCommand.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 2fb28c34bb4..7ad95ea4281 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -80,16 +80,18 @@ protected function validateStorageDirectory(string $directoryName): void protected function captureFieldsDefinitions(): void { if (! $this->input->isInteractive()) { - $this->fields = Collection::make(); - $this->fields->add(new PublicationFieldDefinition(PublicationFieldTypes::String, 'Example Field')); + $this->fields = Collection::make([ + new PublicationFieldDefinition(PublicationFieldTypes::String, 'Example Field') + ]); return; } $this->line('Now please define the fields for your publication type:'); - $this->fields = Collection::make(); - $this->addCreatedAtMetaField(); + $this->fields = Collection::make([ + new PublicationFieldDefinition(PublicationFieldTypes::Datetime, '__createdAt') + ]); do { $this->fields->add($this->captureFieldDefinition()); @@ -202,11 +204,6 @@ protected function checkIfFieldIsDuplicate($name): bool return false; } - protected function addCreatedAtMetaField(): void - { - $this->fields->add(new PublicationFieldDefinition(PublicationFieldTypes::Datetime, '__createdAt')); - } - protected function getCount(int $offset = 0): int { return $this->fields->count() + $offset; From ec2cc5bea9585e5aea6f4406fdd40bb20ed3352f Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:02:04 +0100 Subject: [PATCH 66/84] Expect default state to use __createdAt for sorting --- .../tests/Feature/MakePublicationTypeCommandTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php index 1ff0c001b99..faffbc7f80d 100644 --- a/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php +++ b/packages/publications/tests/Feature/MakePublicationTypeCommandTest.php @@ -116,10 +116,10 @@ public function test_with_default_values() <<<'JSON' { "name": "Test Publication", - "canonicalField": "example-field", + "canonicalField": "__createdAt", "detailTemplate": "detail.blade.php", "listTemplate": "list.blade.php", - "sortField": "example-field", + "sortField": "__createdAt", "sortAscending": true, "pageSize": 0, "fields": [ From 6acded382967ae6daeafe0c799dbba78751b1ef4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:03:22 +0100 Subject: [PATCH 67/84] Merge non-interactive handling to inject default value in normal control flow --- .../src/Commands/MakePublicationTypeCommand.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 7ad95ea4281..b72e8a96fae 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -79,14 +79,6 @@ protected function validateStorageDirectory(string $directoryName): void protected function captureFieldsDefinitions(): void { - if (! $this->input->isInteractive()) { - $this->fields = Collection::make([ - new PublicationFieldDefinition(PublicationFieldTypes::String, 'Example Field') - ]); - - return; - } - $this->line('Now please define the fields for your publication type:'); $this->fields = Collection::make([ @@ -121,7 +113,9 @@ protected function captureFieldDefinition(): PublicationFieldDefinition protected function getFieldName(?string $message = null): string { - $selected = Str::kebab(trim($this->askWithValidation('name', $message ?? "Enter name for field #{$this->getCount()}", ['required']))); + $default = $this->input->isInteractive() ? null: 'Example Field'; + + $selected = Str::kebab(trim($this->askWithValidation('name', $message ?? "Enter name for field #{$this->getCount()}", ['required'], default: $default))); if ($this->checkIfFieldIsDuplicate($selected)) { return $this->getFieldName("Try again: Enter name for field #{$this->getCount()}"); From be8d899700fa23541b61c9bab3dea76cf9811026 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:04:32 +0100 Subject: [PATCH 68/84] Introduce local variable and wrap code --- .../publications/src/Commands/MakePublicationTypeCommand.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index b72e8a96fae..2fb49724607 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -114,8 +114,11 @@ protected function captureFieldDefinition(): PublicationFieldDefinition protected function getFieldName(?string $message = null): string { $default = $this->input->isInteractive() ? null: 'Example Field'; + $message ??= "Enter name for field #{$this->getCount()}"; - $selected = Str::kebab(trim($this->askWithValidation('name', $message ?? "Enter name for field #{$this->getCount()}", ['required'], default: $default))); + $selected = Str::kebab(trim($this->askWithValidation( + 'name', $message, ['required'], default: $default + ))); if ($this->checkIfFieldIsDuplicate($selected)) { return $this->getFieldName("Try again: Enter name for field #{$this->getCount()}"); From d84fa2741c08a95aa5c6f69471205ffec5182401 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:04:49 +0100 Subject: [PATCH 69/84] Switch order of local variables --- .../publications/src/Commands/MakePublicationTypeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 2fb49724607..4bf4b56246e 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -113,8 +113,8 @@ protected function captureFieldDefinition(): PublicationFieldDefinition protected function getFieldName(?string $message = null): string { - $default = $this->input->isInteractive() ? null: 'Example Field'; $message ??= "Enter name for field #{$this->getCount()}"; + $default = $this->input->isInteractive() ? null: 'Example Field'; $selected = Str::kebab(trim($this->askWithValidation( 'name', $message, ['required'], default: $default From a30691d2641354037d029a06f8448ef2ed3920a8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:05:40 +0100 Subject: [PATCH 70/84] Inline local variables and format method code --- .../src/Commands/MakePublicationTypeCommand.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 4bf4b56246e..c72e8e92fc4 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -129,11 +129,11 @@ protected function getFieldName(?string $message = null): string protected function getFieldType(): PublicationFieldTypes { - $options = PublicationFieldTypes::names(); - - $choice = $this->choice("Enter type for field #{$this->getCount()}", $options, 'String'); - - return PublicationFieldTypes::from(strtolower($choice)); + return PublicationFieldTypes::from(strtolower($this->choice( + "Enter type for field #{$this->getCount()}", + PublicationFieldTypes::names(), + 'String' + ))); } protected function getTagGroup(): string From 90ed2259361bd7e51ff1ed3f34f9acf9b86d20ee Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:06:50 +0100 Subject: [PATCH 71/84] Inline local variable --- .../publications/src/Commands/MakePublicationTypeCommand.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index c72e8e92fc4..0ade692e983 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -169,9 +169,7 @@ protected function getCanonicalField(): PublicationFieldDefinition protected function getSortField(): string { - $selectableFields = $this->availableFieldsWithoutCanonicalTypes(); - - return $this->choice('Choose the field you wish to sort by', $selectableFields->pluck('name')->toArray(), 0); + return $this->choice('Choose the field you wish to sort by', $this->availableFieldsWithoutCanonicalTypes()->pluck('name')->toArray(), 0); } protected function getSortDirection(): bool From 3ef1a3db0066eabc1aed8ac9bc9df7095a85764a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:07:47 +0100 Subject: [PATCH 72/84] Rename inversely named helper method --- .../src/Commands/MakePublicationTypeCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 0ade692e983..2d4e5ce569e 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -155,7 +155,7 @@ protected function getTagGroup(): string protected function getCanonicalField(): PublicationFieldDefinition { - $selectableFields = $this->availableFieldsWithoutCanonicalTypes(); + $selectableFields = $this->availableFieldsWithCanonicalTypes(); $options = $selectableFields->pluck('name'); @@ -169,7 +169,7 @@ protected function getCanonicalField(): PublicationFieldDefinition protected function getSortField(): string { - return $this->choice('Choose the field you wish to sort by', $this->availableFieldsWithoutCanonicalTypes()->pluck('name')->toArray(), 0); + return $this->choice('Choose the field you wish to sort by', $this->availableFieldsWithCanonicalTypes()->pluck('name')->toArray(), 0); } protected function getSortDirection(): bool @@ -204,7 +204,7 @@ protected function getCount(int $offset = 0): int return $this->fields->count() + $offset; } - protected function availableFieldsWithoutCanonicalTypes(): Collection + protected function availableFieldsWithCanonicalTypes(): Collection { return $this->fields->reject(function (PublicationFieldDefinition $field): bool { return ! in_array($field->type, PublicationFieldTypes::canonicable()); From f2cb6cf734920d20c24534f332ebdc63370104f6 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:08:12 +0100 Subject: [PATCH 73/84] Shorten helper method name --- .../src/Commands/MakePublicationTypeCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 2d4e5ce569e..6e9bc9e368c 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -155,7 +155,7 @@ protected function getTagGroup(): string protected function getCanonicalField(): PublicationFieldDefinition { - $selectableFields = $this->availableFieldsWithCanonicalTypes(); + $selectableFields = $this->availableCanonicableFields(); $options = $selectableFields->pluck('name'); @@ -169,7 +169,7 @@ protected function getCanonicalField(): PublicationFieldDefinition protected function getSortField(): string { - return $this->choice('Choose the field you wish to sort by', $this->availableFieldsWithCanonicalTypes()->pluck('name')->toArray(), 0); + return $this->choice('Choose the field you wish to sort by', $this->availableCanonicableFields()->pluck('name')->toArray(), 0); } protected function getSortDirection(): bool @@ -204,7 +204,7 @@ protected function getCount(int $offset = 0): int return $this->fields->count() + $offset; } - protected function availableFieldsWithCanonicalTypes(): Collection + protected function availableCanonicableFields(): Collection { return $this->fields->reject(function (PublicationFieldDefinition $field): bool { return ! in_array($field->type, PublicationFieldTypes::canonicable()); From b71b72242488601a4d8360fdbc9255a9bb67face Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:08:29 +0100 Subject: [PATCH 74/84] Inline variable --- .../publications/src/Commands/MakePublicationTypeCommand.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 6e9bc9e368c..ff946b16a8a 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -155,9 +155,7 @@ protected function getTagGroup(): string protected function getCanonicalField(): PublicationFieldDefinition { - $selectableFields = $this->availableCanonicableFields(); - - $options = $selectableFields->pluck('name'); + $options = $this->availableCanonicableFields()->pluck('name'); $selected = $this->choice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', $options->toArray(), From 6c7bc86e04d46ebe61da6fb770d86cbdb06f8afd Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:09:03 +0100 Subject: [PATCH 75/84] Shift method chain for helper method usage with matching operations --- .../src/Commands/MakePublicationTypeCommand.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index ff946b16a8a..26db6c6975d 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -155,7 +155,7 @@ protected function getTagGroup(): string protected function getCanonicalField(): PublicationFieldDefinition { - $options = $this->availableCanonicableFields()->pluck('name'); + $options = $this->availableCanonicableFieldNames(); $selected = $this->choice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', $options->toArray(), @@ -167,7 +167,7 @@ protected function getCanonicalField(): PublicationFieldDefinition protected function getSortField(): string { - return $this->choice('Choose the field you wish to sort by', $this->availableCanonicableFields()->pluck('name')->toArray(), 0); + return $this->choice('Choose the field you wish to sort by', $this->availableCanonicableFieldNames()->toArray(), 0); } protected function getSortDirection(): bool @@ -202,10 +202,10 @@ protected function getCount(int $offset = 0): int return $this->fields->count() + $offset; } - protected function availableCanonicableFields(): Collection + protected function availableCanonicableFieldNames(): Collection { return $this->fields->reject(function (PublicationFieldDefinition $field): bool { return ! in_array($field->type, PublicationFieldTypes::canonicable()); - }); + })->pluck('name'); } } From 39fc53b2a8465bb9686dd68a504e814057a1a668 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:09:36 +0100 Subject: [PATCH 76/84] Document method --- .../publications/src/Commands/MakePublicationTypeCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 26db6c6975d..333efa01315 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -202,6 +202,7 @@ protected function getCount(int $offset = 0): int return $this->fields->count() + $offset; } + /** Get a collection of names for added fields that can be canonicable */ protected function availableCanonicableFieldNames(): Collection { return $this->fields->reject(function (PublicationFieldDefinition $field): bool { From d20e0956f31c8528fe65982977f89fd1bce2975a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:09:39 +0100 Subject: [PATCH 77/84] Revert "Document method" This reverts commit 39fc53b2a8465bb9686dd68a504e814057a1a668. --- .../publications/src/Commands/MakePublicationTypeCommand.php | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 333efa01315..26db6c6975d 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -202,7 +202,6 @@ protected function getCount(int $offset = 0): int return $this->fields->count() + $offset; } - /** Get a collection of names for added fields that can be canonicable */ protected function availableCanonicableFieldNames(): Collection { return $this->fields->reject(function (PublicationFieldDefinition $field): bool { From b9423414abc66107e5e4e97900daba13b48bcaa5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:10:15 +0100 Subject: [PATCH 78/84] Inline variable --- .../src/Commands/MakePublicationTypeCommand.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 26db6c6975d..2f31bdb3ae7 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -157,12 +157,11 @@ protected function getCanonicalField(): PublicationFieldDefinition { $options = $this->availableCanonicableFieldNames(); - $selected = $this->choice('Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', + return $this->fields->firstWhere('name', $this->choice( + 'Choose a canonical name field (this will be used to generate filenames, so the values need to be unique)', $options->toArray(), $options->first() - ); - - return $this->fields->firstWhere('name', $selected); + )); } protected function getSortField(): string From 9902d280a48ce159d1e0de645071d34e71465b66 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:12:02 +0100 Subject: [PATCH 79/84] Unwrap offset option from helper method and remote its parameter --- .../src/Commands/MakePublicationTypeCommand.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 2f31bdb3ae7..a9ad59e187c 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -88,7 +88,8 @@ protected function captureFieldsDefinitions(): void do { $this->fields->add($this->captureFieldDefinition()); - $addAnother = $this->confirm("Field #{$this->getCount(-1)} added! Add another field?"); + $offsetCount = $this->getCount() - 1; + $addAnother = $this->confirm("Field #$offsetCount added! Add another field?"); } while ($addAnother); } @@ -196,9 +197,9 @@ protected function checkIfFieldIsDuplicate($name): bool return false; } - protected function getCount(int $offset = 0): int + protected function getCount(): int { - return $this->fields->count() + $offset; + return $this->fields->count(); } protected function availableCanonicableFieldNames(): Collection From 8fdfe487eeb075e1b1de94637e1b2e2c76599939 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:12:16 +0100 Subject: [PATCH 80/84] Inline variable --- .../publications/src/Commands/MakePublicationTypeCommand.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index a9ad59e187c..078fe348e15 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -88,8 +88,7 @@ protected function captureFieldsDefinitions(): void do { $this->fields->add($this->captureFieldDefinition()); - $offsetCount = $this->getCount() - 1; - $addAnother = $this->confirm("Field #$offsetCount added! Add another field?"); + $addAnother = $this->confirm("Field #".($this->getCount() - 1)." added! Add another field?"); } while ($addAnother); } From 0a2b23c230f11b4f5e8b69db89a77ce36b76f5a3 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 13 Jan 2023 13:12:29 +0000 Subject: [PATCH 81/84] Apply fixes from StyleCI --- .../src/Commands/MakePublicationTypeCommand.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 078fe348e15..c35c0bbbb78 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -13,8 +13,8 @@ use Hyde\Publications\PublicationFieldTypes; use Illuminate\Support\Collection; use Illuminate\Support\Str; -use InvalidArgumentException; use function in_array; +use InvalidArgumentException; use function is_dir; use function is_file; use LaravelZero\Framework\Commands\Command; @@ -82,13 +82,13 @@ protected function captureFieldsDefinitions(): void $this->line('Now please define the fields for your publication type:'); $this->fields = Collection::make([ - new PublicationFieldDefinition(PublicationFieldTypes::Datetime, '__createdAt') + new PublicationFieldDefinition(PublicationFieldTypes::Datetime, '__createdAt'), ]); do { $this->fields->add($this->captureFieldDefinition()); - $addAnother = $this->confirm("Field #".($this->getCount() - 1)." added! Add another field?"); + $addAnother = $this->confirm('Field #'.($this->getCount() - 1).' added! Add another field?'); } while ($addAnother); } @@ -114,7 +114,7 @@ protected function captureFieldDefinition(): PublicationFieldDefinition protected function getFieldName(?string $message = null): string { $message ??= "Enter name for field #{$this->getCount()}"; - $default = $this->input->isInteractive() ? null: 'Example Field'; + $default = $this->input->isInteractive() ? null : 'Example Field'; $selected = Str::kebab(trim($this->askWithValidation( 'name', $message, ['required'], default: $default From 729c02fe7f78d537c015a80137639e9cffe353e5 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:13:59 +0100 Subject: [PATCH 82/84] Convert concatenation to 'sprintf()' call --- .../publications/src/Commands/MakePublicationTypeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index c35c0bbbb78..044ef075cb1 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -88,7 +88,7 @@ protected function captureFieldsDefinitions(): void do { $this->fields->add($this->captureFieldDefinition()); - $addAnother = $this->confirm('Field #'.($this->getCount() - 1).' added! Add another field?'); + $addAnother = $this->confirm(sprintf("Field #%d added! Add another field?", $this->getCount() - 1)); } while ($addAnother); } From 6b6daedaf8899f3eaef039542f5399a39b35223a Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 13 Jan 2023 13:14:21 +0000 Subject: [PATCH 83/84] Apply fixes from StyleCI --- .../publications/src/Commands/MakePublicationTypeCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/publications/src/Commands/MakePublicationTypeCommand.php b/packages/publications/src/Commands/MakePublicationTypeCommand.php index 044ef075cb1..63fd82ad496 100644 --- a/packages/publications/src/Commands/MakePublicationTypeCommand.php +++ b/packages/publications/src/Commands/MakePublicationTypeCommand.php @@ -88,7 +88,7 @@ protected function captureFieldsDefinitions(): void do { $this->fields->add($this->captureFieldDefinition()); - $addAnother = $this->confirm(sprintf("Field #%d added! Add another field?", $this->getCount() - 1)); + $addAnother = $this->confirm(sprintf('Field #%d added! Add another field?', $this->getCount() - 1)); } while ($addAnother); } From 54186c34b704438fec99cf6cd4c314c1b10728f4 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 13 Jan 2023 14:24:11 +0100 Subject: [PATCH 84/84] Revert "Update virtual page class to support custom closure compiling" This reverts commit 2c147e29f72637699e204ff3978be4fd8afea687. --- packages/framework/src/Pages/VirtualPage.php | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/packages/framework/src/Pages/VirtualPage.php b/packages/framework/src/Pages/VirtualPage.php index 345c9793759..1e5a93c65dc 100644 --- a/packages/framework/src/Pages/VirtualPage.php +++ b/packages/framework/src/Pages/VirtualPage.php @@ -4,7 +4,6 @@ namespace Hyde\Pages; -use Closure; use Hyde\Framework\Actions\AnonymousViewCompiler; use Hyde\Markdown\Models\FrontMatter; use Hyde\Pages\Concerns\HydePage; @@ -31,8 +30,6 @@ class VirtualPage extends HydePage implements DynamicPage protected string $contents; protected string $view; - protected Closure $compiler; - public static function make(string $identifier = '', FrontMatter|array $matter = [], string $contents = '', string $view = ''): static { return new static($identifier, $matter, $contents, $view); @@ -53,19 +50,13 @@ public static function make(string $identifier = '', FrontMatter|array $matter = * this will be passed to the view. * @param string $contents The contents of the page. This will be saved as-is to the output file. * @param string $view The view key for the view to use to render the page contents. - * @param Closure|null $compiler Additionally, you can instead pass a closure to control the compiling completely. - * The closure accepts the page instance, and must return a string (which will be saved as the page's contents). */ - public function __construct(string $identifier, FrontMatter|array $matter = [], string $contents = '', string $view = '', Closure $compiler = null) + public function __construct(string $identifier, FrontMatter|array $matter = [], string $contents = '', string $view = '') { parent::__construct($identifier, $matter); $this->contents = $contents; $this->view = $view; - - if ($compiler) { - $this->compiler = $compiler; - } } public function getContents(): string @@ -80,10 +71,6 @@ public function getBladeView(): string public function compile(): string { - if (isset($this->compiler)) { - return ($this->compiler)($this); - } - if (! $this->contents && $this->view) { if (str_ends_with($this->view, '.blade.php')) { return AnonymousViewCompiler::call($this->view, $this->matter->toArray());