Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the publication page compiler #757

Merged
merged 24 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cb20565
Convert test method names to snake_case
caendesilva Dec 15, 2022
bafd0c4
Introduce local variable
caendesilva Dec 15, 2022
194023a
Check if the file exists before attempting to compile
caendesilva Dec 15, 2022
19a3a65
Convert string interpolation to 'sprintf()' calls
caendesilva Dec 15, 2022
ad22000
Display the relative path in the exception message
caendesilva Dec 15, 2022
842127b
Add tests for missing views
caendesilva Dec 15, 2022
7670946
Extract method for repeated code
caendesilva Dec 15, 2022
bd2d6f9
Inline local variables
caendesilva Dec 15, 2022
cd94ce0
Apply fixes from StyleCI
StyleCIBot Dec 15, 2022
1af30f6
Create AnonymousViewCompiler.php
caendesilva Dec 15, 2022
4f6f9d5
Create AnonymousViewCompilerTest.php
caendesilva Dec 15, 2022
3eba351
Extends InvokableAction
caendesilva Dec 15, 2022
79cf0c6
Add class documentation
caendesilva Dec 15, 2022
d524d77
Add class properties and constructor
caendesilva Dec 15, 2022
e423afa
Implement the __invoke method
caendesilva Dec 15, 2022
4d6abaf
Implement the test
caendesilva Dec 15, 2022
2d2bcdc
Throw FileNotFoundException on fail instead
caendesilva Dec 15, 2022
36a697c
Merge branch 'Create-class-AnonymousViewCompiler' into refactor-publi…
caendesilva Dec 15, 2022
cb89aeb
Merge branch 'publications-feature' of github.com:hydephp/develop int…
caendesilva Dec 15, 2022
f41b16c
Merge branch 'publications-feature' into refactor-publication-page-co…
caendesilva Dec 15, 2022
87584ca
Refactor to use the AnonymousViewCompiler
caendesilva Dec 15, 2022
2dc269f
Inline simplified method
caendesilva Dec 15, 2022
b1118cf
Convert concatenation to a scalar value
caendesilva Dec 15, 2022
423e09e
Apply fixes from StyleCI
StyleCIBot Dec 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@

namespace Hyde\Framework\Actions;

use function file_exists;
use function file_get_contents;
use Hyde\Framework\Concerns\InvokableAction;
use Hyde\Framework\Features\Publications\Models\PublicationListPage;
use Hyde\Framework\Features\Publications\PublicationService;
use Hyde\Hyde;
use Hyde\Pages\PublicationPage;
use Illuminate\Support\Facades\Blade;
use InvalidArgumentException;
use function view;

/**
Expand Down Expand Up @@ -46,9 +42,7 @@ public function compilePublicationPage(): string
}

// Using the Blade facade we can render any file without having to register the directory with the view finder.
return Blade::render(
file_get_contents(Hyde::path("{$this->page->type->getDirectory()}/$template.blade.php")), $data
);
return AnonymousViewCompiler::call("{$this->page->type->getDirectory()}/$template.blade.php", $data);
}

public function compilePublicationListPage(): string
Expand All @@ -63,13 +57,6 @@ public function compilePublicationListPage(): string
}

// Using the Blade facade we can render any file without having to register the directory with the view finder.
$viewPath = Hyde::path("{$this->page->type->getDirectory()}/$template").'.blade.php';
if (! file_exists($viewPath)) {
throw new InvalidArgumentException("View [$viewPath] not found.");
}

return Blade::render(
file_get_contents($viewPath), $data
);
return AnonymousViewCompiler::call("{$this->page->type->getDirectory()}/$template.blade.php", $data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Hyde\Framework\Testing\Feature\Actions;

use Hyde\Framework\Actions\PublicationPageCompiler;
use Hyde\Framework\Exceptions\FileNotFoundException;
use Hyde\Framework\Features\Publications\Models\PublicationType;
use Hyde\Hyde;
use Hyde\Pages\PublicationPage;
Expand All @@ -15,7 +16,7 @@
*/
class PublicationPageCompilerTest extends TestCase
{
public function testCanCompilePublicationPages()
public function test_can_compile_publication_pages()
{
$this->directory('test-publication');
$this->setupTestPublication();
Expand All @@ -27,7 +28,7 @@ public function testCanCompilePublicationPages()
$this->assertEquals('Detail: My Publication', $string);
}

public function testCanCompilePublicationListPages()
public function test_can_compile_publication_list_pages()
{
$this->directory('test-publication');
$this->setupTestPublication();
Expand All @@ -39,4 +40,26 @@ public function testCanCompilePublicationListPages()

$this->assertEquals('List: My Publication', $string);
}

public function test_with_missing_detail_blade_view()
{
$this->directory('test-publication');
$this->setupTestPublication();

$this->expectException(FileNotFoundException::class);
$this->expectExceptionMessage('File test-publication/test-publication_detail.blade.php not found.');

PublicationPageCompiler::call(new PublicationPage('my-publication', type: PublicationType::get('test-publication')));
}

public function test_with_missing_list_blade_view()
{
$this->directory('test-publication');
$this->setupTestPublication();

$this->expectException(FileNotFoundException::class);
$this->expectExceptionMessage('File test-publication/test-publication_list.blade.php not found.');

PublicationPageCompiler::call(PublicationType::get('test-publication')->getListPage());
}
}