Added the ability for themes to have their own stylesheet - theme.css in the public folder

This commit is contained in:
Andy Heathershaw 2016-09-02 12:36:34 +01:00
parent 82ec82f628
commit 67bfecd2b3
2 changed files with 19 additions and 3 deletions

View File

@ -13,10 +13,16 @@ class ThemeHelper
return $this->getThemeName(); return $this->getThemeName();
} }
public function hasStylesheet()
{
$cssFilename = sprintf('%s/%s/theme.css', $this->getThemePublicPath(), $this->getThemeName());
return file_exists($cssFilename);
}
public function info() public function info()
{ {
$themeName = $this->getThemeName(); $themeName = $this->getThemeName();
$jsonFile = sprintf('%s/%s/theme.json', $this->getThemeBasePath(), $this->sanitiseThemeName($themeName)); $jsonFile = sprintf('%s/%s/theme.json', $this->getThemePrivatePath(), $this->sanitiseThemeName($themeName));
if (file_exists($jsonFile)) if (file_exists($jsonFile))
{ {
return json_decode(file_get_contents($jsonFile), true); return json_decode(file_get_contents($jsonFile), true);
@ -47,17 +53,22 @@ class ThemeHelper
{ {
return sprintf( return sprintf(
'%s/%s/%s.blade.php', '%s/%s/%s.blade.php',
$this->getThemeBasePath(), $this->getThemePrivatePath(),
$themeName, $themeName,
str_replace('.', DIRECTORY_SEPARATOR, $viewPath) str_replace('.', DIRECTORY_SEPARATOR, $viewPath)
); );
} }
private function getThemeBasePath() private function getThemePrivatePath()
{ {
return sprintf('%s/resources/views/themes', dirname(dirname(__DIR__))); return sprintf('%s/resources/views/themes', dirname(dirname(__DIR__)));
} }
private function getThemePublicPath()
{
return sprintf('%s/public/themes', dirname(dirname(__DIR__)));
}
private function getThemeName() private function getThemeName()
{ {
$themeName = ThemeHelper::DEFAULT_THEME; $themeName = ThemeHelper::DEFAULT_THEME;

View File

@ -14,6 +14,11 @@
<link href="themes/base/bootstrap/css/bootstrap.min.css?v={{ urlencode(config('app.version')) }}" rel="stylesheet"> <link href="themes/base/bootstrap/css/bootstrap.min.css?v={{ urlencode(config('app.version')) }}" rel="stylesheet">
<link href="themes/base/font-awesome/css/font-awesome.min.css?v={{ urlencode(config('app.version')) }}" rel="stylesheet"> <link href="themes/base/font-awesome/css/font-awesome.min.css?v={{ urlencode(config('app.version')) }}" rel="stylesheet">
<link href="themes/base/css/app.css?v={{ urlencode(config('app.version')) }}" rel="stylesheet"> <link href="themes/base/css/app.css?v={{ urlencode(config('app.version')) }}" rel="stylesheet">
@if (\App\Facade\Theme::hasStylesheet())
<link href="{{ $theme_url }}/theme.css?v={{ urlencode($theme_version) }}" rel="stylesheet">
@endif
@stack('styles') @stack('styles')
</head> </head>
<body> <body>