Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #194 from QTSdev/master
Add a filter for JShrinkFilter. Adds a php based minifier for javascript files.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
App::uses('AssetFilter', 'AssetCompress.Lib'); | ||
|
||
/** | ||
* JShrink filter. | ||
* | ||
* Allows you to minify Javascript files through JShrink. | ||
* JShrink can be downloaded at https://github.com/tedivm/JShrink. | ||
* You need to put Minifier.php in your vendors jshrink folder. | ||
* | ||
*/ | ||
class JShrinkFilter extends AssetFilter { | ||
|
||
/** | ||
* Settings for JShrink minifier. | ||
* | ||
* @var array | ||
*/ | ||
protected $_settings = array( | ||
'path' => 'jshrink/Minifier.php', | ||
'flaggedComments' => true, | ||
); | ||
|
||
/** | ||
* Apply JShrink to $content. | ||
* | ||
* @param string $filename target filename | ||
* @param string $content Content to filter. | ||
* @throws Exception | ||
* @return string | ||
*/ | ||
public function output($filename, $content) { | ||
App::import('Vendor', 'Minifier', array('file' => $this->_settings['path'])); | ||
if (!class_exists('JShrink\Minifier')) { | ||
throw new Exception(sprintf('Cannot not load filter class "%s".', 'JShrink\Minifier')); | ||
} | ||
return JShrink\Minifier::minify($content, array('flaggedComments' => $this->_settings['flaggedComments'])); | ||
} | ||
|
||
} | ||
|