diff --git a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php index 9eed497e5f2..bdabf351f30 100644 --- a/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php +++ b/packages/framework/src/Framework/Actions/CreatesNewPublicationType.php @@ -87,7 +87,7 @@ protected function createDetailTemplate(): void @endsection BLADE; - $this->savePublicationFile("detail.blade.php", $contents); + $this->savePublicationFile('detail.blade.php', $contents); } protected function createListTemplate(): void @@ -111,7 +111,7 @@ protected function createListTemplate(): void @endsection BLADE; - $this->savePublicationFile("list.blade.php", $contents); + $this->savePublicationFile('list.blade.php', $contents); } protected function savePublicationFile(string $filename, string $contents): int diff --git a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php index b8dc27ea463..05c0683adb9 100644 --- a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php +++ b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php @@ -9,6 +9,7 @@ use Hyde\Framework\Features\Publications\PublicationService; use Hyde\Pages\PublicationPage; use Illuminate\Support\Facades\View; +use function str_ends_with; /** * @todo Consider changing to check if template key ends with .blade.php and using that to signify if it's an anonymous view. @@ -47,13 +48,15 @@ protected function compilePublicationListPage(): string protected function compileView(string $template, array $data): string { - return View::exists($template) - ? View::make($template, $data)->render() - : AnonymousViewCompiler::call($this->getTemplateFilePath($template), $data); + return str_ends_with($template, '.blade.php') + ? AnonymousViewCompiler::call($this->getTemplateFilePath($template), $data) + : View::make($template, $data)->render(); } protected function getTemplateFilePath(string $template): string { + $template = basename($template, '.blade.php'); + return "{$this->page->type->getDirectory()}/$template.blade.php"; } } diff --git a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php index 5b8689f1bd4..6b6d5ed288e 100644 --- a/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php +++ b/packages/framework/src/Framework/Features/Publications/Models/PublicationType.php @@ -51,8 +51,8 @@ public static function fromFile(string $schemaFile): static public function __construct( public string $name, public string $canonicalField = 'identifier', - public string $detailTemplate = 'detail', - public string $listTemplate = 'list', + public string $detailTemplate = 'detail.blade.php', + public string $listTemplate = 'list.blade.php', array|PaginationSettings $pagination = [], array $fields = [], ?string $directory = null diff --git a/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php b/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php index 419a0972ce4..0529669fa59 100644 --- a/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php +++ b/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php @@ -26,7 +26,7 @@ public function test_can_compile_publication_pages() $this->directory('test-publication'); $this->setupTestPublication(); - file_put_contents(Hyde::path('test-publication/test-publication_detail.blade.php'), 'Detail: {{ $publication->title }}'); + file_put_contents(Hyde::path('test-publication/detail.blade.php'), 'Detail: {{ $publication->title }}'); $string = PublicationPageCompiler::call(new PublicationPage('my-publication', type: PublicationType::get('test-publication'))); @@ -39,7 +39,7 @@ public function test_can_compile_publication_list_pages() $this->setupTestPublication(); file_put_contents(Hyde::path('test-publication/my-publication.md'), 'Foo'); - file_put_contents(Hyde::path('test-publication/test-publication_list.blade.php'), 'List: {{ $publications->first()->title }}'); + file_put_contents(Hyde::path('test-publication/list.blade.php'), 'List: {{ $publications->first()->title }}'); $string = PublicationPageCompiler::call(PublicationType::get('test-publication')->getListPage()); @@ -113,7 +113,7 @@ public function test_with_missing_detail_blade_view() $this->setupTestPublication(); $this->expectException(FileNotFoundException::class); - $this->expectExceptionMessage('File [test-publication/test-publication_detail.blade.php] not found.'); + $this->expectExceptionMessage('File [test-publication/detail.blade.php] not found.'); PublicationPageCompiler::call(new PublicationPage('my-publication', type: PublicationType::get('test-publication'))); } @@ -124,7 +124,7 @@ public function test_with_missing_list_blade_view() $this->setupTestPublication(); $this->expectException(FileNotFoundException::class); - $this->expectExceptionMessage('File [test-publication/test-publication_list.blade.php] not found.'); + $this->expectExceptionMessage('File [test-publication/list.blade.php] not found.'); PublicationPageCompiler::call(PublicationType::get('test-publication')->getListPage()); } diff --git a/packages/framework/tests/Feature/Commands/MakePublicationCommandTest.php b/packages/framework/tests/Feature/Commands/MakePublicationCommandTest.php index 2fb6357337b..1d8e2783f6b 100644 --- a/packages/framework/tests/Feature/Commands/MakePublicationCommandTest.php +++ b/packages/framework/tests/Feature/Commands/MakePublicationCommandTest.php @@ -360,8 +360,8 @@ protected function makeSchemaFile(array $merge = []): void json_encode(array_merge([ 'name' => 'Test Publication', 'canonicalField' => 'title', - 'detailTemplate' => 'test-publication_detail', - 'listTemplate' => 'test-publication_list', + 'detailTemplate' => 'detail', + 'listTemplate' => 'list', 'pagination' => [ 'pageSize' => 10, 'prevNextLinks' => true, diff --git a/packages/framework/tests/Feature/PublicationListPageTest.php b/packages/framework/tests/Feature/PublicationListPageTest.php index 8b811818ba0..5fa8ba2d886 100644 --- a/packages/framework/tests/Feature/PublicationListPageTest.php +++ b/packages/framework/tests/Feature/PublicationListPageTest.php @@ -68,8 +68,8 @@ protected function getTestData(): array return [ 'name' => 'test', 'canonicalField' => 'canonical', - 'detailTemplate' => 'detail', - 'listTemplate' => 'list', + 'detailTemplate' => 'detail.blade.php', + 'listTemplate' => 'list.blade.php', 'pagination' => [ 'sortField' => 'sort', 'sortAscending' => true, diff --git a/packages/framework/tests/Feature/PublicationPageTest.php b/packages/framework/tests/Feature/PublicationPageTest.php index bff8605712e..ad051c6c5e5 100644 --- a/packages/framework/tests/Feature/PublicationPageTest.php +++ b/packages/framework/tests/Feature/PublicationPageTest.php @@ -116,8 +116,8 @@ protected function createRealPublicationFiles(): void file_put_contents(Hyde::path('test-publication/schema.json'), '{ "name": "test", "canonicalField": "slug", - "detailTemplate": "test_detail", - "listTemplate": "test_list", + "detailTemplate": "test_detail.blade.php", + "listTemplate": "test_list.blade.php", "pagination": { "sortField": "__createdAt", "sortAscending": true, diff --git a/packages/framework/tests/Feature/PublicationTypeTest.php b/packages/framework/tests/Feature/PublicationTypeTest.php index f199cad2609..6129fe63f05 100644 --- a/packages/framework/tests/Feature/PublicationTypeTest.php +++ b/packages/framework/tests/Feature/PublicationTypeTest.php @@ -39,8 +39,8 @@ public function test_construct_with_default_values() $this->assertEquals('Test Publication', $publicationType->name); $this->assertEquals('identifier', $publicationType->canonicalField); - $this->assertEquals('detail', $publicationType->detailTemplate); - $this->assertEquals('list', $publicationType->listTemplate); + $this->assertEquals('detail.blade.php', $publicationType->detailTemplate); + $this->assertEquals('list.blade.php', $publicationType->listTemplate); $this->assertEquals([], $publicationType->fields); $this->assertEquals(PaginationSettings::fromArray([ 'sortField' => '__createdAt', @@ -211,8 +211,8 @@ protected function getTestData(array $mergeData = []): array return array_merge([ 'name' => 'Test Publication', 'canonicalField' => 'title', - 'detailTemplate' => 'test-publication_detail', - 'listTemplate' => 'test-publication_list', + 'detailTemplate' => 'detail.blade.php', + 'listTemplate' => 'list.blade.php', 'pagination' => [ 'sortField' => '__createdAt', 'sortAscending' => true, diff --git a/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php b/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php index 57969957b97..3c70f0f3ef9 100644 --- a/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php +++ b/packages/framework/tests/Unit/Pages/PublicationPageUnitTest.php @@ -211,7 +211,7 @@ public function testConstructFactoryData() public function testCompile() { $this->directory('directory'); - Hyde::touch('directory/detailTemplate.blade.php'); + Hyde::touch('directory/detail.blade.php'); $page = new PublicationPage('foo', [], '', $this->pubType()); Hyde::shareViewData($page); @@ -242,8 +242,8 @@ protected function pubType(): PublicationType return new PublicationType( 'name', 'canonicalField', - 'detailTemplate', - 'listTemplate', + 'detail.blade.php', + 'list.blade.php', ['sortField', true, true, 1], [], 'directory' diff --git a/tests/fixtures/test-publication-schema.json b/tests/fixtures/test-publication-schema.json index 08d24f68970..0528d26e352 100644 --- a/tests/fixtures/test-publication-schema.json +++ b/tests/fixtures/test-publication-schema.json @@ -1,8 +1,8 @@ { "name": "Test Publication", "canonicalField": "title", - "detailTemplate": "test-publication_detail", - "listTemplate": "test-publication_list", + "detailTemplate": "detail.blade.php", + "listTemplate": "list.blade.php", "pagination": { "sortField": "__createdAt", "sortAscending": true,