Skip to content

Commit

Permalink
Merge pull request #777 from hydephp/publications-feature-refactors
Browse files Browse the repository at this point in the history
Remove directoryName prefix from default generated publication templates
  • Loading branch information
caendesilva authored Dec 27, 2022
2 parents ef9563b + 4cbe3f1 commit de5c0e0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Hyde\Framework\Actions\Contracts\CreateActionContract;
use Hyde\Framework\Features\Publications\Models\PublicationType;
use Hyde\Hyde;
use Illuminate\Support\Collection;
use Illuminate\Contracts\Support\Arrayable;

/**
* Scaffold a new publication type schema.
Expand All @@ -23,8 +23,8 @@ class CreatesNewPublicationType extends CreateAction implements CreateActionCont

public function __construct(
protected string $name,
protected Collection $fields,
protected string $canonicalField,
protected Arrayable $fields,
protected ?string $canonicalField = null,
protected ?string $sortField = null,
protected ?bool $sortAscending = null,
protected ?bool $prevNextLinks = null,
Expand All @@ -36,36 +36,24 @@ public function __construct(

protected function handleCreate(): void
{
$type = new PublicationType(
(new PublicationType(
$this->name,
$this->canonicalField,
$this->detailTemplateName(),
$this->listTemplateName(),
$this->canonicalField ?? '__createdAt',
'detail',
'list',
[
$this->sortField ?? '__createdAt',
$this->sortAscending ?? true,
$this->prevNextLinks ?? true,
$this->pageSize ?? 25,
],
$this->fields->toArray()
);

$type->save($this->outputPath);
))->save($this->outputPath);

$this->createDetailTemplate();
$this->createListTemplate();
}

protected function detailTemplateName(): string
{
return "{$this->directoryName}_detail";
}

protected function listTemplateName(): string
{
return "{$this->directoryName}_list";
}

protected function createDetailTemplate(): void
{
$contents = <<<'BLADE'
Expand Down Expand Up @@ -99,7 +87,7 @@ protected function createDetailTemplate(): void
@endsection
BLADE;

$this->savePublicationFile("{$this->detailTemplateName()}.blade.php", $contents);
$this->savePublicationFile('detail.blade.php', $contents);
}

protected function createListTemplate(): void
Expand All @@ -123,7 +111,7 @@ protected function createListTemplate(): void
@endsection
BLADE;

$this->savePublicationFile("{$this->listTemplateName()}.blade.php", $contents);
$this->savePublicationFile('list.blade.php', $contents);
}

protected function savePublicationFile(string $filename, string $contents): int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function test_it_creates_a_new_publication_type()
{
"name": "Test Publication",
"canonicalField": "canonical",
"detailTemplate": "test-publication_detail",
"listTemplate": "test-publication_list",
"detailTemplate": "detail",
"listTemplate": "list",
"pagination": {
"sortField": "sort",
"sortAscending": false,
Expand All @@ -62,17 +62,16 @@ public function test_create_with_default_parameters()
$creator = new CreatesNewPublicationType(
'Test Publication',
new Collection(),
'canonical',
);
$creator->create();

$this->assertFileExists(Hyde::path('test-publication/schema.json'));
$this->assertSame(<<<'JSON'
{
"name": "Test Publication",
"canonicalField": "canonical",
"detailTemplate": "test-publication_detail",
"listTemplate": "test-publication_list",
"canonicalField": "__createdAt",
"detailTemplate": "detail",
"listTemplate": "list",
"pagination": {
"sortField": "__createdAt",
"sortAscending": true,
Expand All @@ -94,7 +93,7 @@ public function test_it_creates_list_and_detail_pages()
);
$creator->create();

$this->assertFileExists(Hyde::path('test-publication/test-publication_detail.blade.php'));
$this->assertFileExists(Hyde::path('test-publication/test-publication_list.blade.php'));
$this->assertFileExists(Hyde::path('test-publication/detail.blade.php'));
$this->assertFileExists(Hyde::path('test-publication/list.blade.php'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public function test_command_creates_publication_type()
{
"name": "Test Publication",
"canonicalField": "publication-title",
"detailTemplate": "test-publication_detail",
"listTemplate": "test-publication_list",
"detailTemplate": "detail",
"listTemplate": "list",
"pagination": {
"sortField": "__createdAt",
"sortAscending": true,
Expand All @@ -97,7 +97,8 @@ public function test_command_creates_publication_type()
file_get_contents(Hyde::path('test-publication/schema.json'))
);

// TODO: Assert Blade templates were created?
$this->assertFileExists(Hyde::path('test-publication/detail.blade.php'));
$this->assertFileExists(Hyde::path('test-publication/list.blade.php'));
}

public function test_with_default_values()
Expand Down

0 comments on commit de5c0e0

Please sign in to comment.