Allow setting css options per CSS file in AssetBundle::, fixes #10158

This commit is contained in:
Mehdi Achour
2015-11-16 15:12:14 +01:00
parent 61acf28338
commit 5619e98eda
3 changed files with 45 additions and 5 deletions

View File

@@ -62,6 +62,7 @@ Yii Framework 2 Change Log
- Chg #9411: `DetailView` now automatically sets container tag ID in case it's not specified (samdark)
- Chg #9953: `TimestampBehavior::getValue()` changed to make value processing consistent with `AttributeBehavior::getValue()` (silverfire)
- New #10083: Added wrapper for PHP webserver (samdark)
- Enh #10158: Added the possibility to specify CSS options per file in `AssetBundle::$css` (machour)
2.0.6 August 05, 2015
---------------------

View File

@@ -8,6 +8,7 @@
namespace yii\web;
use yii\base\Object;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use Yii;
@@ -86,8 +87,12 @@ class AssetBundle extends Object
*/
public $js = [];
/**
* @var array list of CSS files that this bundle contains. Each CSS file can be specified
* in one of the three formats as explained in [[js]].
* @var array list of CSS files that this bundle contains. Each CSS file can be specified in one
* of the following formats:
*
* - a string, with an absolute URL or a relative path, as explained in [[js]].
* - an array, with a first entry being the URL or relative path, and a list of key => pair values
* that will be used to overwrite [[cssOptions]] settings.
*
* Note that only forward slash "/" can be used as directory separator.
*/
@@ -147,7 +152,10 @@ class AssetBundle extends Object
$view->registerJsFile($manager->getAssetUrl($this, $js), $this->jsOptions);
}
foreach ($this->css as $css) {
$view->registerCssFile($manager->getAssetUrl($this, $css), $this->cssOptions);
$css = ArrayHelper::toArray($css);
$file = array_shift($css);
$options = ArrayHelper::merge($this->cssOptions, $css);
$view->registerCssFile($manager->getAssetUrl($this, $file), $options);
}
}
@@ -170,8 +178,12 @@ class AssetBundle extends Object
}
}
foreach ($this->css as $i => $css) {
if (Url::isRelative($css)) {
$this->css[$i] = $converter->convert($css, $this->basePath);
$css = ArrayHelper::toArray($css);
$file = array_shift($css);
if (Url::isRelative($file)) {
$css = ArrayHelper::merge($this->cssOptions, $css);
array_unshift($css, $converter->convert($file, $this->basePath));
$this->css[$i] = $css;
}
}
}