mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
NEW: themedCSS() and themedJavascript() work with any file layout.
themedCSS() and themedJavascript() files have previously been hardcoded to reside in the css/ or javascript/ folder directly beneath the theme path. This short-cut still works, but you can also specify the theme-relative path in its entirely, giving you more flexibility about your resource layout.
This commit is contained in:
parent
61d7c3af28
commit
96126323d2
@ -219,24 +219,19 @@ class ThemeResourceLoader {
|
|||||||
* @param array $themes List of themes
|
* @param array $themes List of themes
|
||||||
* @return string Path to resolved CSS file (relative to base dir)
|
* @return string Path to resolved CSS file (relative to base dir)
|
||||||
*/
|
*/
|
||||||
public function findThemedCSS($name, $themes)
|
public function findThemedCSS($name, $themes) {
|
||||||
{
|
if(substr($name, -4) !== '.css') $name .= '.css';
|
||||||
$css = "/css/$name.css";
|
|
||||||
$paths = $this->getThemePaths($themes);
|
|
||||||
foreach ($paths as $themePath) {
|
|
||||||
$abspath = $this->base . '/' . $themePath;
|
|
||||||
|
|
||||||
if (file_exists($abspath . $css)) {
|
$filename = $this->findThemedResource("css/$name", $themes);
|
||||||
return $themePath . $css;
|
if($filename === null) {
|
||||||
}
|
$filename = $this->findThemedResource($name, $themes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CSS exists in no context
|
return $filename;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers the given themeable javascript as required.
|
* Resolve themed javascript path
|
||||||
*
|
*
|
||||||
* A javascript file in the current theme path name 'themename/javascript/$name.js' is first searched for,
|
* A javascript file in the current theme path name 'themename/javascript/$name.js' is first searched for,
|
||||||
* and it that doesn't exist and the module parameter is set then a javascript file with that name in
|
* and it that doesn't exist and the module parameter is set then a javascript file with that name in
|
||||||
@ -247,17 +242,40 @@ class ThemeResourceLoader {
|
|||||||
* @return string Path to resolved javascript file (relative to base dir)
|
* @return string Path to resolved javascript file (relative to base dir)
|
||||||
*/
|
*/
|
||||||
public function findThemedJavascript($name, $themes) {
|
public function findThemedJavascript($name, $themes) {
|
||||||
$js = "/javascript/$name.js";
|
if(substr($name, -3) !== '.js') $name .= '.js';
|
||||||
|
|
||||||
|
$filename = $this->findThemedResource("javascript/$name", $themes);
|
||||||
|
if($filename === null) {
|
||||||
|
$filename = $this->findThemedResource($name, $themes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve a themed resource
|
||||||
|
*
|
||||||
|
* A themed resource and be any file that resides in a theme folder.
|
||||||
|
*
|
||||||
|
* @param string $resource A file path relative to the root folder of a theme
|
||||||
|
* @param array $themes An order listed of themes to search
|
||||||
|
*/
|
||||||
|
public function findThemedResource($resource, $themes)
|
||||||
|
{
|
||||||
|
if($resource[0] !== '/') {
|
||||||
|
$resource = '/' . $resource;
|
||||||
|
}
|
||||||
|
|
||||||
$paths = $this->getThemePaths($themes);
|
$paths = $this->getThemePaths($themes);
|
||||||
|
|
||||||
foreach ($paths as $themePath) {
|
foreach ($paths as $themePath) {
|
||||||
$abspath = $this->base . '/' . $themePath;
|
$abspath = $this->base . '/' . $themePath;
|
||||||
|
if (file_exists($abspath . $resource)) {
|
||||||
if (file_exists($abspath . $js)) {
|
return $themePath . $resource;
|
||||||
return $themePath . $js;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// js exists in no context
|
// Resource exists in no context
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user