]> BookStack Code Mirror - bookstack/commitdiff
Reorganised and split out export templates & styles
authorDan Brown <redacted>
Wed, 8 Jun 2022 16:56:59 +0000 (17:56 +0100)
committerDan Brown <redacted>
Wed, 8 Jun 2022 16:56:59 +0000 (17:56 +0100)
Moved export templates elements into their own folder for better
grouping of logical usage.
Within the base export template, added some body classes to allow easier
targeted customisation via custom head css.
Split content of export templates into smaller partials for easier
future customization.

Closes #3443

17 files changed:
app/Entities/Tools/ExportFormatter.php
resources/sass/export-styles.scss
resources/views/books/export.blade.php [deleted file]
resources/views/chapters/export.blade.php [deleted file]
resources/views/common/export-styles.blade.php [deleted file]
resources/views/exports/book.blade.php [new file with mode: 0644]
resources/views/exports/chapter.blade.php [new file with mode: 0644]
resources/views/exports/page.blade.php [moved from resources/views/pages/export.blade.php with 71% similarity]
resources/views/exports/parts/book-contents-menu.blade.php [new file with mode: 0644]
resources/views/exports/parts/chapter-contents-menu.blade.php [new file with mode: 0644]
resources/views/exports/parts/chapter-item.blade.php [new file with mode: 0644]
resources/views/exports/parts/custom-head.blade.php [moved from resources/views/common/export-custom-head.blade.php with 100% similarity]
resources/views/exports/parts/meta.blade.php [moved from resources/views/entities/export-meta.blade.php with 100% similarity]
resources/views/exports/parts/page-item.blade.php [new file with mode: 0644]
resources/views/exports/parts/styles.blade.php [new file with mode: 0644]
resources/views/layouts/export.blade.php
tests/Entity/ExportTest.php

