Skip to content

Commit

Permalink
Added SASS support to Resources component (octobercms#2961)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaVR authored and LukeTowers committed Jul 10, 2017
1 parent 2046efb commit 89d0d29
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions modules/cms/components/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class Resources extends ComponentBase
*/
public $lessDir = 'less';

/**
* @var string The default SASS directory
*/
public $sassDir = 'sass';

/**
* @return array
*/
Expand Down Expand Up @@ -54,6 +59,12 @@ public function defineProperties()
'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',
Expand All @@ -73,6 +84,7 @@ public function init()
{
$this->assetPath = $this->guessAssetPath();
$this->jsDir = $this->guessAssetDirectory(['js', 'javascript'], $this->jsDir);
$this->sassDir = $this->guessAssetDirectory(['sass', 'scss'], $this->sassDir);
}

public function onRun()
Expand All @@ -93,6 +105,14 @@ public function onRun()
$less += array_map([$this, 'prefixLess'], (array) $assets);
}

/*
* SASS
*/
$sass = [];
if ($assets = $this->property('sass')) {
$sass += array_map([$this, 'prefixSass'], (array) $assets);
}

/*
* CSS
*/
Expand All @@ -109,6 +129,10 @@ public function onRun()
$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));
}
Expand Down Expand Up @@ -138,6 +162,11 @@ protected function prefixLess($value)
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) {
Expand Down

0 comments on commit 89d0d29

Please sign in to comment.