Browse Source

...

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
82535b254d
  1. 33
      framework/web/AssetBundle.php

33
framework/web/AssetBundle.php

@ -17,14 +17,21 @@ use yii\base\Object;
class AssetBundle extends Object class AssetBundle extends Object
{ {
/** /**
* @var string the root directory of the asset files. If this is not set, * @var string the root directory of the source asset files. If this is set,
* the assets are considered to be located under a Web-accessible folder already * the source asset files will be published to [[basePath]] when the bundle
* and no asset publishing will be performed. * is being used the first time.
*/
public $sourcePath;
/**
* @var string the root directory of the public asset files. If this is not set
* while [[sourcePath]] is set, a default value will be set by [[AssetManager]]
* when it publishes the source asset files. If you set this property, please
* make sure the directory is Web accessible.
*/ */
public $basePath; public $basePath;
/** /**
* @var string the base URL that will be prefixed to the asset files. * @var string the base URL that will be prefixed to the asset files.
* This property must be set if [[basePath]] is not set. * This property must be set if you set [[basePath]] explicitly.
* When this property is not set, it will be initialized as the base URL * When this property is not set, it will be initialized as the base URL
* that the assets are published to. * that the assets are published to.
*/ */
@ -33,12 +40,11 @@ class AssetBundle extends Object
* @var array list of JavaScript files that this bundle contains. Each JavaScript file can * @var array list of JavaScript files that this bundle contains. Each JavaScript file can
* be specified in one of the three formats: * be specified in one of the three formats:
* *
* - a relative path: a path relative to [[basePath]] if [[basePath]] is set, * - a relative file path: a path relative to [[basePath]];,
* or a URL relative to [[baseUrl]] if [[basePath]] is not set;
* - an absolute URL; * - an absolute URL;
* - a path alias that can be resolved into a relative path or an absolute URL. * - a path alias that can be resolved into a relative path or an absolute URL.
* *
* Note that you should not use backward slashes "\" to specify JavaScript files. * Note that only forward slashes "/" should be used as directory separators.
* *
* Each JavaScript file may be associated with options. In this case, the array key * Each JavaScript file may be associated with options. In this case, the array key
* should be the JavaScript file path, while the corresponding array value should * should be the JavaScript file path, while the corresponding array value should
@ -49,12 +55,11 @@ class AssetBundle extends Object
* @var array list of CSS files that this bundle contains. Each CSS file can * @var array list of CSS files that this bundle contains. Each CSS file can
* be specified in one of the three formats: * be specified in one of the three formats:
* *
* - a relative path: a path relative to [[basePath]] if [[basePath]] is set, * - a relative file path: a path relative to [[basePath]];,
* or a URL relative to [[baseUrl]] if [[basePath]] is not set;
* - an absolute URL; * - an absolute URL;
* - a path alias that can be resolved into a relative path or an absolute URL. * - a path alias that can be resolved into a relative path or an absolute URL.
* *
* Note that you should not use backward slashes "\" to specify CSS files. * Note that only forward slashes "/" should be used as directory separators.
* *
* Each CSS file may be associated with options. In this case, the array key * Each CSS file may be associated with options. In this case, the array key
* should be the CSS file path, while the corresponding array value should * should be the CSS file path, while the corresponding array value should
@ -71,8 +76,8 @@ class AssetBundle extends Object
if ($this->baseUrl !== null) { if ($this->baseUrl !== null) {
$this->baseUrl = rtrim(Yii::getAlias($this->baseUrl), '/'); $this->baseUrl = rtrim(Yii::getAlias($this->baseUrl), '/');
} }
if ($this->basePath !== null) { if ($this->sourcePath !== null) {
$this->basePath = rtrim(Yii::getAlias($this->basePath), '/\\'); $this->sourcePath = rtrim(Yii::getAlias($this->sourcePath), '/\\');
} }
} }
@ -105,8 +110,8 @@ class AssetBundle extends Object
*/ */
public function publish($assetManager) public function publish($assetManager)
{ {
if ($this->basePath !== null) { if ($this->sourcePath !== null) {
$baseUrl = $assetManager->publish($this->basePath); $baseUrl = $assetManager->publish($this->sourcePath);
if ($this->baseUrl === null) { if ($this->baseUrl === null) {
$this->baseUrl = $baseUrl; $this->baseUrl = $baseUrl;
} }

Loading…
Cancel
Save