index 99aa4536f52bef1ec985c2b46aace5ed5c0f2669..97902db8219c12d5183a97b0e5a3565d4c158378 100644 (file)
@@ -39,7 +39,7 @@ class ExportFormatter
     public function pageToContainedHtml(Page $page)
     {
         $page->html = (new PageContent($page))->render();
-        $pageHtml = view('pages.export', [
+        $pageHtml = view('exports.page', [
             'page'       => $page,
             'format'     => 'html',
             'cspContent' => $this->cspService->getCspMetaTagValue(),
@@ -59,7 +59,7 @@ class ExportFormatter
         $pages->each(function ($page) {
             $page->html = (new PageContent($page))->render();
         });
-        $html = view('chapters.export', [
+        $html = view('exports.chapter', [
             'chapter'    => $chapter,
             'pages'      => $pages,
             'format'     => 'html',
@@ -77,7 +77,7 @@ class ExportFormatter
     public function bookToContainedHtml(Book $book)
     {
         $bookTree = (new BookContents($book))->getTree(false, true);
-        $html = view('books.export', [
+        $html = view('exports.book', [
             'book'         => $book,
             'bookChildren' => $bookTree,
             'format'       => 'html',
@@ -95,7 +95,7 @@ class ExportFormatter
     public function pageToPdf(Page $page)
     {
         $page->html = (new PageContent($page))->render();
-        $html = view('pages.export', [
+        $html = view('exports.page', [
             'page'   => $page,
             'format' => 'pdf',
             'engine' => $this->pdfGenerator->getActiveEngine(),
@@ -116,7 +116,7 @@ class ExportFormatter
             $page->html = (new PageContent($page))->render();
         });
 
-        $html = view('chapters.export', [
+        $html = view('exports.chapter', [
             'chapter' => $chapter,
             'pages'   => $pages,
             'format'  => 'pdf',
@@ -134,7 +134,7 @@ class ExportFormatter
     public function bookToPdf(Book $book)
     {
         $bookTree = (new BookContents($book))->getTree(false, true);
-        $html = view('books.export', [
+        $html = view('exports.book', [
             'book'         => $book,
             'bookChildren' => $bookTree,
             'format'       => 'pdf',
index 1a8b34c5b9af119865929d1eebde78c8180d2a99..b8160b4c2df575e594b347b0e811dbf8a425fe4b 100644 (file)
@@ -59,4 +59,47 @@ ul.contents ul li {
 }
 .chapter-hint + h1 {
   margin-top: 0;
+}
+
+// PDF specific overrides
+body.export-format-pdf {
+  font-size: 14px;
+  line-height: 1.2;
+
+  h1, h2, h3, h4, h5, h6 {
+    line-height: 1.2;
+  }
+
+  table {
+    max-width: 800px !important;
+    font-size: 0.8em;
+    width: 100% !important;
+  }
+
+  table td {
+    width: auto !important;
+  }
+
+  .page-content .float {
+    float: none !important;
+  }
+
+  .page-content img.align-left, .page-content img.align-right  {
+    float: none !important;
+    clear: both;
+    display: block;
+  }
+
+}
+
+// DOMPDF pdf export specific overrides
+body.export-format-pdf.export-engine-dompdf {
+  // Fix for full width linked image sizes on DOMPDF
+  .page-content a > img {
+    max-width: 700px;
+  }
+  // Undoes the above for table images to prevent visually worse scenario, Awaiting next DOMPDF release for patch
+  .page-content td a > img {
+    max-width: 100%;
+  }
 }
\ No newline at end of file
diff --git a/resources/views/books/export.blade.php b/resources/views/books/export.blade.php
deleted file mode 100644 (file)
index 0b6b4a5..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-@extends('layouts.export')
-
-@section('title', $book->name)
-
-@section('content')
-    <h1 style="font-size: 4.8em">{{$book->name}}</h1>
-
-    <p>{{ $book->description }}</p>
-
-    @if(count($bookChildren) > 0)
-        <ul class="contents">
-            @foreach($bookChildren as $bookChild)
-                <li><a href="#{{$bookChild->getType()}}-{{$bookChild->id}}">{{ $bookChild->name }}</a></li>
-                @if($bookChild->isA('chapter') && count($bookChild->visible_pages) > 0)
-                    <ul>
-                        @foreach($bookChild->visible_pages as $page)
-                            <li><a href="#page-{{$page->id}}">{{ $page->name }}</a></li>
-                        @endforeach
-                    </ul>
-                @endif
-            @endforeach
-        </ul>
-    @endif
-
-    @foreach($bookChildren as $bookChild)
-        <div class="page-break"></div>
-        <h1 id="{{$bookChild->getType()}}-{{$bookChild->id}}">{{ $bookChild->name }}</h1>
-
-        @if($bookChild->isA('chapter'))
-            <p>{{ $bookChild->description }}</p>
-
-            @if(count($bookChild->visible_pages) > 0)
-                @foreach($bookChild->visible_pages as $page)
-                    <div class="page-break"></div>
-                    <div class="chapter-hint">{{$bookChild->name}}</div>
-                    <h1 id="page-{{$page->id}}">{{ $page->name }}</h1>
-                    {!! $page->html !!}
-                @endforeach
-            @endif
-
-        @else
-            {!! $bookChild->html !!}
-        @endif
-
-    @endforeach
-@endsection
\ No newline at end of file
diff --git a/resources/views/chapters/export.blade.php b/resources/views/chapters/export.blade.php
deleted file mode 100644 (file)
index 61286ab..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-@extends('layouts.export')
-
-@section('title', $chapter->name)
-
-@section('content')
-    <h1 style="font-size: 4.8em">{{$chapter->name}}</h1>
-
-    <p>{{ $chapter->description }}</p>
-
-    @if(count($pages) > 0)
-        <ul class="contents">
-            @foreach($pages as $page)
-                <li><a href="#page-{{$page->id}}">{{ $page->name }}</a></li>
-            @endforeach
-        </ul>
-    @endif
-
-    @foreach($pages as $page)
-        <div class="page-break"></div>
-        <h1 id="page-{{$page->id}}">{{ $page->name }}</h1>
-        {!! $page->html !!}
-    @endforeach
-@endsection
\ No newline at end of file
diff --git a/resources/views/common/export-styles.blade.php b/resources/views/common/export-styles.blade.php
deleted file mode 100644 (file)
index 1dfa6bb..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-<style>
-    @if (!app()->runningUnitTests())
-        {!! file_get_contents(public_path('/dist/export-styles.css')) !!}
-    @endif
-</style>
-
-@if ($format === 'pdf')
-    <style>
-
-        /* PDF size adjustments */
-        body {
-            font-size: 14px;
-            line-height: 1.2;
-        }
-
-        h1, h2, h3, h4, h5, h6 {
-            line-height: 1.2;
-        }
-
-        table {
-            max-width: 800px !important;
-            font-size: 0.8em;
-            width: 100% !important;
-        }
-
-        table td {
-            width: auto !important;
-        }
-
-        /* Patches for CSS variable colors */
-        a {
-            color: {{ setting('app-color') }};
-        }
-
-        blockquote {
-            border-left-color: {{ setting('app-color') }};
-        }
-
-        /* Patches for content layout */
-        .page-content .float {
-            float: none !important;
-        }
-
-        .page-content img.align-left, .page-content img.align-right  {
-            float: none !important;
-            clear: both;
-            display: block;
-        }
-
-        @if($engine === \BookStack\Entities\Tools\PdfGenerator::ENGINE_DOMPDF)
-        {{-- Fix for full width linked image sizes on DOMPDF --}}
-        .page-content a > img {
-            max-width: 700px;
-        }
-        {{-- Undoes the above for table images to prevent visually worse scenario, Awaiting next DOMPDF release for patch --}}
-        .page-content td a > img {
-            max-width: 100%;
-        }
-        @endif
-    </style>
-@endif
\ No newline at end of file
diff --git a/resources/views/exports/book.blade.php b/resources/views/exports/book.blade.php
new file mode 100644 (file)
index 0000000..42e03ea
--- /dev/null
@@ -0,0 +1,20 @@
+@extends('layouts.export')
+
+@section('title', $book->name)
+
+@section('content')
+
+    <h1 style="font-size: 4.8em">{{$book->name}}</h1>
+    <p>{{ $book->description }}</p>
+
+    @include('exports.parts.book-contents-menu', ['children' => $bookChildren])
+
+    @foreach($bookChildren as $bookChild)
+        @if($bookChild->isA('chapter'))
+            @include('exports.parts.chapter-item', ['chapter' => $bookChild])
+        @else
+            @include('exports.parts.page-item', ['page' => $bookChild, 'chapter' => null])
+        @endif
+    @endforeach
+
+@endsection
\ No newline at end of file
diff --git a/resources/views/exports/chapter.blade.php b/resources/views/exports/chapter.blade.php
new file mode 100644 (file)
index 0000000..ae49fa9
--- /dev/null
@@ -0,0 +1,16 @@
+@extends('layouts.export')
+
+@section('title', $chapter->name)
+
+@section('content')
+
+    <h1 style="font-size: 4.8em">{{$chapter->name}}</h1>
+    <p>{{ $chapter->description }}</p>
+
+    @include('exports.parts.chapter-contents-menu', ['pages' => $pages])
+
+    @foreach($pages as $page)
+        @include('exports.parts.page-item', ['page' => $page, 'chapter' => null])
+    @endforeach
+
+@endsection
\ No newline at end of file
similarity index 71%
rename from resources/views/pages/export.blade.php
rename to resources/views/exports/page.blade.php
index d2f448d6e889bd430f3ce53852530d8411c2945c..e9324e96b9924c7d11f261e17e52387563abe630 100644 (file)
@@ -8,6 +8,6 @@
     <hr>
 
     <div class="text-muted text-small">
-        @include('entities.export-meta', ['entity' => $page])
+        @include('exports.parts.meta', ['entity' => $page])
     </div>
 @endsection
\ No newline at end of file
diff --git a/resources/views/exports/parts/book-contents-menu.blade.php b/resources/views/exports/parts/book-contents-menu.blade.php
new file mode 100644 (file)
index 0000000..6b75442
--- /dev/null
@@ -0,0 +1,10 @@
+@if(count($children) > 0)
+    <ul class="contents">
+        @foreach($children as $bookChild)
+            <li><a href="#{{$bookChild->getType()}}-{{$bookChild->id}}">{{ $bookChild->name }}</a></li>
+            @if($bookChild->isA('chapter') && count($bookChild->visible_pages) > 0)
+                @include('exports.parts.chapter-contents-menu', ['pages' => $bookChild->visible_pages])
+            @endif
+        @endforeach
+    </ul>
+@endif
\ No newline at end of file
diff --git a/resources/views/exports/parts/chapter-contents-menu.blade.php b/resources/views/exports/parts/chapter-contents-menu.blade.php
new file mode 100644 (file)
index 0000000..eeaa349
--- /dev/null
@@ -0,0 +1,7 @@
+@if (count($pages) > 0)
+        <ul class="contents">
+            @foreach($pages as $page)
+                <li><a href="#page-{{$page->id}}">{{ $page->name }}</a></li>
+            @endforeach
+        </ul>
+@endif
\ No newline at end of file
diff --git a/resources/views/exports/parts/chapter-item.blade.php b/resources/views/exports/parts/chapter-item.blade.php
new file mode 100644 (file)
index 0000000..f58068b
--- /dev/null
@@ -0,0 +1,10 @@
+<div class="page-break"></div>
+<h1 id="chapter-{{$chapter->id}}">{{ $chapter->name }}</h1>
+
+<p>{{ $chapter->description }}</p>
+
+@if(count($chapter->visible_pages) > 0)
+    @foreach($chapter->visible_pages as $page)
+        @include('exports.parts.page-item', ['page' => $page, 'chapter' => $chapter])
+    @endforeach
+@endif
\ No newline at end of file
diff --git a/resources/views/exports/parts/page-item.blade.php b/resources/views/exports/parts/page-item.blade.php
new file mode 100644 (file)
index 0000000..1a138ae
--- /dev/null
@@ -0,0 +1,8 @@
+<div class="page-break"></div>
+
+@if (isset($chapter))
+    <div class="chapter-hint">{{$chapter->name}}</div>
+@endif
+
+<h1 id="page-{{$page->id}}">{{ $page->name }}</h1>
+{!! $page->html !!}
\ No newline at end of file
diff --git a/resources/views/exports/parts/styles.blade.php b/resources/views/exports/parts/styles.blade.php
new file mode 100644 (file)
index 0000000..830b8e4
--- /dev/null
@@ -0,0 +1,20 @@
+{{-- Fetch in our standard export styles --}}
+<style>
+    @if (!app()->runningUnitTests())
+        {!! file_get_contents(public_path('/dist/export-styles.css')) !!}
+    @endif
+</style>
+
+{{-- Apply any additional styles that can't be applied via our standard SCSS export styles --}}
+@if ($format === 'pdf')
+    <style>
+        /* Patches for CSS variable colors within PDF exports */
+        a {
+            color: {{ setting('app-color') }};
+        }
+
+        blockquote {
+            border-left-color: {{ setting('app-color') }};
+        }
+    </style>
+@endif
\ No newline at end of file
index 36568fef4dad22efa7876f9825ebd90336b9d6bb..d631ad3c9bf81db2a70badcf0acf11260a6eddc3 100644 (file)
@@ -8,10 +8,10 @@
         <meta http-equiv="Content-Security-Policy" content="{{ $cspContent }}">
     @endif
 
-    @include('common.export-styles', ['format' => $format, 'engine' => $engine ?? ''])
-    @include('common.export-custom-head')
+    @include('exports.parts.styles', ['format' => $format, 'engine' => $engine ?? ''])
+    @include('exports.parts.custom-head')
 </head>
-<body>
+<body class="export export-format-{{ $format }} export-engine-{{ $engine ?? 'none' }}">
 <div class="page-content">
     @yield('content')
 </div>
index 08d0921111fdb88a908867af8f228a9c1280e175..826b69be5d22b307882ba9e4385fd85d599c8a99 100644 (file)
@@ -457,4 +457,12 @@ class ExportTest extends TestCase
             $resp->assertElementExists('head meta[http-equiv="Content-Security-Policy"][content*="script-src "]');
         }
     }
+
+    public function test_html_exports_contain_body_classes_for_export_identification()
+    {
+        $page = Page::query()->first();
+
+        $resp = $this->asEditor()->get($page->getUrl('/export/html'));
+        $resp->assertElementExists('body.export.export-format-html.export-engine-none');
+    }
 }