Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions PackageCompressor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class PackageCompressor extends CClientScript
*/
public $combineOnly = false;

/**
* Only effective when $enableCompression is set to "true"
*
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to copyCssAssets. I'd also change the docs to:

Whether to copy CSS assets from their source location to the package output directory. Note, that this
feature is considered experimental. It will copy all files from the CSS files' source directory to the
package output directory which may not always lead to useful results.

* @var bool wheter to rewrite URLs in CSS files to an absolute path before combining
*/
public $rewriteCssUris = false;

/**
* If this is enabled, during compression all other requests will wait until the compressing
* process has completed. If disabled, the uncompressed files will be delivered for these
Expand Down Expand Up @@ -84,7 +91,7 @@ public function compressPackage($name)

$info = array();
$am = Yii::app()->assetManager;
$basePath = Yii::getPathOfAlias('webroot');
$basePath = realpath(Yii::getPathOfAlias('webroot'));

// /www/root/sub -> /www/root (baseUrl=/sub)
if(($baseUrl = Yii::app()->request->baseUrl)!=='')
Expand Down Expand Up @@ -126,8 +133,17 @@ public function compressPackage($name)
{
$files = array();
$urls = array();
foreach(array_keys($this->cssFiles) as $file)
$files[] = $basePath.$file;

foreach(array_keys($this->cssFiles) as $file) {
if ($this->rewriteCssUris) {
$inFile = $basePath.$file;
$outFile = $basePath.$file.'-rewrite.css';
file_put_contents($outFile, Minify_CSS_UriRewriter::rewrite(file_get_contents($inFile), dirname($inFile), $basePath));
} else {
$outFile = $basePath.$file;
}
$files[] = $outFile;
}

$fileName = $this->compressFiles($name,'css',$files);
if(isset($this->packages[$name]['baseUrl']))
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
}
],
"require": {
"php": ">=5.0.0"
"php": ">=5.0.0",
"mrclay/minify": "2.1.*"
}
}