Skip to content

Commit

Permalink
Merge pull request #194 from QTSdev/master
Browse files Browse the repository at this point in the history
Add a filter for JShrinkFilter.

Adds a php based minifier for javascript files.
  • Loading branch information
markstory committed Feb 22, 2014
2 parents c1870c2 + 7c4b680 commit d496744
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Lib/Filter/JShrinkFilter.php
@@ -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']));
}

}

0 comments on commit d496744

Please sign in to comment.