]> BookStack Code Mirror - bookstack/commitdiff
Header: Simplified, split and re-orgranised view file(s)
authorDan Brown <redacted>
Sun, 24 Sep 2023 09:29:51 +0000 (10:29 +0100)
committerDan Brown <redacted>
Sun, 24 Sep 2023 09:29:51 +0000 (10:29 +0100)
- Moved "common" template partials, that are only used in layouts, to
  layouts/parts folder.
- Simplified HTML structure of header template.
- Extracted logo and links from header template to simplify.
- Added header-links-start template for easier extension/customization
  without needing to override full list of links.
  - Added test to cover usage of this.

For #4564

16 files changed:
resources/sass/_header.scss
resources/views/common/header.blade.php [deleted file]
resources/views/layouts/base.blade.php
resources/views/layouts/parts/custom-head.blade.php [moved from resources/views/common/custom-head.blade.php with 100% similarity]
resources/views/layouts/parts/custom-styles.blade.php [moved from resources/views/common/custom-styles.blade.php with 100% similarity]
resources/views/layouts/parts/footer.blade.php [moved from resources/views/common/footer.blade.php with 100% similarity]
resources/views/layouts/parts/header-links-start.blade.php [new file with mode: 0644]
resources/views/layouts/parts/header-links.blade.php [new file with mode: 0644]
resources/views/layouts/parts/header-logo.blade.php [new file with mode: 0644]
resources/views/layouts/parts/header-search.blade.php [new file with mode: 0644]
resources/views/layouts/parts/header-user-menu.blade.php [moved from resources/views/common/header-user-menu.blade.php with 100% similarity]
resources/views/layouts/parts/header.blade.php [new file with mode: 0644]
resources/views/layouts/parts/notifications.blade.php [moved from resources/views/common/notifications.blade.php with 100% similarity]
resources/views/layouts/parts/skip-to-content.blade.php [moved from resources/views/common/skip-to-content.blade.php with 100% similarity]
resources/views/layouts/plain.blade.php
tests/ThemeTest.php

index c1b6af4c655652b609f0ffaa45505300e5a6f183..4a4c70401b1f7ca2db6d1ed4c7cde3f6d90037b7 100644 (file)
@@ -2,12 +2,12 @@
  * Includes the main navigation header and the faded toolbar.
  */
 
-header .grid {
+header.grid {
   grid-template-columns: minmax(max-content, 2fr) 1fr minmax(max-content, 2fr);
 }
 
 @include smaller-than($l) {
-  header .grid {
+  header.grid {
     grid-template-columns: 1fr;
     grid-row-gap: 0;
   }
diff --git a/resources/views/common/header.blade.php b/resources/views/common/header.blade.php
deleted file mode 100644 (file)
index 86ad356..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-<header id="header" component="header-mobile-toggle" class="primary-background">
-    <div class="grid mx-l">
-
-        <div>
-            <a href="{{ url('/') }}" data-shortcut="home_view" class="logo">
-                @if(setting('app-logo', '') !== 'none')
-                    <img class="logo-image" src="{{ setting('app-logo', '') === '' ? url('/logo.png') : url(setting('app-logo', '')) }}" alt="Logo">
-                @endif
-                @if (setting('app-name-header'))
-                    <span class="logo-text">{{ setting('app-name') }}</span>
-                @endif
-            </a>
-            <button type="button"
-                    refs="header-mobile-toggle@toggle"
-                    title="{{ trans('common.header_menu_expand') }}"
-                    aria-expanded="false"
-                    class="mobile-menu-toggle hide-over-l">@icon('more')</button>
-        </div>
-
-        <div class="flex-container-column items-center justify-center hide-under-l">
-            @if (user()->hasAppAccess())
-            <form component="global-search" action="{{ url('/search') }}" method="GET" class="search-box" role="search" tabindex="0">
-                <button id="header-search-box-button"
-                        refs="global-search@button"
-                        type="submit"
-                        aria-label="{{ trans('common.search') }}"
-                        tabindex="-1">@icon('search')</button>
-                <input id="header-search-box-input"
-                       refs="global-search@input"
-                       type="text"
-                       name="term"
-                       data-shortcut="global_search"
-                       autocomplete="off"
-                       aria-label="{{ trans('common.search') }}" placeholder="{{ trans('common.search') }}"
-                       value="{{ $searchTerm ?? '' }}">
-                <div refs="global-search@suggestions" class="global-search-suggestions card">
-                    <div refs="global-search@loading" class="text-center px-m global-search-loading">@include('common.loading-icon')</div>
-                    <div refs="global-search@suggestion-results" class="px-m"></div>
-                    <button class="text-button card-footer-link" type="submit">{{ trans('common.view_all') }}</button>
-                </div>
-            </form>
-            @endif
-        </div>
-
-        <nav refs="header-mobile-toggle@menu" class="header-links">
-            <div class="links text-center">
-                @if (user()->hasAppAccess())
-                    <a class="hide-over-l" href="{{ url('/search') }}">@icon('search'){{ trans('common.search') }}</a>
-                    @if(userCanOnAny('view', \BookStack\Entities\Models\Bookshelf::class) || userCan('bookshelf-view-all') || userCan('bookshelf-view-own'))
-                        <a href="{{ url('/shelves') }}" data-shortcut="shelves_view">@icon('bookshelf'){{ trans('entities.shelves') }}</a>
-                    @endif
-                    <a href="{{ url('/books') }}" data-shortcut="books_view">@icon('books'){{ trans('entities.books') }}</a>
-                    @if(!user()->isGuest() && userCan('settings-manage'))
-                        <a href="{{ url('/settings') }}" data-shortcut="settings_view">@icon('settings'){{ trans('settings.settings') }}</a>
-                    @endif
-                    @if(!user()->isGuest() && userCan('users-manage') && !userCan('settings-manage'))
-                        <a href="{{ url('/settings/users') }}" data-shortcut="settings_view">@icon('users'){{ trans('settings.users') }}</a>
-                    @endif
-                @endif
-
-                @if(user()->isGuest())
-                    @if(setting('registration-enabled') && config('auth.method') === 'standard')
-                        <a href="{{ url('/register') }}">@icon('new-user'){{ trans('auth.sign_up') }}</a>
-                    @endif
-                    <a href="{{ url('/login')  }}">@icon('login'){{ trans('auth.log_in') }}</a>
-                @endif
-            </div>
-            @if(!user()->isGuest())
-                @include('common.header-user-menu', ['user' => user()])
-            @endif
-        </nav>
-
-    </div>
-</header>
index f303aff267752caaca1419eba7e07ba019d02e61..f9dbc68b455b6d831c796ac213bae0494fa6fb6a 100644 (file)
@@ -32,8 +32,8 @@
     @yield('head')
 
     <!-- Custom Styles & Head Content -->
-    @include('common.custom-styles')
-    @include('common.custom-head')
+    @include('layouts.parts.custom-styles')
+    @include('layouts.parts.custom-head')
 
     @stack('head')
 
       class="@stack('body-class')">
 
     @include('layouts.parts.base-body-start')
-    @include('common.skip-to-content')
-    @include('common.notifications')
-    @include('common.header')
+    @include('layouts.parts.skip-to-content')
+    @include('layouts.parts.notifications')
+    @include('layouts.parts.header')
 
     <div id="content" components="@yield('content-components')" class="block">
         @yield('content')
     </div>
 
-    @include('common.footer')
+    @include('layouts.parts.footer')
 
     <div component="back-to-top" class="back-to-top print-hidden">
         <div class="inner">
diff --git a/resources/views/layouts/parts/header-links-start.blade.php b/resources/views/layouts/parts/header-links-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
diff --git a/resources/views/layouts/parts/header-links.blade.php b/resources/views/layouts/parts/header-links.blade.php
new file mode 100644 (file)
index 0000000..697f406
--- /dev/null
@@ -0,0 +1,25 @@
+@include('layouts.parts.header-links-start')
+
+@if (user()->hasAppAccess())
+    <a class="hide-over-l" href="{{ url('/search') }}">@icon('search'){{ trans('common.search') }}</a>
+    @if(userCanOnAny('view', \BookStack\Entities\Models\Bookshelf::class) || userCan('bookshelf-view-all') || userCan('bookshelf-view-own'))
+        <a href="{{ url('/shelves') }}"
+           data-shortcut="shelves_view">@icon('bookshelf'){{ trans('entities.shelves') }}</a>
+    @endif
+    <a href="{{ url('/books') }}" data-shortcut="books_view">@icon('books'){{ trans('entities.books') }}</a>
+    @if(!user()->isGuest() && userCan('settings-manage'))
+        <a href="{{ url('/settings') }}"
+           data-shortcut="settings_view">@icon('settings'){{ trans('settings.settings') }}</a>
+    @endif
+    @if(!user()->isGuest() && userCan('users-manage') && !userCan('settings-manage'))
+        <a href="{{ url('/settings/users') }}"
+           data-shortcut="settings_view">@icon('users'){{ trans('settings.users') }}</a>
+    @endif
+@endif
+
+@if(user()->isGuest())
+    @if(setting('registration-enabled') && config('auth.method') === 'standard')
+        <a href="{{ url('/register') }}">@icon('new-user'){{ trans('auth.sign_up') }}</a>
+    @endif
+    <a href="{{ url('/login')  }}">@icon('login'){{ trans('auth.log_in') }}</a>
+@endif
\ No newline at end of file
diff --git a/resources/views/layouts/parts/header-logo.blade.php b/resources/views/layouts/parts/header-logo.blade.php
new file mode 100644 (file)
index 0000000..c1bbd78
--- /dev/null
@@ -0,0 +1,8 @@
+<a href="{{ url('/') }}" data-shortcut="home_view" class="logo">
+    @if(setting('app-logo', '') !== 'none')
+        <img class="logo-image" src="{{ setting('app-logo', '') === '' ? url('/logo.png') : url(setting('app-logo', '')) }}" alt="Logo">
+    @endif
+    @if (setting('app-name-header'))
+        <span class="logo-text">{{ setting('app-name') }}</span>
+    @endif
+</a>
\ No newline at end of file
diff --git a/resources/views/layouts/parts/header-search.blade.php b/resources/views/layouts/parts/header-search.blade.php
new file mode 100644 (file)
index 0000000..d542611
--- /dev/null
@@ -0,0 +1,20 @@
+<form component="global-search" action="{{ url('/search') }}" method="GET" class="search-box" role="search" tabindex="0">
+    <button id="header-search-box-button"
+            refs="global-search@button"
+            type="submit"
+            aria-label="{{ trans('common.search') }}"
+            tabindex="-1">@icon('search')</button>
+    <input id="header-search-box-input"
+           refs="global-search@input"
+           type="text"
+           name="term"
+           data-shortcut="global_search"
+           autocomplete="off"
+           aria-label="{{ trans('common.search') }}" placeholder="{{ trans('common.search') }}"
+           value="{{ $searchTerm ?? '' }}">
+    <div refs="global-search@suggestions" class="global-search-suggestions card">
+        <div refs="global-search@loading" class="text-center px-m global-search-loading">@include('common.loading-icon')</div>
+        <div refs="global-search@suggestion-results" class="px-m"></div>
+        <button class="text-button card-footer-link" type="submit">{{ trans('common.view_all') }}</button>
+    </div>
+</form>
\ No newline at end of file
diff --git a/resources/views/layouts/parts/header.blade.php b/resources/views/layouts/parts/header.blade.php
new file mode 100644 (file)
index 0000000..25f8e8c
--- /dev/null
@@ -0,0 +1,25 @@
+<header id="header" component="header-mobile-toggle" class="primary-background px-xl grid">
+    <div>
+        @include('layouts.parts.header-logo')
+        <button type="button"
+                refs="header-mobile-toggle@toggle"
+                title="{{ trans('common.header_menu_expand') }}"
+                aria-expanded="false"
+                class="mobile-menu-toggle hide-over-l">@icon('more')</button>
+    </div>
+
+    <div class="flex-container-column items-center justify-center hide-under-l">
+    @if(user()->hasAppAccess())
+        @include('layouts.parts.header-search')
+    @endif
+    </div>
+
+    <nav refs="header-mobile-toggle@menu" class="header-links">
+        <div class="links text-center">
+            @include('layouts.parts.header-links')
+        </div>
+        @if(!user()->isGuest())
+            @include('layouts.parts.header-user-menu', ['user' => user()])
+        @endif
+    </nav>
+</header>
index a3ee74143b3749d658e3836d313677f148518dee..a644ef78997040499a447c9caa9c86deb60c5b3d 100644 (file)
@@ -14,8 +14,8 @@
     <link rel="stylesheet" media="print" href="{{ versioned_asset('dist/print-styles.css') }}">
 
     <!-- Custom Styles & Head Content -->
-    @include('common.custom-styles')
-    @include('common.custom-head')
+    @include('layouts.parts.custom-styles')
+    @include('layouts.parts.custom-head')
 </head>
 <body>
     @yield('content')
index f0266cd0c1349420fdd4c07724b68d9b77b7ef56..53361e35194dad7b8fdec639373cc1a673bdfdd4 100644 (file)
@@ -366,6 +366,20 @@ class ThemeTest extends TestCase
         });
     }
 
+    public function test_header_links_start_template_file_can_be_used()
+    {
+        $content = 'This is added text in the header bar';
+
+        $this->usingThemeFolder(function (string $folder) use ($content) {
+            $viewDir = theme_path('layouts/parts');
+            mkdir($viewDir, 0777, true);
+            file_put_contents($viewDir . '/header-links-start.blade.php', $content);
+            $this->setSettings(['registration-enabled' => 'true']);
+
+            $this->get('/login')->assertSee($content);
+        });
+    }
+
     protected function usingThemeFolder(callable $callback)
     {
         // Create a folder and configure a theme