Browse files

Merge remote-tracking branch 'origin/master' into node-visitor

  • Loading branch information...
2 parents afc1495 + f84453c commit 1e8f0860116537168f17adb5aad0352c4d39d314 @kriswallsmith committed Jan 9, 2013
View
29 .travis.phpunit.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit bootstrap="./tests/bootstrap.php" colors="true">
+ <testsuites>
+ <testsuite name="Assetic Test Suite">
+ <directory suffix="Test.php">./tests/Assetic/Test/</directory>
+ </testsuite>
+ </testsuites>
+
+ <php>
+ <server name="COFFEE_BIN" value="node_modules/coffee-script/bin/coffee" />
+ <server name="CSSMIN" value="vendor/cssmin/source/CssMin.php" />
+ <server name="HANDLEBARS_BIN" value="node_modules/handlebars/bin/handlebars" />
+ <server name="JSMIN" value="vendor/minify/min/lib/JSMin.php" />
+ <server name="JSMINPLUS" value="vendor/minify/min/lib/JSMinPlus.php" />
+ <server name="NODE_PATH" value="./node_modules" />
+ <server name="PACKAGER" value="vendor/packager/packager.php" />
+ <server name="PACKER" value="vendor/packer/class.JavaScriptPacker.php" />
+ <server name="UGLIFYCSS_BIN" value="node_modules/uglifycss/uglifycss" />
+ <server name="UGLIFYJS2_BIN" value="node_modules/uglify-js/bin/uglifyjs" />
+ <server name="UGLIFYJS_BIN" value="vendor/uglifyjs/node_modules/uglify-js/bin/uglifyjs" />
+ </php>
+
+ <filter>
+ <whitelist>
+ <directory suffix=".php">./src/Assetic/</directory>
+ </whitelist>
+ </filter>
+</phpunit>
View
4 .travis.yml
@@ -11,5 +11,7 @@ before_script:
- git clone https://github.com/mrclay/minify.git vendor/minify --quiet --depth 1
- svn checkout http://cssmin.googlecode.com/svn/trunk/ vendor/cssmin --quiet
- wget --quiet -O javascript-packer.zip "http://joliclic.free.fr/php/javascript-packer/telechargement.php?id=2&action=telecharger" && mkdir -p vendor/packer && unzip -qq javascript-packer.zip -d vendor/packer; rm javascript-packer.zip
+ - npm install --quiet uglify-js@1 && mkdir -p vendor/uglifyjs && mv node_modules vendor/uglifyjs
+ - npm install --quiet coffee-script handlebars less stylus uglifycss uglify-js
-script: phpunit --configuration phpunit.travis.xml
+script: phpunit --configuration .travis.phpunit.xml --verbose
View
1 CHANGELOG-1.1.md
@@ -7,6 +7,7 @@
* Added Handlebars support
* Added Scssphp-compass support
* Added the CacheBustingWorker
+ * Added the UglifyJs2Filter
1.1.0-alpha1 (August 28, 2012)
------------------------------
View
40 phpunit.travis.xml
@@ -1,40 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<phpunit bootstrap="./tests/bootstrap.php" colors="true">
- <testsuites>
- <testsuite name="Assetic Test Suite">
- <directory suffix="Test.php">./tests/Assetic/Test/</directory>
- </testsuite>
- </testsuites>
-
- <php>
- <!-- <server name="CLOSURE_JAR" value="/path/to/google-closure/compiler.jar" /> -->
- <!-- <server name="COFFEE_BIN" value="/path/to/coffee" /> -->
- <!-- <server name="HANDLEBARS_BIN" value="/path/to/handlebars" /> -->
- <!-- <server name="NODE_BIN" value="/path/to/node" /> -->
- <!-- <server name="NODE_PATH" value="/path/to/node/lib" /> -->
- <!-- <server name="LESSPHP" value="vendor/lessphp/lessc.inc.php" />-->
- <!-- <server name="SASS_BIN" value="/path/to/sass" /> -->
- <!-- <server name="COMPASS_BIN" value="/path/to/compass" /> -->
- <!-- <server name="RUBY_BIN" value="/path/to/ruby" /> -->
- <!-- <server name="SPROCKETS_LIB" value="/path/to/sprockets/lib" /> -->
- <!-- <server name="TWIG_LIB" value="vendor/twig/lib" /> -->
- <!-- <server name="YUI_COMPRESSOR_JAR" value="/path/to/yuicompressor-2.4.2.jar" /> -->
- <!-- <server name="OPTIPNG_BIN" value="/path/to/optipng" /> -->
- <!-- <server name="JPEGOPTIM_BIN" value="/path/to/jpegoptim" /> -->
- <!-- <server name="JPEGTRAN_BIN" value="/path/to/jpegtran" /> -->
- <!-- <server name="PNGOUT_BIN" value="/path/to/pngout" /> -->
- <server name="CSSMIN" value="vendor/cssmin/source/CssMin.php" />
- <server name="JSMIN" value="vendor/minify/min/lib/JSMin.php" />
- <server name="JSMINPLUS" value="vendor/minify/min/lib/JSMinPlus.php" />
- <!-- <server name="CSSEMBED_JAR" value="/path/to/cssembed.jar" /> -->
- <server name="PACKAGER" value="vendor/packager/packager.php" />
- <server name="PACKER" value="vendor/packer/class.JavaScriptPacker.php" />
- </php>
-
- <filter>
- <whitelist>
- <directory suffix=".php">./src/Assetic/</directory>
- </whitelist>
- </filter>
-</phpunit>
View
10 src/Assetic/Filter/CompassFilter.php
@@ -49,6 +49,7 @@ class CompassFilter implements FilterInterface
private $loadPaths = array();
private $httpPath;
private $httpImagesPath;
+ private $httpFontsPath;
private $httpGeneratedImagesPath;
private $generatedImagesPath;
private $httpJavascriptsPath;
@@ -163,6 +164,11 @@ public function setHttpImagesPath($httpImagesPath)
$this->httpImagesPath = $httpImagesPath;
}
+ public function setHttpFontsPath($httpFontsPath)
+ {
+ $this->httpFontsPath = $httpFontsPath;
+ }
+
public function setHttpGeneratedImagesPath($httpGeneratedImagesPath)
{
$this->httpGeneratedImagesPath = $httpGeneratedImagesPath;
@@ -270,6 +276,10 @@ public function filterLoad(AssetInterface $asset)
$optionsConfig['http_images_path'] = $this->httpImagesPath;
}
+ if ($this->httpFontsPath) {
+ $optionsConfig['http_fonts_path'] = $this->httpFontsPath;
+ }
+
if ($this->httpGeneratedImagesPath) {
$optionsConfig['http_generated_images_path'] = $this->httpGeneratedImagesPath;
}
View
105 src/Assetic/Filter/UglifyJs2Filter.php
@@ -0,0 +1,105 @@
+<?php
+
+/*
+ * This file is part of the Assetic package, an OpenSky project.
+ *
+ * (c) 2010-2012 OpenSky Project Inc
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Assetic\Filter;
+
+use Assetic\Asset\AssetInterface;
+use Assetic\Exception\FilterException;
+
+/**
+ * UglifyJs2 filter.
+ *
+ * @link http://lisperator.net/uglifyjs
+ * @author Kris Wallsmith <kris.wallsmith@gmail.com>
+ */
+class UglifyJs2Filter extends BaseNodeFilter
+{
+ private $uglifyjsBin;
+ private $nodeBin;
+ private $compress;
+ private $beautify;
+ private $mangle;
+
+ public function __construct($uglifyjsBin = '/usr/bin/uglifyjs', $nodeBin = null)
+ {
+ $this->uglifyjsBin = $uglifyjsBin;
+ $this->nodeBin = $nodeBin;
+ }
+
+ public function setCompress($compress)
+ {
+ $this->compress = $compress;
+ }
+
+ public function setBeautify($beautify)
+ {
+ $this->beautify = $beautify;
+ }
+
+ public function setMangle($mangle)
+ {
+ $this->mangle = $mangle;
+ }
+
+ public function filterLoad(AssetInterface $asset)
+ {
+ }
+
+ public function filterDump(AssetInterface $asset)
+ {
+ $pb = $this->createProcessBuilder($this->nodeBin
+ ? array($this->nodeBin, $this->uglifyjsBin)
+ : array($this->uglifyjsBin));
+
+ if ($this->compress) {
+ $pb->add('--compress');
+ }
+
+ if ($this->beautify) {
+ $pb->add('--beautify');
+ }
+
+ if ($this->mangle) {
+ $pb->add('--mangle');
+ }
+
+ // input and output files
+ $input = tempnam(sys_get_temp_dir(), 'input');
+ $output = tempnam(sys_get_temp_dir(), 'output');
+
+ file_put_contents($input, $asset->getContent());
+ $pb->add('-o')->add($output)->add($input);
+
+ $proc = $pb->getProcess();
+ $code = $proc->run();
+ unlink($input);
+
+ if (0 < $code) {
+ if (file_exists($output)) {
+ unlink($output);
+ }
+
+ if (127 === $code) {
+ throw new \RuntimeException('Path to node executable could not be resolved.');
+ }
+
+ throw FilterException::fromProcess($proc)->setInput($asset->getContent());
+ }
+
+ if (!file_exists($output)) {
+ throw new \RuntimeException('Error creating output file.');
+ }
+
+ $asset->setContent(file_get_contents($output));
+
+ unlink($output);
+ }
+}
View
24 tests/Assetic/Test/Filter/CompassFilterTest.php
@@ -20,22 +20,30 @@
* @author Maxime Thirouin <dev@moox.fr>
* @group integration
*/
-class CompassFilterTest extends \PHPUnit_Framework_TestCase
+class CompassFilterTest extends FilterTestCase
{
+ private $filter;
+
protected function setUp()
{
- if (!isset($_SERVER['COMPASS_BIN'])) {
- $this->markTestSkipped('There is no COMPASS_BIN environment variable.');
+ if (!$compassBin = $this->findExecutable('compass', 'COMPASS_BIN')) {
+ $this->markTestSkipped('Unable to find `compass` executable.');
}
+
+ $this->filter = new CompassFilter($compassBin);
+ }
+
+ protected function tearDown()
+ {
+ $this->filter = null;
}
public function testFilterLoadWithScss()
{
$asset = new FileAsset(__DIR__.'/fixtures/compass/stylesheet.scss');
$asset->load();
- $filter = new CompassFilter($_SERVER['COMPASS_BIN']);
- $filter->filterLoad($asset);
+ $this->filter->filterLoad($asset);
$this->assertContains('.test-class', $asset->getContent());
$this->assertContains('font-size: 2em;', $asset->getContent());
@@ -46,8 +54,7 @@ public function testFilterLoadWithSass()
$asset = new FileAsset(__DIR__.'/fixtures/compass/stylesheet.sass');
$asset->load();
- $filter = new CompassFilter($_SERVER['COMPASS_BIN']);
- $filter->filterLoad($asset);
+ $this->filter->filterLoad($asset);
$this->assertContains('.test-class', $asset->getContent());
$this->assertContains('font-size: 2em;', $asset->getContent());
@@ -58,8 +65,7 @@ public function testCompassMixin()
$asset = new FileAsset(__DIR__.'/fixtures/compass/compass.sass');
$asset->load();
- $filter = new CompassFilter($_SERVER['COMPASS_BIN']);
- $filter->filterLoad($asset);
+ $this->filter->filterLoad($asset);
$this->assertContains('text-decoration', $asset->getContent());
}
View
116 tests/Assetic/Test/Filter/UglifyJs2FilterTest.php
@@ -0,0 +1,116 @@
+<?php
+
+/*
+ * This file is part of the Assetic package, an OpenSky project.
+ *
+ * (c) 2010-2012 OpenSky Project Inc
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Assetic\Test\Filter;
+
+use Assetic\Asset\FileAsset;
+use Assetic\Filter\UglifyJs2Filter;
+use Symfony\Component\Process\ProcessBuilder;
+
+/**
+ * @group integration
+ */
+class UglifyJs2FilterTest extends FilterTestCase
+{
+ private $asset;
+ private $filter;
+
+ protected function setUp()
+ {
+ $uglifyjsBin = $this->findExecutable('uglifyjs', 'UGLIFYJS2_BIN');
+ $nodeBin = $this->findExecutable('node', 'NODE_BIN');
+ if (!$uglifyjsBin) {
+ $this->markTestSkipped('Unable to find `uglifyjs` executable.');
+ }
+
+ // verify uglifyjs version
+ $pb = new ProcessBuilder($nodeBin ? array($nodeBin, $uglifyjsBin) : array($uglifyjsBin));
+ $pb->add('--version');
+ if (isset($_SERVER['NODE_PATH'])) {
+ $pb->setEnv('NODE_PATH', $_SERVER['NODE_PATH']);
+ }
+ if (0 !== $pb->getProcess()->run()) {
+ $this->markTestSkipped('Incorrect version of UglifyJs');
+ }
+
+ $this->asset = new FileAsset(__DIR__.'/fixtures/uglifyjs/script.js');
+ $this->asset->load();
+
+ $this->filter = new UglifyJs2Filter($uglifyjsBin, $nodeBin);
+ }
+
+ protected function tearDown()
+ {
+ $this->asset = null;
+ $this->filter = null;
+ }
+
+ public function testUglify()
+ {
+ $this->filter->filterDump($this->asset);
+
+ $expected = '(function(){var foo=new Array(1,2,3,4);var bar=Array(a,b,c);var var1=new Array(5);var var2=new Array(a);function bar(foo){var2.push(foo);return foo}var foo=function(var1){return var1};foo("abc123");bar("abc123")})();';
+ $this->assertEquals($expected, $this->asset->getContent());
+ }
+
+ public function testCompress()
+ {
+ $this->filter->setCompress(true);
+ $this->filter->filterDump($this->asset);
+
+ $expected = '(function(){function bar(foo){return var2.push(foo),foo}var foo=[1,2,3,4],bar=[a,b,c];Array(5);var var2=Array(a),foo=function(var1){return var1};foo("abc123"),bar("abc123")})();';
+ $this->assertEquals($expected, $this->asset->getContent());
+ }
+
+ public function testMangle()
+ {
+ $this->filter->setMangle(true);
+ $this->filter->filterDump($this->asset);
+
+ $expected = '(function(){var r=new Array(1,2,3,4);var n=Array(a,b,c);var u=new Array(5);var e=new Array(a);function n(r){e.push(r);return r}var r=function(r){return r};r("abc123");n("abc123")})();';
+ $this->assertEquals($expected, $this->asset->getContent());
+ }
+
+ public function testCompressAndMangle()
+ {
+ $this->filter->setCompress(true);
+ $this->filter->setMangle(true);
+ $this->filter->filterDump($this->asset);
+
+ $expected = '(function(){function r(r){return u.push(r),r}var n=[1,2,3,4],r=[a,b,c];Array(5);var u=Array(a),n=function(r){return r};n("abc123"),r("abc123")})();';
+ $this->assertEquals($expected, $this->asset->getContent());
+ }
+
+ public function testBeautify()
+ {
+ $this->filter->setBeautify(true);
+ $this->filter->filterDump($this->asset);
+
+ $expected = <<<JS
+(function() {
+ var foo = new Array(1, 2, 3, 4);
+ var bar = Array(a, b, c);
+ var var1 = new Array(5);
+ var var2 = new Array(a);
+ function bar(foo) {
+ var2.push(foo);
+ return foo;
+ }
+ var foo = function(var1) {
+ return var1;
+ };
+ foo("abc123");
+ bar("abc123");
+})();
+JS;
+ $this->assertEquals($expected, $this->asset->getContent());
+ }
+}
View
49 tests/Assetic/Test/Filter/UglifyJsFilterTest.php
@@ -13,6 +13,7 @@
use Assetic\Asset\FileAsset;
use Assetic\Filter\UglifyJsFilter;
+use Symfony\Component\Process\ProcessBuilder;
/**
* @group integration
@@ -30,6 +31,16 @@ protected function setUp()
$this->markTestSkipped('Unable to find `uglifyjs` executable.');
}
+ // verify uglifyjs version
+ $pb = new ProcessBuilder($nodeBin ? array($nodeBin, $uglifyjsBin) : array($uglifyjsBin));
+ $pb->add('--version');
+ if (isset($_SERVER['NODE_PATH'])) {
+ $pb->setEnv('NODE_PATH', $_SERVER['NODE_PATH']);
+ }
+ if (0 === $pb->getProcess()->run()) {
+ $this->markTestSkipped('Incorrect version of UglifyJs');
+ }
+
$this->asset = new FileAsset(__DIR__.'/fixtures/uglifyjs/script.js');
$this->asset->load();
@@ -49,9 +60,9 @@ public function testUglify()
$expected = <<<JS
/**
* Copyright
- */function bar(e){return var2.push(e),e}var foo=new Array(1,2,3,4),bar=Array(a,b,c),var1=new Array(5),var2=new Array(a),foo=function(e){return e};
+ */(function(){function t(e){return r.push(e),e}var e=new Array(1,2,3,4),t=Array(a,b,c),n=new Array(5),r=new Array(a),e=function(e){return e};e("abc123"),t("abc123")})();
JS;
- $this->assertSame($expected, $this->asset->getContent());
+ $this->assertEquals($expected, $this->asset->getContent());
}
public function testUnsafeUglify()
@@ -62,9 +73,9 @@ public function testUnsafeUglify()
$expected = <<<JS
/**
* Copyright
- */function bar(e){return var2.push(e),e}var foo=[1,2,3,4],bar=[a,b,c],var1=Array(5),var2=Array(a),foo=function(e){return e};
+ */(function(){function t(e){return r.push(e),e}var e=[1,2,3,4],t=[a,b,c],n=Array(5),r=Array(a),e=function(e){return e};e("abc123"),t("abc123")})();
JS;
- $this->assertSame($expected, $this->asset->getContent());
+ $this->assertEquals($expected, $this->asset->getContent());
}
public function testBeautifyUglify()
@@ -75,38 +86,40 @@ public function testBeautifyUglify()
$expected = <<<JS
/**
* Copyright
- */function bar(e) {
- return var2.push(e), e;
-}
-
-var foo = new Array(1, 2, 3, 4), bar = Array(a, b, c), var1 = new Array(5), var2 = new Array(a), foo = function(e) {
- return e;
-};
+ */(function() {
+ function t(e) {
+ return r.push(e), e;
+ }
+ var e = new Array(1, 2, 3, 4), t = Array(a, b, c), n = new Array(5), r = new Array(a), e = function(e) {
+ return e;
+ };
+ e("abc123"), t("abc123");
+})();
JS;
- $this->assertSame($expected, $this->asset->getContent());
+ $this->assertEquals($expected, $this->asset->getContent());
}
- public function testMangleUglify()
+ public function testNoMangleUglify()
{
- $this->filter->setMangle(true);
+ $this->filter->setMangle(false);
$this->filter->filterDump($this->asset);
$expected = <<<JS
/**
* Copyright
- */function bar(e){return var2.push(e),e}var foo=new Array(1,2,3,4),bar=Array(a,b,c),var1=new Array(5),var2=new Array(a),foo=function(e){return e};
+ */(function(){function bar(foo){return var2.push(foo),foo}var foo=new Array(1,2,3,4),bar=Array(a,b,c),var1=new Array(5),var2=new Array(a),foo=function(var1){return var1};foo("abc123"),bar("abc123")})();
JS;
- $this->assertSame($expected, $this->asset->getContent());
+ $this->assertEquals($expected, $this->asset->getContent());
}
public function testNoCopyrightUglify()
{
$this->filter->setNoCopyright(true);
$this->filter->filterDump($this->asset);
- $expected = 'function bar(e){return var2.push(e),e}var foo=new Array(1,2,3,4),bar=Array(a,b,c),var1=new Array(5),var2=new Array(a),foo=function(e){return e};';
- $this->assertSame($expected, $this->asset->getContent());
+ $expected = '(function(){function t(e){return r.push(e),e}var e=new Array(1,2,3,4),t=Array(a,b,c),n=new Array(5),r=new Array(a),e=function(e){return e};e("abc123"),t("abc123")})();';
+ $this->assertEquals($expected, $this->asset->getContent());
}
}
View
7 tests/Assetic/Test/Filter/fixtures/uglifyjs/script.js
@@ -2,6 +2,8 @@
* Copyright
*/
+(function() {
+
var foo = new Array(1, 2, 3, 4);
var bar = Array(a, b, c);
var var1 = new Array(5);
@@ -16,3 +18,8 @@ function bar(foo) {
var foo = function (var1) {
return var1;
}
+
+foo('abc123')
+bar('abc123')
+
+})()

0 comments on commit 1e8f086

Please sign in to comment.