/**
* Converts a given asset file into a CSS or JS file.
* @param string $asset the asset file path, relative to $basePath
* @param string $basePath the directory the $asset is relative to.
* @return string the converted asset file path, relative to $basePath.
*/
public function convert($asset, $basePath)
{
$pos = strrpos($asset, '.');
if ($pos === false) {
return parent::convert($asset, $basePath);
}
$ext = substr($asset, $pos + 1);
if (!isset($this->parsers[$ext])) {
return parent::convert($asset, $basePath);
}
$parserConfig = ArrayHelper::merge($this->defaultParsersOptions[$ext], $this->parsers[$ext]);
$this->destinationDir = $this->destinationDir ? trim($this->destinationDir, '/') : '';
$resultFile = strlen($this->destinationDir) > 0 ? $this->destinationDir . '/' : '' . ltrim(substr($asset, 0, $pos + 1), '/') . $parserConfig['output'];
$from = $basePath . '/' . ltrim($asset, '/');
$to = $basePath . '/' . $resultFile;
if (!$this->needRecompile($from, $to) && !$this->force) {
return $resultFile;
}
$this->checkDestinationDir($basePath, $resultFile);
$parser = new $parserConfig['class']($parserConfig['options']);
$parserOptions = isset($parserConfig['options']) ? $parserConfig['options'] : array();
$parser->parse($from, $to, $parserOptions);
if (YII_DEBUG) {
Yii::info("Converted {$asset} into {$resultFile} ", __CLASS__);
}
return $resultFile;
}