Added SASS support to Resources component (#2961)

This commit is contained in:
Benjamin 2017-07-11 01:29:11 +02:00 committed by Luke Towers
parent 2046efb51d
commit 89d0d29b69
1 changed files with 29 additions and 0 deletions

View File

@ -25,6 +25,11 @@ class Resources extends ComponentBase
*/
public $lessDir = 'less';
/**
* @var string The default SASS directory
*/
public $sassDir = 'sass';
/**
* @return array
*/
@ -54,6 +59,12 @@ class Resources extends ComponentBase
'type' => 'stringList',
'showExternalParam' => false
],
'sass' => [
'title' => 'SASS',
'description' => 'SASS file(s) in the assets/sass folder',
'type' => 'stringList',
'showExternalParam' => false
],
'css' => [
'title' => 'CSS',
'description' => 'Stylesheet file(s) in the assets/css folder',
@ -73,6 +84,7 @@ class Resources extends ComponentBase
{
$this->assetPath = $this->guessAssetPath();
$this->jsDir = $this->guessAssetDirectory(['js', 'javascript'], $this->jsDir);
$this->sassDir = $this->guessAssetDirectory(['sass', 'scss'], $this->sassDir);
}
public function onRun()
@ -93,6 +105,14 @@ class Resources extends ComponentBase
$less += array_map([$this, 'prefixLess'], (array) $assets);
}
/*
* SASS
*/
$sass = [];
if ($assets = $this->property('sass')) {
$sass += array_map([$this, 'prefixSass'], (array) $assets);
}
/*
* CSS
*/
@ -109,6 +129,10 @@ class Resources extends ComponentBase
$this->addCss(CombineAssets::combine($less, $this->assetPath));
}
if (count($sass)) {
$this->addCss(CombineAssets::combine($sass, $this->assetPath));
}
if (count($css)) {
$this->addCss(CombineAssets::combine($css, $this->assetPath));
}
@ -138,6 +162,11 @@ class Resources extends ComponentBase
return $this->lessDir.'/'.trim($value);
}
protected function prefixSass($value)
{
return $this->sassDir.'/'.trim($value);
}
protected function guessAssetDirectory(array $possible, $default = null)
{
foreach ($possible as $option) {