FEATURE #1524: merge views into one directory

This commit is contained in:
Michal Kváček
2016-03-31 16:47:40 +02:00
parent 980fec83c0
commit 7a51c913d3
4 changed files with 56 additions and 7 deletions
+1
View File
@@ -2,6 +2,7 @@
/resources/views/modules /resources/views/modules
/public/modules /public/modules
/resources/views/vendor /resources/views/vendor
/public/assets
# directories with custom templates # directories with custom templates
**/views/**/custom/* **/views/**/custom/*
@@ -21,7 +21,6 @@ class TemplateRegistrator
protected $namespace; protected $namespace;
/** /**
* @var string absolute path to currently registered directory * @var string absolute path to currently registered directory
*
* This variable is set in register() method as $baseDirectory/$path * This variable is set in register() method as $baseDirectory/$path
*/ */
protected $registeredPath; protected $registeredPath;
@@ -78,7 +77,6 @@ class TemplateRegistrator
/** /**
* Registers new template path. * Registers new template path.
*
* This method registeres given path itself with all subdirectories * This method registeres given path itself with all subdirectories
* *
* @param string $path path relatively to root of the project * @param string $path path relatively to root of the project
@@ -140,7 +138,13 @@ class TemplateRegistrator
{ {
// skip custom directories (contains updated templates only) // skip custom directories (contains updated templates only)
$dirName = basename($path); $dirName = basename($path);
if ($dirName == Template::EDITED_TEMPLATES_DIRECTORY) { $ignoredDirectories = [
Template::EDITED_TEMPLATES_DIRECTORY,
Template::ASSETS_DIRECTORY,
Template::MODULES_DIRECTORY
];
if (in_array($dirName, $ignoredDirectories)) {
return; return;
} }
@@ -156,7 +160,6 @@ class TemplateRegistrator
/** /**
* Registers all templates * Registers all templates
*
* This method takes all templates in given directory and registers them into database. Templates registered in * This method takes all templates in given directory and registers them into database. Templates registered in
* this way may be used for further manipulation. * this way may be used for further manipulation.
* *
@@ -259,7 +262,6 @@ class TemplateRegistrator
/** /**
* Get template name * Get template name
*
* Converts path to template to corresponding name * Converts path to template to corresponding name
* *
* @param $template * @param $template
+3
View File
@@ -21,6 +21,9 @@ class Template extends Model
protected $guarded = []; protected $guarded = [];
protected $pathModel = null; protected $pathModel = null;
const EDITED_TEMPLATES_DIRECTORY = 'custom'; const EDITED_TEMPLATES_DIRECTORY = 'custom';
const ASSETS_DIRECTORY = 'assets';
const MODULES_DIRECTORY = 'modules';
const TEMPLATE_SUFFIX = '.blade.php'; const TEMPLATE_SUFFIX = '.blade.php';
const CUSTOM_EDIT_DIRECTORY = 1; const CUSTOM_EDIT_DIRECTORY = 1;
const ORIGINAL_DIRECTORY = 2; const ORIGINAL_DIRECTORY = 2;
+45 -2
View File
@@ -10,21 +10,24 @@ use App\Handlers\Search\Content;
use App\Handlers\Search\Files; use App\Handlers\Search\Files;
use App\Handlers\Search\Presenters\AdminContent as AdminContentPresenter; use App\Handlers\Search\Presenters\AdminContent as AdminContentPresenter;
use App\Handlers\Search\Presenters\AdminFiles; use App\Handlers\Search\Presenters\AdminFiles;
use App\Models\Template;
use App\Widgets\HtmlCode\HtmlCode; use App\Widgets\HtmlCode\HtmlCode;
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\File;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider class AppServiceProvider extends ServiceProvider
{ {
/** /**
* Bootstrap any application services. * Bootstrap any application services.
*
* @return void * @return void
*/ */
public function boot() public function boot()
{ {
// ignore running from artisan // ignore running from artisan
if (App::runningInConsole()) { if (App::runningInConsole()) {
$this->publishViewResources();
return; return;
} }
@@ -36,7 +39,6 @@ class AppServiceProvider extends ServiceProvider
/** /**
* Register any application services. * Register any application services.
*
* @return void * @return void
*/ */
public function register() public function register()
@@ -118,4 +120,45 @@ class AppServiceProvider extends ServiceProvider
$registrator->register(new Content(), new AdminContentPresenter()); $registrator->register(new Content(), new AdminContentPresenter());
$registrator->register(new Files(), new AdminFiles()); $registrator->register(new Files(), new AdminFiles());
} }
/**
* Publish all public assets from all themes
*/
private function publishViewResources()
{
$themes = File::directories(resource_path('views/visitor'));
$assets = [];
foreach ($themes as $theme) {
$themeName = basename($theme);
if (is_dir($theme . '/'.Template::ASSETS_DIRECTORY)) {
$assets[$theme . '/'.Template::ASSETS_DIRECTORY] = public_path('assets/' . $themeName);
}
if (is_dir($theme . '/'.Template::MODULES_DIRECTORY)) {
$this->publishModuleViews($theme . '/'.Template::MODULES_DIRECTORY, $themeName);
}
}
if (!empty($assets)) {
$this->publishes($assets, 'public-assets');
}
}
private function publishModuleViews($themeModules, $themeName)
{
$modules = File::directories($themeModules);
$moduleViews = [];
foreach ($modules as $module) {
$moduleName = strtolower(basename($module));
$moduleViews[$module] = resource_path('views/modules/' . $moduleName . '/visitor/' . $themeName);
}
if (!empty($moduleViews)) {
$this->publishes($moduleViews, 'module-views');
}
}
} }