Skip to content

Commit

Permalink
Added base template convenience partials for theme system users
Browse files Browse the repository at this point in the history
Included test to cover usage and paths.
Closes #894
  • Loading branch information
ssddanbrown committed Jun 22, 2022
1 parent 0d9b5a9 commit 8d8da31
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions resources/views/layouts/base.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class="{{ setting()->getForCurrentUser('dark-mode-enabled') ? 'dark-mode ' : ''
</head>
<body class="@yield('body-class')">

@include('layouts.parts.base-body-start')
@include('common.skip-to-content')
@include('common.notifications')
@include('common.header')
Expand All @@ -53,5 +54,6 @@ class="{{ setting()->getForCurrentUser('dark-mode-enabled') ? 'dark-mode ' : ''
<script src="{{ versioned_asset('dist/app.js') }}" nonce="{{ $cspNonce }}"></script>
@yield('scripts')

@include('layouts.parts.base-body-end')
</body>
</html>
2 changes: 2 additions & 0 deletions resources/views/layouts/parts/base-body-end.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{-- This is a placeholder template file provided as a --}}
{{-- convenience to users of the visual theme system. --}}
2 changes: 2 additions & 0 deletions resources/views/layouts/parts/base-body-start.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{-- This is a placeholder template file provided as a --}}
{{-- convenience to users of the visual theme system. --}}
23 changes: 22 additions & 1 deletion tests/ThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
use League\CommonMark\ConfigurableEnvironmentInterface;

class ThemeTest extends TestCase
Expand Down Expand Up @@ -254,6 +255,23 @@ public function test_register_command_allows_provided_command_to_be_usable_via_a
$this->assertStringContainsString('Command ran!', $output);
}

public function test_body_start_and_end_template_files_can_be_used()
{
$bodyStartStr = 'barry-fought-against-the-panther';
$bodyEndStr = 'barry-lost-his-fight-with-grace';

$this->usingThemeFolder(function(string $folder) use ($bodyStartStr, $bodyEndStr) {
$viewDir = theme_path('layouts/parts');
mkdir($viewDir, 0777, true);
file_put_contents($viewDir . '/base-body-start.blade.php', $bodyStartStr);
file_put_contents($viewDir . '/base-body-end.blade.php', $bodyEndStr);

$resp = $this->asEditor()->get('/');
$resp->assertSee($bodyStartStr);
$resp->assertSee($bodyEndStr);
});
}

protected function usingThemeFolder(callable $callback)
{
// Create a folder and configure a theme
Expand All @@ -262,7 +280,10 @@ protected function usingThemeFolder(callable $callback)
$themeFolderPath = theme_path('');
File::makeDirectory($themeFolderPath);

call_user_func($callback, $themeFolderName);
// Run provided callback with theme env option set
$this->runWithEnv('APP_THEME', $themeFolderName, function() use ($callback, $themeFolderName) {
call_user_func($callback, $themeFolderName);
});

// Cleanup the custom theme folder we created
File::deleteDirectory($themeFolderPath);
Expand Down

0 comments on commit 8d8da31

Please sign in to comment.