Browse Source

scripts WIP

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
ee2d93b181
  1. 2
      framework/base/ViewContent.php
  2. 20
      framework/web/AssetBundle.php
  3. 16
      framework/web/AssetManager.php

2
framework/base/ViewContent.php

@ -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");

20
framework/web/AssetBundle.php

@ -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
} }
} }
} }
/**
* @param \yii\web\AssetManager $assetManager
*/
public function publish($assetManager)
{
if ($this->basePath !== null && $this->baseUrl === null) {
return;
}
}
} }

16
framework/web/AssetManager.php

@ -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];

Loading…
Cancel
Save