FEATURE: add blade template registration into templates
This commit is contained in:
@@ -30,8 +30,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
// ignore running from artisan
|
||||
if (App::runningInConsole()) {
|
||||
$this->publishViewResources();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -143,37 +141,5 @@ class AppServiceProvider extends ServiceProvider
|
||||
$registrator->register(new Files(), new AdminFiles(), SearchEngineRegistrator::ADMIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish all public assets from all themes
|
||||
*/
|
||||
private function publishViewResources()
|
||||
{
|
||||
$theme = config('app.theme');
|
||||
$themeDir = resource_path('views/visitor/' . $theme);
|
||||
|
||||
// publish assets if exists for current theme
|
||||
if (is_dir($themeDir . '/' . Template::ASSETS_DIRECTORY)) {
|
||||
$this->publishes([$themeDir . '/' . Template::ASSETS_DIRECTORY => public_path('assets/' . $theme)], 'public-assets');
|
||||
}
|
||||
|
||||
if (is_dir($themeDir . '/' . Template::MODULES_DIRECTORY)) {
|
||||
$this->publishModuleViews($themeDir . '/' . Template::MODULES_DIRECTORY);
|
||||
}
|
||||
}
|
||||
|
||||
private function publishModuleViews($themeModules)
|
||||
{
|
||||
$theme = config('app.theme');
|
||||
$modules = File::directories($themeModules);
|
||||
|
||||
$moduleViews = [];
|
||||
foreach ($modules as $module) {
|
||||
$moduleName = strtolower(basename($module));
|
||||
$moduleViews[$module] = resource_path('views/modules/' . $moduleName . '/visitor/' . $theme);
|
||||
}
|
||||
|
||||
if (!empty($moduleViews)) {
|
||||
$this->publishes($moduleViews, 'module-views');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,34 +4,47 @@ namespace App\Providers;
|
||||
|
||||
use App\Handlers\Registrators\TemplateRegistrator;
|
||||
use App\Models\Module;
|
||||
use App\Models\Template;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class TemplateServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function boot()
|
||||
private function getTemplate()
|
||||
{
|
||||
if (App::runningInConsole())
|
||||
return;
|
||||
|
||||
parent::boot();
|
||||
|
||||
// select template
|
||||
$template = Module::where('is_template', true)
|
||||
->where('enabled', true)
|
||||
->first();
|
||||
|
||||
if ($template) {
|
||||
$template->settings = json_decode($template->module_settings);
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
// ignore running from artisan
|
||||
if (App::runningInConsole()) {
|
||||
$this->publishViewResources();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$template = $this->getTemplate();
|
||||
|
||||
if (!$template) {
|
||||
throw new \ErrorException('Template is not set, cannot continue');
|
||||
}
|
||||
|
||||
$templateSettings = json_decode($template->module_settings);
|
||||
|
||||
// include files
|
||||
$files = isset($templateSettings->files) ? $templateSettings->files : [];
|
||||
$files = isset($template->settings->files) ? $template->settings->files : [];
|
||||
|
||||
foreach ($files as $file) {
|
||||
include_once app_path('../templates/' . $templateSettings->staticName . '/' . $file);
|
||||
include_once $file;
|
||||
}
|
||||
|
||||
// register templates
|
||||
@@ -51,16 +64,18 @@ class TemplateServiceProvider extends ServiceProvider
|
||||
$registrator = $this->app->make('registerTemplateDir');
|
||||
foreach ($publicTemplates as $template) {
|
||||
// setup some global variables
|
||||
// try {
|
||||
// $registrator->setBaseDirectory('resources/views/modules/gallery/visitor');
|
||||
// $registrator->setNamespace('gallery');
|
||||
// $registrator->setModuleId(call_user_func([config('gallery.handler'), 'getModuleId']));
|
||||
//
|
||||
// // register path with current template name
|
||||
// $registrator->register(config('app.theme'), 'gallery::admin/adminMenu.templatePath');
|
||||
// } catch (InvalidArgumentException $e) {
|
||||
// // ignore this exception
|
||||
// }
|
||||
$module = strtolower($template['module']);
|
||||
$namespace = isset($template['namespace']) ? $template['namespace'] : strtolower($template['module']);
|
||||
try {
|
||||
$registrator->setBaseDirectory('resources/views/modules/' . $module);
|
||||
$registrator->setNamespace($namespace);
|
||||
$registrator->setModuleId(call_user_func([config($module . '.handler'), 'getModuleId']));
|
||||
|
||||
// register path with current template name
|
||||
$registrator->register('visitor', $template['templateName']);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
// ignore this exception
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,4 +87,32 @@ class TemplateServiceProvider extends ServiceProvider
|
||||
public function register()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish all public assets from all themes
|
||||
*/
|
||||
private function publishViewResources()
|
||||
{
|
||||
$template = $this->getTemplate();
|
||||
if (!$template) {
|
||||
return;
|
||||
}
|
||||
|
||||
$templateDir = app_path('../templates/' . $template->settings->staticName . '/Resources');
|
||||
$assetsDir = $templateDir . '/' . Template::ASSETS_DIRECTORY;
|
||||
$viewsDir = $templateDir . '/views';
|
||||
|
||||
// publish assets if exists for current theme
|
||||
if (is_dir($assetsDir)) {
|
||||
$this->publishes([$assetsDir => public_path('assets/visitor')], 'public-assets');
|
||||
}
|
||||
|
||||
// publish base visitors views
|
||||
$this->publishes([$viewsDir . '/visitor' => resource_path('views/visitor')], 'module-views');
|
||||
|
||||
// publish admin views
|
||||
if (is_dir($viewsDir . '/modules')) {
|
||||
$this->publishes([$viewsDir . '/modules' => resource_path('views/modules')], 'module-views');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user