Permalink
Browse files

Added in Dean Edwards' JavaScript Packer

  • Loading branch information...
meenie committed Mar 24, 2013
1 parent fee17af commit 5a646e544191cb9a9347eb5b2b2ad716f9261c10
Showing with 77 additions and 2 deletions.
  1. +14 −2 composer.json
  2. +63 −0 src/Munee/Asset/Filter/JavaScript/Packer.php
View
@@ -23,6 +23,18 @@
"leafo/scssphp": "*",
"tedivm/jshrink": "*",
"imagine/Imagine": "*",
"coffeescript/coffeescript": "1.3.*"
}
"coffeescript/coffeescript": "*",
"joliclic/javascript-packer": "*"
},
"repositories": [
{
"type": "package",
"package": {
"name": "joliclic/javascript-packer",
"version": "1.1",
"dist": { "url": "http://joliclic.free.fr/php/javascript-packer/telechargement.php?id=2&action=telecharger", "type": "zip" },
"autoload": { "classmap": [ "class.JavaScriptPacker.php" ] }
}
}
]
}
@@ -0,0 +1,63 @@
<?php
/**
* Munee: Optimising Your Assets
*
* @copyright Cody Lundquist 2013
* @license http://opensource.org/licenses/mit-license.php
*/
namespace Munee\Asset\Filter\JavaScript;
use Munee\Asset\Filter;
use \JavaScriptPacker;
/**
* Dean Edwards' Packer Filter for JavaScript
*
* @author Cody Lundquist
*/
class Packer extends Filter
{
/**
* @var array
*/
protected $_allowedParams = array(
'packer' => array(
'regex' => 'true|false|t|f|yes|no|y|n',
'default' => 'false',
'cast' => 'boolean'
)
);
/**
* @var array
*/
protected $_defaultOptions = array(
'encoding' => 62,
'fastDecode' => true,
'specialChars' => false
);
/**
* JavaScript Packer
*
* @param string $file
* @param array $arguments
* @param array $javaScriptOptions
*
* @return void
*/
public function doFilter($file, $arguments, $javaScriptOptions)
{
$userOptions = isset($javaScriptOptions['packer']) ? $javaScriptOptions['packer'] : array();
$options = array_merge($this->_defaultOptions, $userOptions);
if (! $arguments['packer']) {
return;
}
$content = file_get_contents($file);
$packer = new JavaScriptPacker($content, $options['encoding'], $options['fastDecode'], $options['specialChars']);
file_put_contents($file, $packer->pack());
}
}

0 comments on commit 5a646e5

Please sign in to comment.