Skip to content

Commit

Permalink
Merge pull request #1554 from hydephp/improved-head-and-scripts-includes
Browse files Browse the repository at this point in the history
Support using HTML includes to set head and script HTML
  • Loading branch information
caendesilva committed Feb 12, 2024
2 parents a5b9df8 + f1447c1 commit 7676ac9
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ This serves two purposes:
### Added
- Added the existing `media_extensions` option to the `hyde` configuration file in https://github.com/hydephp/develop/pull/1531
- Added configuration options to add custom HTML to the `<head>` and `<script>` sections in https://github.com/hydephp/develop/pull/1542
- Added support for adding custom HTML to the `<head>` and `<script>` sections using HTML includes in https://github.com/hydephp/develop/pull/1554
- Added an `html` helper to the `Includes` facade in https://github.com/hydephp/develop/pull/1552

### Changed
Expand Down
2 changes: 2 additions & 0 deletions docs/digging-deeper/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ Includes::markdown('example.md', 'Default content');
HydePHP also supports some drop-in includes that you can use as an alternative to some config options. These currently are as follows:

- `footer` If a `footer.md` file exists in the includes directory, Hyde will use that as the footer text, instead of the one set in the `hyde.footer` config option.
- 'head' If a `head.html` file exists in the includes directory, Hyde include that within the `<head>` tag of the generated HTML, in addition to the one set in the `hyde.head` config option.
- 'scripts' If a `scripts.html` file exists in the includes directory, Hyde include that at the end of the `<body>` tag of the generated HTML, in addition to the one set in the `hyde.scripts` config option.


## Reading time helper
Expand Down
3 changes: 2 additions & 1 deletion packages/framework/resources/views/layouts/head.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
@endif

{{-- If the user has defined any custom head tags, render them here --}}
{!! config('hyde.head') !!}
{!! config('hyde.head') !!}
{!! Includes::html('head') !!}
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ function toggleTheme() {

{{-- If the user has defined any custom scripts, render them here --}}
{!! config('hyde.scripts') !!}
{!! Includes::html('scripts') !!}
7 changes: 7 additions & 0 deletions packages/framework/tests/Unit/Views/HeadComponentViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ public function testCanAddHeadHtmlFromConfigHook()
$this->assertStringContainsString('<meta name="custom-hook" content="foo">', $this->renderTestView());
}

public function testCanAddHeadHtmlFromHtmlInclude()
{
$this->file('resources/includes/head.html', '<meta name="custom-include" content="foo">');

$this->assertStringContainsString('<meta name="custom-include" content="foo">', $this->renderTestView());
}

protected function escapeIncludes(string $contents): string
{
return str_replace('@include', '@@include', $contents);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,20 @@ public function test_component_uses_relative_path_to_app_js_file_for_nested_page
Filesystem::unlink('_media/app.js');
}

public function testCanAddHeadHtmlFromConfigHook()
public function testCanAddScriptsHtmlFromConfigHook()
{
config(['hyde.scripts' => '<script src="custom-hook.js"></script>']);

$this->assertStringContainsString('<script src="custom-hook.js"></script>', $this->renderTestView());
}

public function testCanAddScriptsHtmlFromHtmlInclude()
{
$this->file('resources/includes/scripts.html', '<script src="html-include.js"></script>');

$this->assertStringContainsString('<script src="html-include.js"></script>', $this->renderTestView());
}

public function test_scripts_can_be_pushed_to_the_component_scripts_stack()
{
view()->share('routeKey', '');
Expand Down

0 comments on commit 7676ac9

Please sign in to comment.