Skip to content

Commit 7735128

Browse files
authored
Merge pull request #12 from thedevdojo/updatingThemes
Updating themes
2 parents 4840cc0 + 5f08d3a commit 7735128

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ You will want to publish the themes config, and you will now see a new config lo
4242
4343
return [
4444
45-
'themes_folder' => resource_path('views/themes'),
45+
'folder' => resource_path('themes'),
4646
'publish_assets' => true,
4747
'create_tables' => true
4848
4949
];
5050
```
5151

52-
Now, you can choose an alternate location for your themes folder. By default this will be put into the `resources/views` folder; however, you can change that to any location you would like.
52+
Now, you can choose an alternate location for your themes folder. By default this will be put into the `resources` folder; however, you can change that to any location you would like.
53+
54+
> Warning, If you add the themes folder into the `resources/views` folder and you run `php artisan optimize` you may get an error that it cannot find certain components. This is because it will search all the `.blade.php` files inside the views folder. So, this may not be the best place to put your themes. Instead this package will register only the views of the active theme.
5355
5456
Additionally, you can set **publish_assets** to *true* or *false*, if it is set to *true* anytime the themes directory is scanned it will publish the `assets` folder in your theme to the public folder inside a new `themes` folder. Set this to *false* and this will no longer happen.
5557

config/themes.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?php
22

33
return [
4-
5-
'themes_folder' => resource_path('views/themes'),
4+
'folder' => resource_path('themes'),
65
'publish_assets' => true,
76
'create_tables' => true
8-
97
];

resources/views/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
@if(count($themes) < 1)
165165
<div class="alert alert-warning">
166166
<strong>Wuh oh!</strong>
167-
<p>It doesn't look like you have any themes available in your theme folder located at <code><?= resource_path('views/themes'); ?></code></p>
167+
<p>It doesn't look like you have any themes available in your theme folder located at <code><?= resource_path('themes'); ?></code></p>
168168
</div>
169169
@endif
170170

resources/views/options.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<div class="panel">
5959
<div class="panel-body">
6060

61-
@if(file_exists(config('themes.themes_folder', resource_path('views/themes')) . '/' . $theme->folder . '/options.blade.php'))
61+
@if(file_exists(config('themes.folder', resource_path('themes')) . '/' . $theme->folder . '/options.blade.php'))
6262
<?php if (!defined('ACTIVE_THEME_FOLDER')) { define("ACTIVE_THEME_FOLDER", $theme->folder); } ?>
6363
<form action="{{ route('voyager.theme.options', $theme->folder) }}" method="POST" enctype="multipart/form-data">
6464

src/Http/Controllers/ThemesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ThemesController extends Controller
1414
private $themes_folder = '';
1515

1616
public function __construct(){
17-
$this->themes_folder = config('themes.themes_folder', resource_path('views/themes'));
17+
$this->themes_folder = config('themes.folder', resource_path('themes'));
1818
}
1919

2020
public function index(){

src/ThemesServiceProvider.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ThemesServiceProvider extends ServiceProvider
3232
*/
3333
public function register()
3434
{
35-
if ( request()->is(config('voyager.prefix')) || request()->is(config('voyager.prefix').'/*') || app()->runningInConsole() ) {
35+
if ( app()->runningInConsole() ) {
3636

3737
try {
3838
DB::connection()->getPdo();
@@ -66,7 +66,9 @@ public function boot()
6666
{
6767
try{
6868

69-
$this->loadViewsFrom(__DIR__.'/../resources/views', 'themes');
69+
// dd(config('themes.folder'));
70+
71+
//$this->loadViewsFrom(config('themes.folder'), 'themes');
7072

7173
$theme = '';
7274

@@ -84,17 +86,17 @@ public function boot()
8486

8587
view()->share('theme', $theme);
8688

87-
$this->themes_folder = config('themes.themes_folder', resource_path('views/themes'));
89+
$folder = config('themes.folder', resource_path('themes'));
8890

89-
$this->loadDynamicMiddleware($this->themes_folder, $theme);
91+
$this->loadDynamicMiddleware($folder, $theme);
9092
$this->registerThemeComponents($theme);
9193
$this->registerThemeFolioDirectory($theme);
9294

9395
// Make sure we have an active theme
9496
if (isset($theme)) {
95-
$this->loadViewsFrom($this->themes_folder.'/'.@$theme->folder, 'theme');
97+
$this->loadViewsFrom($folder.'/'.@$theme->folder, 'theme');
9698
}
97-
$this->loadViewsFrom($this->themes_folder, 'themes_folder');
99+
//$this->loadViewsFrom($folder, 'themes_folder');
98100

99101
} catch(\Exception $e){
100102
return $e->getMessage();
@@ -120,13 +122,13 @@ public function addThemeRoutes($router)
120122
}
121123

122124
private function registerThemeComponents($theme){
123-
Blade::anonymousComponentPath(resource_path('views/themes/' . $theme->folder . '/components/elements'));
124-
Blade::anonymousComponentPath(resource_path('views/themes/' . $theme->folder . '/components'));
125+
Blade::anonymousComponentPath(config('themes.folder') . '/' . $theme->folder . '/components/elements');
126+
Blade::anonymousComponentPath(config('themes.folder') . '/' . $theme->folder . '/components');
125127
}
126128

127129
private function registerThemeFolioDirectory($theme){
128-
if (File::exists(resource_path('views/themes/' . $theme->folder . '/pages'))) {
129-
Folio::path(resource_path('views/themes/' . $theme->folder . '/pages'))->middleware([
130+
if (File::exists( config('themes.folder') . '/' . $theme->folder . '/pages')) {
131+
Folio::path( config('themes.folder') . '/' . $theme->folder . '/pages')->middleware([
130132
'*' => [
131133
//
132134
],
@@ -182,11 +184,11 @@ protected function ensurePermissionExist()
182184
}
183185
}
184186

185-
private function loadDynamicMiddleware($themes_folder, $theme){
187+
private function loadDynamicMiddleware($folder, $theme){
186188
if (empty($theme)) {
187189
return;
188190
}
189-
$middleware_folder = $themes_folder . '/' . $theme->folder . '/middleware';
191+
$middleware_folder = $folder . '/' . $theme->folder . '/middleware';
190192
if(file_exists( $middleware_folder )){
191193
$middleware_files = scandir($middleware_folder);
192194
foreach($middleware_files as $middleware){

0 commit comments

Comments
 (0)