Skip to content
Snippets Groups Projects
Commit b9e0f4e0 authored by Chris Hallberg's avatar Chris Hallberg
Browse files

LESS active inheritance and simplification.

parent eba852b9
No related merge requests found
...@@ -327,6 +327,18 @@ class Initializer ...@@ -327,6 +327,18 @@ class Initializer
$resources->setGenerator($this->config->generator); $resources->setGenerator($this->config->generator);
} }
$lessActive = false;
$scssActive = false;
// Find LESS activity
foreach ($themes as $key=>$currentThemeInfo) {
if (isset($currentThemeInfo['less']['active'])) {
$lessActive = $currentThemeInfo['less']['active'];
}
if (isset($currentThemeInfo['scss']['active'])) {
$scssActive = $currentThemeInfo['scss']['active'];
}
}
// Apply the loaded theme settings in reverse for proper inheritance: // Apply the loaded theme settings in reverse for proper inheritance:
foreach ($themes as $key=>$currentThemeInfo) { foreach ($themes as $key=>$currentThemeInfo) {
if (isset($currentThemeInfo['helpers'])) { if (isset($currentThemeInfo['helpers'])) {
...@@ -337,10 +349,10 @@ class Initializer ...@@ -337,10 +349,10 @@ class Initializer
$templatePathStack[] = $this->tools->getBaseDir() . "/$key/templates"; $templatePathStack[] = $this->tools->getBaseDir() . "/$key/templates";
// Add CSS and JS dependencies: // Add CSS and JS dependencies:
if (isset($currentThemeInfo['less'])) { if ($lessActive && isset($currentThemeInfo['less'])) {
$resources->addLessCss($currentThemeInfo['less']); $resources->addLessCss($currentThemeInfo['less']);
} }
if (isset($currentThemeInfo['scss'])) { if ($scssActive && isset($currentThemeInfo['scss'])) {
$resources->addScssCss($currentThemeInfo['scss']); $resources->addScssCss($currentThemeInfo['scss']);
} }
if (isset($currentThemeInfo['css'])) { if (isset($currentThemeInfo['css'])) {
......
...@@ -44,12 +44,6 @@ class ResourceContainer ...@@ -44,12 +44,6 @@ class ResourceContainer
* @var array * @var array
*/ */
protected $less = array(); protected $less = array();
/**
* Less CSS active boolean
*
* @var array
*/
protected $lessActive = false;
/** /**
* scss CSS files * scss CSS files
...@@ -57,12 +51,6 @@ class ResourceContainer ...@@ -57,12 +51,6 @@ class ResourceContainer
* @var array * @var array
*/ */
protected $scss = array(); protected $scss = array();
/**
* SCSS CSS active boolean
*
* @var array
*/
protected $scssActive = false;
/** /**
* CSS files * CSS files
...@@ -111,13 +99,10 @@ class ResourceContainer ...@@ -111,13 +99,10 @@ class ResourceContainer
if (!is_array($less) && !is_a($less, 'Traversable')) { if (!is_array($less) && !is_a($less, 'Traversable')) {
$less = array($less); $less = array($less);
} }
$this->lessActive = !isset($less['active']) || $less['active'] === true; unset($less['active']);
if ($this->lessActive) { foreach ($less as $index=>$current) {
unset($less['active']); $this->less[$index] = $current;
foreach ($less as $index=>$current) { $this->removeCSS($current);
$this->less[$index] = $current;
$this->removeCSS($current);
}
} }
} }
...@@ -133,13 +118,10 @@ class ResourceContainer ...@@ -133,13 +118,10 @@ class ResourceContainer
if (!is_array($scss) && !is_a($scss, 'Traversable')) { if (!is_array($scss) && !is_a($scss, 'Traversable')) {
$scss = array($scss); $scss = array($scss);
} }
$this->scssActive = !isset($scss['active']) || $scss['active'] === true; unset($scss['active']);
if ($this->scssActive) { foreach ($scss as $index=>$current) {
unset($scss['active']); $this->scss[$index] = $current;
foreach ($scss as $index=>$current) { $this->removeCSS($current);
$this->scss[$index] = $current;
$this->removeCSS($current);
}
} }
} }
...@@ -157,7 +139,7 @@ class ResourceContainer ...@@ -157,7 +139,7 @@ class ResourceContainer
$css = array($css); $css = array($css);
} }
foreach ($css as $current) { foreach ($css as $current) {
if (!$this->activeInLess($current) && !$this->activeInScss($current)) { if (!$this->dynamicallyParsed($current)) {
$this->css[] = $current; $this->css[] = $current;
} }
} }
...@@ -291,29 +273,15 @@ class ResourceContainer ...@@ -291,29 +273,15 @@ class ResourceContainer
* *
* @return boolean * @return boolean
*/ */
private function activeInLess($file) private function dynamicallyParsed($file)
{
if (empty($this->less) || $this->lessActive === false) {
return false;
}
list($lessFile,) = explode('.', $file);
$lessFile .= '.less';
return in_array($lessFile, $this->less, true) ? true : false;
}
/**
* Check if a CSS file is being dynamically compiled in SCSS
*
* @return boolean
*/
private function activeInScss($file)
{ {
if (empty($this->scss) || $this->scssActive === false) { if (empty($this->less)) {
return false; return false;
} }
list($scssFile,) = explode('.', $file); list($fileName,) = explode('.', $file);
$scssFile .= '.scss'; $lessFile = $fileName . '.less';
return in_array($scssFile, $this->scss, true) ? true : false; $scssFile = $fileName . '.scss';
return in_array($lessFile, $this->less, true) || in_array($scssFile, $this->scss, true);
} }
/** /**
......
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