Skip to content

Commit

Permalink
Merge pull request #3 from hydephp/update-tests
Browse files Browse the repository at this point in the history
Add more tests
  • Loading branch information
caendesilva authored Feb 5, 2024
2 parents 6996f51 + a99e34c commit 6325c69
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/BladedownCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ protected function getBaseViewData(): array

protected function getViewData(): array
{
// Todo: If this is a custom view set in the front matter, we may want to alias the $content to $slot for compatibility.
return array_merge($this->getBaseViewData(), [
'title' => $this->page->title,
'content' => new HtmlString($this->html),
Expand Down
11 changes: 10 additions & 1 deletion tests/bin/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function testFileContainsExpectedStrings(string $file, array $strings): void
}
}

testFileContainsExpectedStrings(('hyde/_site/index.html'), [
testFileContainsExpectedStrings('hyde/_site/index.html', [
'Bladedown Test Page',
'Hello, World!',

Expand All @@ -35,3 +35,12 @@ function testFileContainsExpectedStrings(string $file, array $strings): void
'<blockquote class="my-0" style="border-color: cornflowerblue">',
'Include with custom <abbr title="HyperText Markup Language">HTML</abbr> slot content',
]);

testFileContainsExpectedStrings('hyde/_site/custom-layout.html', [
'<title>Custom Layout</title>',
'border: 4px solid cornflowerblue;',
'Hello, World!',
'This is the custom layout.',
]);

echo "All tests passed!\n";
12 changes: 12 additions & 0 deletions tests/fixtures/custom-layout.blade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Custom Layout
extends: layouts.my-custom-layout # Todo we could try to prepend the layouts directory if that's standard and the file is not find in the view root
background: cornflowerblue
name: World
---

# Hello, {{ $name }}!

This uses the custom layout `layouts.my-custom-layout` and sets the background to `cornflowerblue`.

[Back to index](/)
24 changes: 24 additions & 0 deletions tests/runner/resources/views/layouts/my-custom-layout.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Custom Layout</title>
<script>
if (localStorage.getItem('color-theme') === 'dark' || !('color-theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.style.background = '#111827';
document.documentElement.style.color = 'white';
}
</script>
</head>
<body>
<article style="border: 4px solid {{ $background }}; padding: 0 1rem; margin: 2rem auto; max-width: 800px;">
{{ $content }}
</article>

<footer style="text-align: center; margin-top: 2rem;">
This is the custom layout.
</footer>
</body>
</html>

0 comments on commit 6325c69

Please sign in to comment.