mirror of
https://github.com/mrclay/minify.git
synced 2025-08-13 09:34:54 +02:00
pass any option to closure compiler
This commit is contained in:
@@ -24,19 +24,12 @@
|
|||||||
*
|
*
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @todo unit tests, $options docs
|
|
||||||
* @todo more options support (or should just passthru them all?)
|
|
||||||
*
|
|
||||||
* @package Minify
|
* @package Minify
|
||||||
* @author Stephen Clay <steve@mrclay.org>
|
* @author Stephen Clay <steve@mrclay.org>
|
||||||
* @author Elan Ruusamäe <glen@delfi.ee>
|
* @author Elan Ruusamäe <glen@delfi.ee>
|
||||||
*/
|
*/
|
||||||
class Minify_ClosureCompiler
|
class Minify_ClosureCompiler
|
||||||
{
|
{
|
||||||
const OPTION_CHARSET = 'charset';
|
|
||||||
const OPTION_COMPILATION_LEVEL = 'compilation_level';
|
|
||||||
const OPTION_WARNING_LEVEL = 'warning_level';
|
|
||||||
|
|
||||||
public static $isDebug = false;
|
public static $isDebug = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,6 +54,17 @@ class Minify_ClosureCompiler
|
|||||||
*/
|
*/
|
||||||
public static $javaExecutable = 'java';
|
public static $javaExecutable = 'java';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default command line options passed to closure-compiler
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $defaultOptions = array(
|
||||||
|
'charset' => 'utf-8',
|
||||||
|
'compilation_level' => 'SIMPLE_OPTIMIZATIONS',
|
||||||
|
'warning_level' => 'QUIET',
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minify a Javascript string
|
* Minify a Javascript string
|
||||||
*
|
*
|
||||||
@@ -137,7 +141,8 @@ class Minify_ClosureCompiler
|
|||||||
$this->checkJar(self::$jarFile);
|
$this->checkJar(self::$jarFile);
|
||||||
$server = array(
|
$server = array(
|
||||||
self::$javaExecutable,
|
self::$javaExecutable,
|
||||||
'-jar', escapeshellarg(self::$jarFile)
|
'-jar',
|
||||||
|
escapeshellarg(self::$jarFile)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $server;
|
return $server;
|
||||||
@@ -151,24 +156,13 @@ class Minify_ClosureCompiler
|
|||||||
{
|
{
|
||||||
$args = array();
|
$args = array();
|
||||||
|
|
||||||
$o = array_merge(
|
$options = array_merge(
|
||||||
array(
|
static::$defaultOptions,
|
||||||
self::OPTION_CHARSET => 'utf-8',
|
|
||||||
self::OPTION_COMPILATION_LEVEL => 'SIMPLE_OPTIMIZATIONS',
|
|
||||||
self::OPTION_WARNING_LEVEL => 'QUIET',
|
|
||||||
),
|
|
||||||
$userOptions
|
$userOptions
|
||||||
);
|
);
|
||||||
|
|
||||||
$charsetOption = $o[self::OPTION_CHARSET];
|
foreach ($options as $key => $value) {
|
||||||
if (preg_match('/^[\\da-zA-Z0-9\\-]+$/', $charsetOption)) {
|
$args[] = "--{$key} " . escapeshellarg($value);
|
||||||
$args[] = "--charset {$charsetOption}";
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (array(self::OPTION_COMPILATION_LEVEL, self::OPTION_WARNING_LEVEL) as $opt) {
|
|
||||||
if ($o[$opt]) {
|
|
||||||
$args[] = "--{$opt} " . escapeshellarg($o[$opt]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $args;
|
return $args;
|
||||||
|
@@ -63,7 +63,7 @@ class MinifyClosureCompilerTest extends TestCase
|
|||||||
$src = "function unused() {};";
|
$src = "function unused() {};";
|
||||||
$minExpected = '';
|
$minExpected = '';
|
||||||
$options = array(
|
$options = array(
|
||||||
Minify_ClosureCompiler::OPTION_COMPILATION_LEVEL => 'ADVANCED_OPTIMIZATIONS'
|
'compilation_level' => 'ADVANCED_OPTIMIZATIONS'
|
||||||
);
|
);
|
||||||
$minOutput = Minify_ClosureCompiler::minify($src, $options);
|
$minOutput = Minify_ClosureCompiler::minify($src, $options);
|
||||||
$this->assertSame($minExpected, $minOutput, 'advanced optimizations');
|
$this->assertSame($minExpected, $minOutput, 'advanced optimizations');
|
||||||
|
Reference in New Issue
Block a user