mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-15 22:09:48 +08:00
Allow setting css options per CSS file in AssetBundle::, fixes #10158
This commit is contained in:
@@ -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 #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)
|
- Chg #9953: `TimestampBehavior::getValue()` changed to make value processing consistent with `AttributeBehavior::getValue()` (silverfire)
|
||||||
- New #10083: Added wrapper for PHP webserver (samdark)
|
- 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
|
2.0.6 August 05, 2015
|
||||||
---------------------
|
---------------------
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
namespace yii\web;
|
namespace yii\web;
|
||||||
|
|
||||||
use yii\base\Object;
|
use yii\base\Object;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
use yii\helpers\Url;
|
use yii\helpers\Url;
|
||||||
use Yii;
|
use Yii;
|
||||||
|
|
||||||
@@ -86,8 +87,12 @@ class AssetBundle extends Object
|
|||||||
*/
|
*/
|
||||||
public $js = [];
|
public $js = [];
|
||||||
/**
|
/**
|
||||||
* @var array list of CSS files that this bundle contains. Each CSS file can be specified
|
* @var array list of CSS files that this bundle contains. Each CSS file can be specified in one
|
||||||
* in one of the three formats as explained in [[js]].
|
* 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.
|
* 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);
|
$view->registerJsFile($manager->getAssetUrl($this, $js), $this->jsOptions);
|
||||||
}
|
}
|
||||||
foreach ($this->css as $css) {
|
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) {
|
foreach ($this->css as $i => $css) {
|
||||||
if (Url::isRelative($css)) {
|
$css = ArrayHelper::toArray($css);
|
||||||
$this->css[$i] = $converter->convert($css, $this->basePath);
|
$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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,6 +201,21 @@ EOF;
|
|||||||
|
|
||||||
$expected = <<<EOF
|
$expected = <<<EOF
|
||||||
123<script src="/js/jquery.js"></script>4
|
123<script src="/js/jquery.js"></script>4
|
||||||
|
EOF;
|
||||||
|
$this->assertEquals($expected, $view->renderFile('@yiiunit/data/views/rawlayout.php'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCssOptions()
|
||||||
|
{
|
||||||
|
$view = $this->getView();
|
||||||
|
|
||||||
|
$this->assertEmpty($view->assetBundles);
|
||||||
|
TestAssetCssOptions::register($view);
|
||||||
|
|
||||||
|
$expected = <<<EOF
|
||||||
|
1<link href="/js/default_options.css" rel="stylesheet" media="screen" hreflang="en">
|
||||||
|
<link href="/js/tv.css" rel="stylesheet" media="tv" hreflang="en">
|
||||||
|
<link href="/js/screen_and_print.css" rel="stylesheet" media="screen, print" hreflang="en">234
|
||||||
EOF;
|
EOF;
|
||||||
$this->assertEquals($expected, $view->renderFile('@yiiunit/data/views/rawlayout.php'));
|
$this->assertEquals($expected, $view->renderFile('@yiiunit/data/views/rawlayout.php'));
|
||||||
}
|
}
|
||||||
@@ -271,3 +286,15 @@ class TestAssetCircleB extends AssetBundle
|
|||||||
'yiiunit\\framework\\web\\TestAssetCircleA'
|
'yiiunit\\framework\\web\\TestAssetCircleA'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TestAssetCssOptions extends AssetBundle
|
||||||
|
{
|
||||||
|
public $basePath = '@testWebRoot/js';
|
||||||
|
public $baseUrl = '@testWeb/js';
|
||||||
|
public $css = [
|
||||||
|
'default_options.css',
|
||||||
|
['tv.css', 'media' => 'tv'],
|
||||||
|
['screen_and_print.css', 'media' => 'screen, print']
|
||||||
|
];
|
||||||
|
public $cssOptions = ['media' => 'screen', 'hreflang' => 'en'];
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user