Commit 78d761e9 authored by Nicolas Widart's avatar Nicolas Widart Committed by GitHub

Merge pull request #297 from armababy/feature/extra-view-namespaces

Feature/extra view namespaces
parents 61b2dcab 40764b7a
...@@ -14,4 +14,22 @@ return [ ...@@ -14,4 +14,22 @@ return [
'setting', 'setting',
'media', 'media',
], ],
/*
|--------------------------------------------------------------------------
| Load additional view namespaces for a module
|--------------------------------------------------------------------------
| You can specify place from which you would like to use module views.
| You can use any combination, but generally it's advisable to add only one,
| extra view namespace.
| By default every extra namespace will be set to false.
*/
'useViewNamespaces' => [
// Read module views from /Themes/<backend-theme-name>/views/modules/asgard/<module-name>
'backend-theme' => false,
// Read module views from /Themes/<frontend-theme-name>/views/modules/asgard/<module-name>
'frontend-theme' => false,
// Read module views from /resources/views/asgard/<module-name>
'resources' => false,
],
]; ];
...@@ -112,40 +112,47 @@ return [ ...@@ -112,40 +112,47 @@ return [
'clipboard.js' => ['theme' => 'vendor/clipboard/dist/clipboard.min.js'], 'clipboard.js' => ['theme' => 'vendor/clipboard/dist/clipboard.min.js'],
], ],
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Define which default assets will always be included in your pages | Define which default assets will always be included in your pages
| through the asset pipeline | through the asset pipeline
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
*/ */
'admin-required-assets' => [ 'admin-required-assets' => [
'css' => [ 'css' => [
'bootstrap.css', 'bootstrap.css',
'font-awesome.css', 'font-awesome.css',
'alertify.core.css', 'alertify.core.css',
'alertify.default.css', 'alertify.default.css',
'dataTables.bootstrap.css', 'dataTables.bootstrap.css',
'icheck.blue.css', 'icheck.blue.css',
'AdminLTE.css', 'AdminLTE.css',
'AdminLTE.all.skins.css', 'AdminLTE.all.skins.css',
'animate.css', 'animate.css',
'pace.css', 'pace.css',
'selectize-default.css', 'selectize-default.css',
'asgard.css', 'asgard.css',
], ],
'js' => [ 'js' => [
'bootstrap.js', 'bootstrap.js',
'mousetrap.js', 'mousetrap.js',
'alertify.js', 'alertify.js',
'icheck.js', 'icheck.js',
'jquery.dataTables.js', 'jquery.dataTables.js',
'dataTables.bootstrap.js', 'dataTables.bootstrap.js',
'jquery.slug.js', 'jquery.slug.js',
'keypressAction.js', 'keypressAction.js',
'app.js', 'app.js',
'pace.js', 'pace.js',
'selectize.js', 'selectize.js',
'main.js', 'main.js',
], ],
], ],
/*
|--------------------------------------------------------------------------
| Enable module view overrides at theme locations
|--------------------------------------------------------------------------
*/
'enable-theme-overrides' => false,
]; ];
...@@ -23,11 +23,6 @@ class CoreServiceProvider extends ServiceProvider ...@@ -23,11 +23,6 @@ class CoreServiceProvider extends ServiceProvider
*/ */
protected $defer = false; protected $defer = false;
/**
* @var string
*/
protected $prefix = 'asgard';
/** /**
* The filters base class name. * The filters base class name.
* *
...@@ -45,15 +40,15 @@ class CoreServiceProvider extends ServiceProvider ...@@ -45,15 +40,15 @@ class CoreServiceProvider extends ServiceProvider
public function boot() public function boot()
{ {
$this->registerMiddleware($this->app['router']);
$this->registerModuleResourceNamespaces();
$this->publishConfig('core', 'available-locales'); $this->publishConfig('core', 'available-locales');
$this->publishConfig('core', 'config'); $this->publishConfig('core', 'config');
$this->publishConfig('core', 'core'); $this->publishConfig('core', 'core');
$this->publishConfig('core', 'settings'); $this->publishConfig('core', 'settings');
$this->publishConfig('core', 'permissions'); $this->publishConfig('core', 'permissions');
$this->registerMiddleware($this->app['router']);
$this->registerModuleResourceNamespaces();
$this->bladeDirectives(); $this->bladeDirectives();
} }
...@@ -119,6 +114,24 @@ class CoreServiceProvider extends ServiceProvider ...@@ -119,6 +114,24 @@ class CoreServiceProvider extends ServiceProvider
return new ThemeManager($app, $path); return new ThemeManager($app, $path);
}); });
$this->app->singleton('asgard.ModulesList', function () {
return [
'block',
'blog',
'core',
'dashboard',
'media',
'menu',
'notification',
'page',
'setting',
'tag',
'translation',
'user',
'workshop',
];
});
} }
/** /**
...@@ -126,8 +139,20 @@ class CoreServiceProvider extends ServiceProvider ...@@ -126,8 +139,20 @@ class CoreServiceProvider extends ServiceProvider
*/ */
private function registerModuleResourceNamespaces() private function registerModuleResourceNamespaces()
{ {
$themes = [];
// Saves about 20ms-30ms at loading
if ($this->app['config']->get('asgard.core.core.enable-theme-overrides') === true) {
$themeManager = app(ThemeManager::class);
$themes = [
'backend' => $themeManager->find(config('asgard.core.core.admin-theme'))->getPath(),
'frontend' => $themeManager->find(setting('core::template', null, 'Flatly'))->getPath(),
];
}
foreach ($this->app['modules']->getOrdered() as $module) { foreach ($this->app['modules']->getOrdered() as $module) {
$this->registerViewNamespace($module); $this->registerViewNamespace($module, $themes);
$this->registerLanguageNamespace($module); $this->registerLanguageNamespace($module);
} }
} }
...@@ -135,16 +160,36 @@ class CoreServiceProvider extends ServiceProvider ...@@ -135,16 +160,36 @@ class CoreServiceProvider extends ServiceProvider
/** /**
* Register the view namespaces for the modules * Register the view namespaces for the modules
* @param Module $module * @param Module $module
* @param array $themes
*/ */
protected function registerViewNamespace(Module $module) protected function registerViewNamespace(Module $module, array $themes)
{ {
if ($module->getLowerName() == 'user') { $hints = [];
return; $moduleName = $module->getLowerName();
if (is_core_module($moduleName)) {
$configFile = 'config';
$configKey = 'asgard.' . $moduleName . '.' . $configFile;
$this->mergeConfigFrom($module->getExtraPath('Config' . DIRECTORY_SEPARATOR . $configFile . '.php'), $configKey);
$moduleConfig = $this->app['config']->get($configKey . '.useViewNamespaces');
if (count($themes) > 0) {
if ($themes['backend'] !== null && array_get($moduleConfig, 'backend-theme') === true) {
$hints[] = $themes['backend'] . '/views/modules/asgard/' . $moduleName;
}
if ($themes['frontend'] !== null && array_get($moduleConfig, 'frontend-theme') === true) {
$hints[] = $themes['frontend'] . '/views/modules/asgard/' . $moduleName;
}
}
if (array_get($moduleConfig, 'resources') === true) {
$hints[] = base_path('resources/views/asgard/' . $moduleName);
}
} }
$this->app['view']->addNamespace(
$module->getLowerName(), $hints[] = $module->getPath() . '/Resources/views';
$module->getPath() . '/Resources/views'
); $this->app['view']->addNamespace($moduleName, $hints);
} }
/** /**
......
...@@ -26,3 +26,10 @@ if (! function_exists('is_module_enabled')) { ...@@ -26,3 +26,10 @@ if (! function_exists('is_module_enabled')) {
return array_key_exists($module, app('modules')->enabled()); return array_key_exists($module, app('modules')->enabled());
} }
} }
if (! function_exists('is_core_module')) {
function is_core_module($module)
{
return in_array(strtolower($module), app('asgard.ModulesList'));
}
}
...@@ -10,4 +10,22 @@ return [ ...@@ -10,4 +10,22 @@ return [
| No custom sidebar: null | No custom sidebar: null
*/ */
'custom-sidebar' => null, 'custom-sidebar' => null,
/*
|--------------------------------------------------------------------------
| Load additional view namespaces for a module
|--------------------------------------------------------------------------
| You can specify place from which you would like to use module views.
| You can use any combination, but generally it's advisable to add only one,
| extra view namespace.
| By default every extra namespace will be set to false.
*/
'useViewNamespaces' => [
// Read module views from /Themes/<backend-theme-name>/views/modules/asgard/<module-name>
'backend-theme' => false,
// Read module views from /Themes/<frontend-theme-name>/views/modules/asgard/<module-name>
'frontend-theme' => false,
// Read module views from /resources/views/asgard/<module-name>
'resources' => true,
],
]; ];
...@@ -44,10 +44,6 @@ class DashboardServiceProvider extends ServiceProvider ...@@ -44,10 +44,6 @@ class DashboardServiceProvider extends ServiceProvider
__DIR__ . '/../Resources/views' => base_path('resources/views/asgard/dashboard'), __DIR__ . '/../Resources/views' => base_path('resources/views/asgard/dashboard'),
], 'views'); ], 'views');
$this->app['view']->prependNamespace(
'dashboard',
base_path('resources/views/asgard/dashboard')
);
$this->app['view']->prependNamespace( $this->app['view']->prependNamespace(
'dashboard', 'dashboard',
$theme->find(config('asgard.core.core.admin-theme'))->getPath() . '/views/modules/dashboard' $theme->find(config('asgard.core.core.admin-theme'))->getPath() . '/views/modules/dashboard'
......
...@@ -48,4 +48,22 @@ return [ ...@@ -48,4 +48,22 @@ return [
| No custom sidebar: null | No custom sidebar: null
*/ */
'custom-sidebar' => null, 'custom-sidebar' => null,
/*
|--------------------------------------------------------------------------
| Load additional view namespaces for a module
|--------------------------------------------------------------------------
| You can specify place from which you would like to use module views.
| You can use any combination, but generally it's advisable to add only one,
| extra view namespace.
| By default every extra namespace will be set to false.
*/
'useViewNamespaces' => [
// Read module views from /Themes/<backend-theme-name>/views/modules/asgard/<module-name>
'backend-theme' => false,
// Read module views from /Themes/<frontend-theme-name>/views/modules/asgard/<module-name>
'frontend-theme' => false,
// Read module views from /resources/views/asgard/<module-name>
'resources' => false,
],
]; ];
...@@ -18,4 +18,22 @@ return [ ...@@ -18,4 +18,22 @@ return [
| having to send it via the views | having to send it via the views
*/ */
'default_menu_presenter' => null, 'default_menu_presenter' => null,
/*
|--------------------------------------------------------------------------
| Load additional view namespaces for a module
|--------------------------------------------------------------------------
| You can specify place from which you would like to use module views.
| You can use any combination, but generally it's advisable to add only one,
| extra view namespace.
| By default every extra namespace will be set to false.
*/
'useViewNamespaces' => [
// Read module views from /Themes/<backend-theme-name>/views/modules/asgard/<module-name>
'backend-theme' => false,
// Read module views from /Themes/<frontend-theme-name>/views/modules/asgard/<module-name>
'frontend-theme' => false,
// Read module views from /resources/views/asgard/<module-name>
'resources' => false,
],
]; ];
...@@ -53,4 +53,22 @@ return [ ...@@ -53,4 +53,22 @@ return [
| No custom sidebar: null | No custom sidebar: null
*/ */
'custom-sidebar' => null, 'custom-sidebar' => null,
/*
|--------------------------------------------------------------------------
| Load additional view namespaces for a module
|--------------------------------------------------------------------------
| You can specify place from which you would like to use module views.
| You can use any combination, but generally it's advisable to add only one,
| extra view namespace.
| By default every extra namespace will be set to false.
*/
'useViewNamespaces' => [
// Read module views from /Themes/<backend-theme-name>/views/modules/asgard/<module-name>
'backend-theme' => false,
// Read module views from /Themes/<frontend-theme-name>/views/modules/asgard/<module-name>
'frontend-theme' => false,
// Read module views from /resources/views/asgard/<module-name>
'resources' => false,
],
]; ];
...@@ -10,4 +10,22 @@ return [ ...@@ -10,4 +10,22 @@ return [
| No custom sidebar: null | No custom sidebar: null
*/ */
'custom-sidebar' => null, 'custom-sidebar' => null,
/*
|--------------------------------------------------------------------------
| Load additional view namespaces for a module
|--------------------------------------------------------------------------
| You can specify place from which you would like to use module views.
| You can use any combination, but generally it's advisable to add only one,
| extra view namespace.
| By default every extra namespace will be set to false.
*/
'useViewNamespaces' => [
// Read module views from /Themes/<backend-theme-name>/views/modules/asgard/<module-name>
'backend-theme' => false,
// Read module views from /Themes/<frontend-theme-name>/views/modules/asgard/<module-name>
'frontend-theme' => false,
// Read module views from /resources/views/asgard/<module-name>
'resources' => false,
],
]; ];
...@@ -12,4 +12,22 @@ return [ ...@@ -12,4 +12,22 @@ return [
| No custom sidebar: null | No custom sidebar: null
*/ */
'custom-sidebar' => null, 'custom-sidebar' => null,
/*
|--------------------------------------------------------------------------
| Load additional view namespaces for a module
|--------------------------------------------------------------------------
| You can specify place from which you would like to use module views.
| You can use any combination, but generally it's advisable to add only one,
| extra view namespace.
| By default every extra namespace will be set to false.
*/
'useViewNamespaces' => [
// Read module views from /Themes/<backend-theme-name>/views/modules/asgard/<module-name>
'backend-theme' => false,
// Read module views from /Themes/<frontend-theme-name>/views/modules/asgard/<module-name>
'frontend-theme' => false,
// Read module views from /resources/views/asgard/<module-name>
'resources' => false,
],
]; ];
...@@ -18,4 +18,22 @@ return [ ...@@ -18,4 +18,22 @@ return [
| No custom sidebar: null | No custom sidebar: null
*/ */
'custom-sidebar' => null, 'custom-sidebar' => null,
/*
|--------------------------------------------------------------------------
| Load additional view namespaces for a module
|--------------------------------------------------------------------------
| You can specify place from which you would like to use module views.
| You can use any combination, but generally it's advisable to add only one,
| extra view namespace.
| By default every extra namespace will be set to false.
*/
'useViewNamespaces' => [
// Read module views from /Themes/<backend-theme-name>/views/modules/asgard/<module-name>
'backend-theme' => false,
// Read module views from /Themes/<frontend-theme-name>/views/modules/asgard/<module-name>
'frontend-theme' => false,
// Read module views from /resources/views/asgard/<module-name>
'resources' => false,
],
]; ];
...@@ -98,4 +98,22 @@ return [ ...@@ -98,4 +98,22 @@ return [
| No custom sidebar: null | No custom sidebar: null
*/ */
'custom-sidebar' => null, 'custom-sidebar' => null,
/*
|--------------------------------------------------------------------------
| Load additional view namespaces for a module
|--------------------------------------------------------------------------
| You can specify place from which you would like to use module views.
| You can use any combination, but generally it's advisable to add only one,
| extra view namespace.
| By default every extra namespace will be set to false.
*/
'useViewNamespaces' => [
// Read module views from /Themes/<backend-theme-name>/views/modules/asgard/<module-name>
'backend-theme' => false,
// Read module views from /Themes/<frontend-theme-name>/views/modules/asgard/<module-name>
'frontend-theme' => false,
// Read module views from /resources/views/asgard/<module-name>
'resources' => true,
],
]; ];
...@@ -67,8 +67,6 @@ class UserServiceProvider extends ServiceProvider ...@@ -67,8 +67,6 @@ class UserServiceProvider extends ServiceProvider
$this->publishes([ $this->publishes([
__DIR__ . '/../Resources/views' => base_path('resources/views/asgard/user'), __DIR__ . '/../Resources/views' => base_path('resources/views/asgard/user'),
]); ]);
$this->loadViewsFrom(base_path('resources/views/asgard/user'), 'user');
$this->loadViewsFrom(__DIR__ . '/../Resources/views', 'user');
$this->publishConfig('user', 'permissions'); $this->publishConfig('user', 'permissions');
$this->publishConfig('user', 'config'); $this->publishConfig('user', 'config');
......
...@@ -10,4 +10,22 @@ return [ ...@@ -10,4 +10,22 @@ return [
| No custom sidebar: null | No custom sidebar: null
*/ */
'custom-sidebar' => null, 'custom-sidebar' => null,
/*
|--------------------------------------------------------------------------
| Load additional view namespaces for a module
|--------------------------------------------------------------------------
| You can specify place from which you would like to use module views.
| You can use any combination, but generally it's advisable to add only one,
| extra view namespace.
| By default every extra namespace will be set to false.
*/
'useViewNamespaces' => [
// Read module views from /Themes/<backend-theme-name>/views/modules/asgard/<module-name>
'backend-theme' => false,
// Read module views from /Themes/<frontend-theme-name>/views/modules/asgard/<module-name>
'frontend-theme' => false,
// Read module views from /resources/views/asgard/<module-name>
'resources' => false,
],
]; ];
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment