mirror of
https://github.com/a2nt/silverstripe-webpack.git
synced 2024-10-22 17:05:31 +02:00
Themed requirements loading
This commit is contained in:
parent
8429a6739a
commit
4231243674
@ -36,7 +36,8 @@ class DeferedRequirements implements TemplateGlobalProvider
|
|||||||
public static function Auto($class = false)
|
public static function Auto($class = false)
|
||||||
{
|
{
|
||||||
$config = Config::inst()->get(self::class);
|
$config = Config::inst()->get(self::class);
|
||||||
$themeName = WebpackTemplateProvider::themeName();
|
$projectName = WebpackTemplateProvider::projectName();
|
||||||
|
$mainTheme = WebpackTemplateProvider::mainTheme();
|
||||||
|
|
||||||
// Initialization
|
// Initialization
|
||||||
Requirements::block(THIRDPARTY_DIR.'/jquery/jquery.js');
|
Requirements::block(THIRDPARTY_DIR.'/jquery/jquery.js');
|
||||||
@ -53,10 +54,10 @@ class DeferedRequirements implements TemplateGlobalProvider
|
|||||||
if (!$config['nofontawesome']) {
|
if (!$config['nofontawesome']) {
|
||||||
DeferedRequirements::loadCSS('//use.fontawesome.com/releases/v5.4.0/css/all.css');
|
DeferedRequirements::loadCSS('//use.fontawesome.com/releases/v5.4.0/css/all.css');
|
||||||
}
|
}
|
||||||
DeferedRequirements::loadCSS($themeName.'.css');
|
DeferedRequirements::loadCSS($mainTheme.'.css');
|
||||||
DeferedRequirements::loadJS($themeName.'.js');
|
DeferedRequirements::loadJS($mainTheme.'.js');
|
||||||
|
|
||||||
// Class libs
|
// Custom controller requirements
|
||||||
$class = get_class(Controller::curr());
|
$class = get_class(Controller::curr());
|
||||||
if (isset($config['custom_requirements'][$class])) {
|
if (isset($config['custom_requirements'][$class])) {
|
||||||
foreach ($config['custom_requirements'][$class] as $file) {
|
foreach ($config['custom_requirements'][$class] as $file) {
|
||||||
@ -73,17 +74,26 @@ class DeferedRequirements implements TemplateGlobalProvider
|
|||||||
$dir = Path::join(
|
$dir = Path::join(
|
||||||
Director::publicFolder(),
|
Director::publicFolder(),
|
||||||
ManifestFileFinder::RESOURCES_DIR,
|
ManifestFileFinder::RESOURCES_DIR,
|
||||||
$themeName,
|
$projectName,
|
||||||
'client',
|
'client',
|
||||||
'dist'
|
'dist'
|
||||||
);
|
);
|
||||||
|
|
||||||
if (file_exists(Path::join($dir, 'css', $themeName.'_'.$class . '.css'))) {
|
// Controller requirements
|
||||||
DeferedRequirements::loadCSS($themeName.'_'.$class . '.css');
|
$themePath = Path::join($dir, 'css', $mainTheme.'_'.$class . '.css');
|
||||||
|
$projectPath = Path::join($dir, 'css', $projectName.'_'.$class . '.css');
|
||||||
|
if ($mainTheme && file_exists($themePath)){
|
||||||
|
DeferedRequirements::loadCSS($mainTheme.'_'.$class . '.css');
|
||||||
|
} else if (file_exists($projectPath)) {
|
||||||
|
DeferedRequirements::loadCSS($projectName.'_'.$class . '.css');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_exists(Path::join($dir, 'js', $themeName.'_'.$class . '.js'))) {
|
$themePath = Path::join($dir, 'js', $mainTheme.'_'.$class . '.js');
|
||||||
DeferedRequirements::loadJS($themeName.'_'.$class . '.js');
|
$projectPath = Path::join($dir, 'js', $projectName.'_'.$class . '.js');
|
||||||
|
if ($mainTheme && file_exists($themePath)){
|
||||||
|
DeferedRequirements::loadJS($mainTheme.'_'.$class . '.js');
|
||||||
|
} else if (file_exists($projectPath)) {
|
||||||
|
DeferedRequirements::loadJS($projectName.'_'.$class . '.js');
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::forTemplate();
|
return self::forTemplate();
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
namespace Site\Templates;
|
namespace Site\Templates;
|
||||||
|
|
||||||
use SilverStripe\Core\Manifest\ModuleManifest;
|
use SilverStripe\Core\Manifest\ModuleManifest;
|
||||||
|
use SilverStripe\View\SSViewer;
|
||||||
use SilverStripe\View\TemplateGlobalProvider;
|
use SilverStripe\View\TemplateGlobalProvider;
|
||||||
use SilverStripe\View\Requirements;
|
use SilverStripe\View\Requirements;
|
||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Control\Director;
|
||||||
@ -66,14 +67,20 @@ class WebpackTemplateProvider implements TemplateGlobalProvider
|
|||||||
Requirements::javascript(self::_getPath($path));
|
Requirements::javascript(self::_getPath($path));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function themeName()
|
public static function projectName()
|
||||||
{
|
{
|
||||||
return Config::inst()->get(ModuleManifest::class, 'project');
|
return Config::inst()->get(ModuleManifest::class, 'project');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function mainTheme()
|
||||||
|
{
|
||||||
|
$themes = Config::inst()->get(SSViewer::class, 'themes');
|
||||||
|
return is_array($themes) && $themes[0] !== '$public' && $themes[0] !== '$default' ? $themes[0] : false;
|
||||||
|
}
|
||||||
|
|
||||||
public static function resourcesURL($link = null)
|
public static function resourcesURL($link = null)
|
||||||
{
|
{
|
||||||
return Controller::join_links(Director::baseURL(), '/resources/'.self::themeName().'/client/dist/img/', $link);
|
return Controller::join_links(Director::baseURL(), '/resources/'.self::projectName().'/client/dist/img/', $link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -111,7 +118,7 @@ class WebpackTemplateProvider implements TemplateGlobalProvider
|
|||||||
{
|
{
|
||||||
return strpos($path, '//') === false ?
|
return strpos($path, '//') === false ?
|
||||||
Controller::join_links(
|
Controller::join_links(
|
||||||
self::themeName(),
|
self::projectName(),
|
||||||
Config::inst()->get(__CLASS__, 'DIST'),
|
Config::inst()->get(__CLASS__, 'DIST'),
|
||||||
(strpos($path, '.css') ? 'css' : 'js'),
|
(strpos($path, '.css') ? 'css' : 'js'),
|
||||||
$path
|
$path
|
||||||
|
Loading…
Reference in New Issue
Block a user