From 1f47ea9781fd85dc08bcae78da924c6996f12e90 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Thu, 18 Apr 2013 15:55:28 -0400 Subject: [PATCH] Added asset processor concept. --- framework/web/AssetManager.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/framework/web/AssetManager.php b/framework/web/AssetManager.php index 5375d08..72dd06b 100644 --- a/framework/web/AssetManager.php +++ b/framework/web/AssetManager.php @@ -26,6 +26,13 @@ class AssetManager extends Component */ public $bundles; /** + * @var array list of asset processors. An asset processor will convert a special type of asset files + * (e.g. LESS, Sass, TypeScript) into JS or CSS files. The array keys are the file extension names + * (e.g. "less", "sass", "ts"), and the array values are the corresponding configuration arrays + * for creating the processor objects. + */ + public $processors; + /** * @return string the root directory storing the published asset files. */ public $basePath = '@wwwroot/assets'; @@ -143,7 +150,15 @@ class AssetManager extends Component */ public function processAsset($asset, $basePath, $baseUrl) { - return $baseUrl . '/' . $asset; + $ext = pathinfo($asset, PATHINFO_EXTENSION); + if (isset($this->processors[$ext])) { + if (is_array($this->processors[$ext])) { + $this->processors[$ext] = Yii::createObject($this->processors[$ext]); + } + return $this->processors[$ext]->process($asset, $basePath, $baseUrl); + } else { + return $baseUrl . '/' . $asset; + } } /**