]> BookStack Code Mirror - bookstack/commitdiff
Added base template convenience partials for theme system users
authorDan Brown <redacted>
Wed, 22 Jun 2022 11:47:31 +0000 (12:47 +0100)
committerDan Brown <redacted>
Wed, 22 Jun 2022 11:47:31 +0000 (12:47 +0100)
Included test to cover usage and paths.
Closes #894

resources/views/layouts/base.blade.php
resources/views/layouts/parts/base-body-end.blade.php [new file with mode: 0644]
resources/views/layouts/parts/base-body-start.blade.php [new file with mode: 0644]
tests/ThemeTest.php

index 1f28e354ce8e119f03a0281fde89563eaee371d5..c465c5f7ef59d2ade5dbcf852e7f8f14269dac86 100644 (file)
@@ -33,6 +33,7 @@
 </head>
 <body class="@yield('body-class')">
 
+    @include('layouts.parts.base-body-start')
     @include('common.skip-to-content')
     @include('common.notifications')
     @include('common.header')
@@ -53,5 +54,6 @@
     <script src="{{ versioned_asset('dist/app.js') }}" nonce="{{ $cspNonce }}"></script>
     @yield('scripts')
 
+    @include('layouts.parts.base-body-end')
 </body>
 </html>
diff --git a/resources/views/layouts/parts/base-body-end.blade.php b/resources/views/layouts/parts/base-body-end.blade.php
new file mode 100644 (file)
index 0000000..4711989
--- /dev/null
@@ -0,0 +1,2 @@
+{{-- This is a placeholder template file provided as a --}}
+{{-- convenience to users of the visual theme system. --}}
\ No newline at end of file
diff --git a/resources/views/layouts/parts/base-body-start.blade.php b/resources/views/layouts/parts/base-body-start.blade.php
new file mode 100644 (file)
index 0000000..4711989
--- /dev/null
@@ -0,0 +1,2 @@
+{{-- This is a placeholder template file provided as a --}}
+{{-- convenience to users of the visual theme system. --}}
\ No newline at end of file
index cad2369f8bec50825e626052d52947d3b8b33b05..551f8350f33976b6edb61520522a85d2c8d0816a 100644 (file)
@@ -17,6 +17,7 @@ use Illuminate\Http\Response;
 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
@@ -254,6 +255,23 @@ class ThemeTest extends TestCase
         $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
@@ -262,7 +280,10 @@ class ThemeTest extends TestCase
         $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);