Skip to content

Commit e95acfd

Browse files
authored
Merge pull request #807 from hydephp/refactor-generated-publication-views
Refactor generated publication views
2 parents c5c2aef + eda9c02 commit e95acfd

File tree

4 files changed

+47
-63
lines changed

4 files changed

+47
-63
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
1-
{{-- The Publication Page Layout --}}
21
@extends('hyde::layouts.app')
32
@section('content')
4-
53
<main id="content" class="mx-auto max-w-7xl py-16 px-8">
6-
{{ $publication->title }}
7-
</main>
4+
<article class="prose dark:prose-invert">
5+
@php/** @var \Hyde\Pages\PublicationPage $publication*/@endphp
6+
<h1>{{ $publication->title }}</h1>
7+
<p>
8+
{{ $publication->markdown }}
9+
</p>
10+
</article>
811

9-
@endsection
12+
<div class="prose dark:prose-invert my-8">
13+
<hr>
14+
</div>
15+
16+
<article class="prose dark:prose-invert">
17+
<h3>Front Matter Data</h3>
18+
<div class="ml-4">
19+
@foreach($publication->matter->data as $key => $value)
20+
<dt class="font-bold">{{ $key }}</dt>
21+
<dd class="ml-4">
22+
{{ is_array($value) ? '(array) '. implode(', ', $value) : $value }}
23+
</dd>
24+
@endforeach
25+
</div>
26+
</article>
27+
</main>
28+
@endsection
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
The default publication list template
1+
@extends('hyde::layouts.app')
2+
@section('content')
3+
<main id="content" class="mx-auto max-w-7xl py-16 px-8">
4+
<div class="prose dark:prose-invert">
5+
<h1>Publications for type {{ $page->type->name }}</h1>
6+
<ol>
7+
@php/** @var \Hyde\Pages\PublicationPage $publication*/@endphp
8+
@foreach($publications as $publication)
9+
<li>
10+
<x-link :href="$publication->getRoute()">{{ $publication->title }}</x-link>
11+
</li>
12+
@endforeach
13+
</ol>
14+
</div>
15+
</main>
16+
@endsection

packages/framework/src/Framework/Actions/CreatesNewPublicationType.php

+4-55
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Hyde\Framework\Actions;
66

7-
use function file_put_contents;
87
use Hyde\Framework\Actions\Concerns\CreateAction;
98
use Hyde\Framework\Actions\Contracts\CreateActionContract;
109
use Hyde\Framework\Features\Publications\Models\PublicationType;
@@ -56,66 +55,16 @@ protected function handleCreate(): void
5655

5756
protected function createDetailTemplate(): void
5857
{
59-
$contents = <<<'BLADE'
60-
@extends('hyde::layouts.app')
61-
@section('content')
62-
<main id="content" class="mx-auto max-w-7xl py-16 px-8">
63-
<article class="prose dark:prose-invert">
64-
@php/** @var \Hyde\Pages\PublicationPage $publication*/@endphp
65-
<h1>{{ $publication->title }}</h1>
66-
<p>
67-
{{ $publication->markdown }}
68-
</p>
69-
</article>
70-
71-
<div class="prose dark:prose-invert my-8">
72-
<hr>
73-
</div>
74-
75-
<article class="prose dark:prose-invert">
76-
<h3>Front Matter Data</h3>
77-
<div class="ml-4">
78-
@foreach($publication->matter->data as $key => $value)
79-
<dt class="font-bold">{{ $key }}</dt>
80-
<dd class="ml-4">
81-
{{ is_array($value) ? '(array) '. implode(', ', $value) : $value }}
82-
</dd>
83-
@endforeach
84-
</div>
85-
</article>
86-
</main>
87-
@endsection
88-
BLADE;
89-
90-
$this->savePublicationFile('detail.blade.php', $contents);
58+
$this->savePublicationFile('detail.blade.php', 'resources/views/layouts/publication.blade.php');
9159
}
9260

9361
protected function createListTemplate(): void
9462
{
95-
$contents = <<<'BLADE'
96-
@extends('hyde::layouts.app')
97-
@section('content')
98-
<main id="content" class="mx-auto max-w-7xl py-16 px-8">
99-
<div class="prose dark:prose-invert">
100-
<h1>Publications for type {{ $page->type->name }}</h1>
101-
<ol>
102-
@php/** @var \Hyde\Pages\PublicationPage $publication*/@endphp
103-
@foreach($publications as $publication)
104-
<li>
105-
<x-link :href="$publication->getRoute()">{{ $publication->title }}</x-link>
106-
</li>
107-
@endforeach
108-
</ol>
109-
</div>
110-
</main>
111-
@endsection
112-
BLADE;
113-
114-
$this->savePublicationFile('list.blade.php', $contents);
63+
$this->savePublicationFile('list.blade.php', 'resources/views/layouts/publication_list.blade.php');
11564
}
11665

117-
protected function savePublicationFile(string $filename, string $contents): int
66+
protected function savePublicationFile(string $filename, string $viewPath): void
11867
{
119-
return file_put_contents(Hyde::path("$this->directoryName/$filename"), "$contents\n");
68+
copy(Hyde::vendorPath($viewPath), Hyde::path("$this->directoryName/$filename"));
12069
}
12170
}

packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,16 @@ public function test_can_compile_publication_list_pages_with_registered_namespac
9696
{
9797
$this->directory('test-publication');
9898
$this->setupTestPublication();
99+
$this->file('vendor/hyde/framework/resources/views/layouts/test.blade.php', 'Registered list view');
99100

100101
$schema = json_decode(file_get_contents(Hyde::path('test-publication/schema.json')));
101-
$schema->listTemplate = 'hyde::layouts.publication_list';
102+
$schema->listTemplate = 'hyde::layouts.test';
102103
file_put_contents(Hyde::path('test-publication/schema.json'), json_encode($schema));
103104
file_put_contents(Hyde::path('test-publication/my-publication.md'), 'Foo');
104105

105106
$publicationType = PublicationType::get('test-publication');
106107
$publicationPage = $publicationType->getListPage();
107-
$this->assertEquals("The default publication list template\n", PublicationPageCompiler::call($publicationPage));
108+
$this->assertEquals('Registered list view', PublicationPageCompiler::call($publicationPage));
108109
}
109110

110111
public function test_with_missing_detail_blade_view()

0 commit comments

Comments
 (0)