]> BookStack Code Mirror - bookstack/commitdiff
Made it possible to override icons via custom theme
authorDan Brown <redacted>
Sat, 17 Feb 2018 12:36:24 +0000 (12:36 +0000)
committerDan Brown <redacted>
Sat, 17 Feb 2018 12:36:24 +0000 (12:36 +0000)
app/helpers.php
config/view.php

index daa747e7125a433d1c4571e2a5025cd63ac61d8f..c087e350991f735fc8b6ae9ba8d6694fb52f7c0d 100644 (file)
@@ -130,13 +130,42 @@ function redirect($to = null, $status = 302, $headers = [], $secure = null)
     return app('redirect')->to($to, $status, $headers, $secure);
 }
 
+/**
+ * Get a path to a theme resource.
+ * @param string $path
+ * @return string|boolean
+ */
+function theme_path($path = '')
+{
+    $theme = config('view.theme');
+    if (!$theme) {
+        return false;
+    }
+
+    return base_path('themes/' . $theme .($path ? DIRECTORY_SEPARATOR.$path : $path));
+}
+
+/**
+ * Get fetch an SVG icon as a string.
+ * Checks for icons defined within a custom theme before defaulting back
+ * to the 'resources/assets/icons' folder.
+ * @param $name
+ * @param array $attrs
+ * @return mixed
+ */
 function icon($name, $attrs = [])
 {
-    $iconPath = resource_path('assets/icons/' . $name . '.svg');
     $attrString = ' ';
     foreach ($attrs as $attrName => $attr) {
         $attrString .=  $attrName . '="' . $attr . '" ';
     }
+
+    $iconPath = resource_path('assets/icons/' . $name . '.svg');
+    $themeIconPath = theme_path('icons/' . $name . '.svg');
+    if ($themeIconPath && file_exists($themeIconPath)) {
+        $iconPath = $themeIconPath;
+    }
+
     $fileContents = file_get_contents($iconPath);
     return  str_replace('<svg', '<svg' . $attrString, $fileContents);
 }
index 8dc2841e748f035bd4860081ab6dfb760c922e53..e9a96c8ab8df3c04d6de5801b57920b4ec6706d9 100644 (file)
@@ -7,6 +7,19 @@ if ($theme = env('APP_THEME', false)) {
 
 return [
 
+    /*
+    |--------------------------------------------------------------------------
+    | App theme
+    |--------------------------------------------------------------------------
+    |
+    | This option defines the theme to use for the application. When a theme
+    | is set there mush be a `themes/<theme_name>` folder to hold the
+    | custom theme overrides.
+    |
+    */
+
+    'theme' => env('APP_THEME', false),
+
     /*
     |--------------------------------------------------------------------------
     | View Storage Paths
Morty Proxy This is a proxified and sanitized view of the page, visit original site.