Commit ee2d93b1 by Qiang Xue

scripts WIP

parent 0416e014
...@@ -98,7 +98,7 @@ class ViewContent extends Component ...@@ -98,7 +98,7 @@ class ViewContent extends Component
$bundle = $this->assetManager->getBundle($name); $bundle = $this->assetManager->getBundle($name);
if ($bundle !== null) { if ($bundle !== null) {
$this->assetBundles[$name] = false; $this->assetBundles[$name] = false;
$bundle->registerWith($this); $bundle->registerAssets($this);
$this->assetBundles[$name] = true; $this->assetBundles[$name] = true;
} else { } else {
throw new InvalidConfigException("Unknown asset bundle: $name"); throw new InvalidConfigException("Unknown asset bundle: $name");
......
...@@ -42,10 +42,18 @@ class AssetBundle extends Object ...@@ -42,10 +42,18 @@ class AssetBundle extends Object
public $css = array(); public $css = array();
public $depends = array(); public $depends = array();
public function mapTo($target)
{
$this->depends = array($target);
$this->js = $this->css = array();
$this->basePath = null;
$this->baseUrl = null;
}
/** /**
* @param \yii\base\ViewContent $content * @param \yii\base\ViewContent $content
*/ */
public function registerWith($content) public function registerAssets($content)
{ {
foreach ($this->depends as $name) { foreach ($this->depends as $name) {
$content->registerAssetBundle($name); $content->registerAssetBundle($name);
...@@ -65,4 +73,14 @@ class AssetBundle extends Object ...@@ -65,4 +73,14 @@ class AssetBundle extends Object
} }
} }
} }
/**
* @param \yii\web\AssetManager $assetManager
*/
public function publish($assetManager)
{
if ($this->basePath !== null && $this->baseUrl === null) {
return;
}
}
} }
\ No newline at end of file
...@@ -129,9 +129,23 @@ class AssetManager extends Component ...@@ -129,9 +129,23 @@ class AssetManager extends Component
$this->bundles[$name] = Yii::createObject($config); $this->bundles[$name] = Yii::createObject($config);
} }
} }
/** @var $bundle AssetBundle */
$bundle = $this->bundles[$name];
if (isset($this->bundleMap[$name]) && is_string($this->bundleMap[$name])) {
$target = $this->bundleMap[$name];
if (!isset($this->bundles[$target])) {
if (isset($this->bundleMap[$target])) {
$this->bundles[$target] = $this->bundleMap[$target];
} else {
throw new InvalidConfigException("Asset bundle '$name' is mapped to an unknown bundle: $target");
}
}
$bundle->mapTo($target);
unset($this->bundleMap[$name]);
}
if ($publish) { if ($publish) {
$bundle->publish($this);
} }
return $this->bundles[$name]; return $this->bundles[$name];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment