diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index e7b951e6497..e559b36c14d 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -7,6 +7,7 @@ This update makes breaking changes to the configuration. You will need to update ### Added - Added a new configuration file, `config/site.php`, see below - Added RSS feed configuration stubs to `config/site.php` +- Added an `Includes` facade that can quickly import partials. ### Changed - internal: Refactor navigation menu components and improve link helpers diff --git a/packages/framework/src/Contracts/IncludeFacadeContract.php b/packages/framework/src/Contracts/IncludeFacadeContract.php new file mode 100644 index 00000000000..f069d5721d4 --- /dev/null +++ b/packages/framework/src/Contracts/IncludeFacadeContract.php @@ -0,0 +1,41 @@ +assertEquals( + Hyde::path('resources/_includes'), + Includes::path() + ); + } + + public function test_path_returns_a_partial_within_the_includes_directory() + { + $this->assertEquals( + Hyde::path('resources/_includes/partial.html'), + Includes::path('partial.html') + ); + } + + public function test_path_creates_directory_if_it_does_not_exist() + { + $path = Includes::path(); + File::deleteDirectory($path); + $this->assertFalse(File::exists($path)); + $this->assertTrue(File::exists(Includes::path())); + } + + public function test_get_returns_partial() + { + $expected = 'foo bar'; + file_put_contents(Hyde::path('resources/_includes/foo.txt'), $expected); + $this->assertEquals($expected, Includes::get('foo.txt')); + unlink(Hyde::path('resources/_includes/foo.txt')); + } + + public function test_get_returns_default_value_when_not_found() + { + $this->assertNull(Includes::get('foo.txt')); + $this->assertEquals('default', Includes::get('foo.txt', 'default')); + } + + public function test_markdown_returns_rendered_partial() + { + $expected = "

foo bar

\n"; + file_put_contents(Hyde::path('resources/_includes/foo.md'), '# foo bar'); + $this->assertEquals($expected, Includes::markdown('foo.md')); + unlink(Hyde::path('resources/_includes/foo.md')); + } + + public function test_markdown_returns_default_value_when_not_found() + { + $this->assertNull(Includes::markdown('foo.md')); + $this->assertEquals('default', Includes::markdown('foo.md', 'default')); + } + + public function test_blade_returns_rendered_partial() + { + $expected = 'foo bar'; + file_put_contents(Hyde::path('resources/_includes/foo.blade.php'), '{{ "foo bar" }}'); + $this->assertEquals($expected, Includes::blade('foo.blade.php')); + unlink(Hyde::path('resources/_includes/foo.blade.php')); + } + + public function test_blade_returns_default_value_when_not_found() + { + $this->assertNull(Includes::blade('foo.blade.php')); + $this->assertEquals('default', Includes::blade('foo.blade.php', 'default')); + } +}