mirror of
https://github.com/mrclay/minify.git
synced 2025-08-07 22:56:33 +02:00
builder/index.php : fix Issue 67
Minify.php : allow minifier = '' Minify/CSS.php : more extensible (Issue 64) Minify/HTML.php : more extensible Minify/Lines.php : fix Issue 55 Minify/Packer.php : usability test_environment.php : test DOCUMENT_ROOT test_Minify_Lines.php : test Issue 55
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
// check for auto-encoding
|
||||
$encodeOutput = ! ini_get('zlib.output_compression');
|
||||
$encodeOutput = (function_exists('gzdeflate')
|
||||
&& !ini_get('zlib.output_compression'));
|
||||
|
||||
require dirname(__FILE__) . '/../config.php';
|
||||
|
||||
|
@@ -12,4 +12,23 @@
|
||||
return array(
|
||||
// 'js' => array('//js/file1.js', '//js/file2.js'),
|
||||
// 'css' => array('//css/file1.css', '//css/file2.css'),
|
||||
|
||||
// custom source example
|
||||
/*'js2' => array(
|
||||
dirname(__FILE__) . '/../min_unit_tests/_test_files/js/before.js',
|
||||
// do NOT process this file
|
||||
new Minify_Source(array(
|
||||
'filepath' => dirname(__FILE__) . '/../min_unit_tests/_test_files/js/before.js',
|
||||
'minifier' => create_function('$a', 'return $a;')
|
||||
))
|
||||
),//*/
|
||||
|
||||
/*'js3' => array(
|
||||
dirname(__FILE__) . '/../min_unit_tests/_test_files/js/before.js',
|
||||
// do NOT process this file
|
||||
new Minify_Source(array(
|
||||
'filepath' => dirname(__FILE__) . '/../min_unit_tests/_test_files/js/before.js',
|
||||
'minifier' => array('Minify_Packer', 'minify')
|
||||
))
|
||||
),//*/
|
||||
);
|
@@ -439,7 +439,7 @@ class Minify {
|
||||
$options = (null !== $source->minifyOptions)
|
||||
? array_merge($defaultOptions, $source->minifyOptions)
|
||||
: $defaultOptions;
|
||||
if ($defaultMinifier) {
|
||||
if ($minifier) {
|
||||
self::$_controller->loadMinifier($minifier);
|
||||
// get source content and minify it
|
||||
$pieces[] = call_user_func($minifier, $source->getContent(), $options);
|
||||
|
@@ -16,9 +16,17 @@
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
* @author http://code.google.com/u/1stvamp/ (Issue 64 patch)
|
||||
*/
|
||||
class Minify_CSS {
|
||||
|
||||
/**
|
||||
* Defines which class to call as part of callbacks, change this
|
||||
* if you extend Minify_CSS
|
||||
* @var string
|
||||
*/
|
||||
protected static $className = 'Minify_CSS';
|
||||
|
||||
/**
|
||||
* Minify a CSS string
|
||||
*
|
||||
@@ -52,7 +60,7 @@ class Minify_CSS {
|
||||
$options['preserveComments'] = false;
|
||||
return Minify_CommentPreserver::process(
|
||||
$css
|
||||
,array('Minify_CSS', 'minify')
|
||||
,array(self::$className, 'minify')
|
||||
,array($options)
|
||||
);
|
||||
}
|
||||
@@ -83,7 +91,7 @@ class Minify_CSS {
|
||||
// apply callback to all valid comments (and strip out surrounding ws
|
||||
self::$_inHack = false;
|
||||
$css = preg_replace_callback('@\\s*/\\*([\\s\\S]*?)\\*/\\s*@'
|
||||
,array('Minify_CSS', '_commentCB'), $css);
|
||||
,array(self::$className, '_commentCB'), $css);
|
||||
|
||||
// remove ws around { } and last semicolon in declaration block
|
||||
$css = preg_replace('/\\s*{\\s*/', '{', $css);
|
||||
@@ -125,7 +133,7 @@ class Minify_CSS {
|
||||
[^~>+,\\s]+ # selector part
|
||||
{ # open declaration block
|
||||
/x'
|
||||
,array('Minify_CSS', '_selectorsCB'), $css);
|
||||
,array(self::$className, '_selectorsCB'), $css);
|
||||
|
||||
// minimize hex colors
|
||||
$css = preg_replace('/([^=])#([a-f\\d])\\2([a-f\\d])\\3([a-f\\d])\\4([\\s;\\}])/i'
|
||||
@@ -133,7 +141,7 @@ class Minify_CSS {
|
||||
|
||||
// remove spaces between font families
|
||||
$css = preg_replace_callback('/font-family:([^;}]+)([;}])/'
|
||||
,array('Minify_CSS', '_fontFamilyCB'), $css);
|
||||
,array(self::$className, '_fontFamilyCB'), $css);
|
||||
|
||||
$css = preg_replace('/@import\\s+url/', '@import url', $css);
|
||||
|
||||
@@ -160,9 +168,9 @@ class Minify_CSS {
|
||||
}
|
||||
if ($rewrite) {
|
||||
$css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/'
|
||||
,array('Minify_CSS', '_urlCB'), $css);
|
||||
,array(self::$className, '_urlCB'), $css);
|
||||
$css = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/'
|
||||
,array('Minify_CSS', '_urlCB'), $css);
|
||||
,array(self::$className, '_urlCB'), $css);
|
||||
}
|
||||
self::$_tempPrepend = self::$_tempCurrentDir = '';
|
||||
return trim($css);
|
||||
|
@@ -18,6 +18,13 @@
|
||||
*/
|
||||
class Minify_HTML {
|
||||
|
||||
/**
|
||||
* Defines which class to call as part of callbacks, change this
|
||||
* if you extend Minify_HTML
|
||||
* @var string
|
||||
*/
|
||||
protected static $className = 'Minify_HTML';
|
||||
|
||||
/**
|
||||
* "Minify" an HTML page
|
||||
*
|
||||
@@ -59,30 +66,30 @@ class Minify_HTML {
|
||||
// replace SCRIPTs (and minify) with placeholders
|
||||
$html = preg_replace_callback(
|
||||
'/\\s*(<script\\b[^>]*?>)([\\s\\S]*?)<\\/script>\\s*/i'
|
||||
,array('Minify_HTML', '_removeScriptCB')
|
||||
,array(self::$className, '_removeScriptCB')
|
||||
,$html);
|
||||
|
||||
// replace STYLEs (and minify) with placeholders
|
||||
$html = preg_replace_callback(
|
||||
'/\\s*(<style\\b[^>]*?>)([\\s\\S]*?)<\\/style>\\s*/i'
|
||||
,array('Minify_HTML', '_removeStyleCB')
|
||||
,array(self::$className, '_removeStyleCB')
|
||||
,$html);
|
||||
|
||||
// remove HTML comments (not containing IE conditional comments).
|
||||
$html = preg_replace_callback(
|
||||
'/<!--([\\s\\S]*?)-->/'
|
||||
,array('Minify_HTML', '_commentCB')
|
||||
,array(self::$className, '_commentCB')
|
||||
,$html);
|
||||
|
||||
// replace PREs with placeholders
|
||||
$html = preg_replace_callback('/\\s*(<pre\\b[^>]*?>[\\s\\S]*?<\\/pre>)\\s*/i'
|
||||
,array('Minify_HTML', '_removePreCB')
|
||||
,array(self::$className, '_removePreCB')
|
||||
, $html);
|
||||
|
||||
// replace TEXTAREAs with placeholders
|
||||
$html = preg_replace_callback(
|
||||
'/\\s*(<textarea\\b[^>]*?>[\\s\\S]*?<\\/textarea>)\\s*/i'
|
||||
,array('Minify_HTML', '_removeTaCB')
|
||||
,array(self::$className, '_removeTaCB')
|
||||
, $html);
|
||||
|
||||
// trim each line.
|
||||
@@ -99,7 +106,7 @@ class Minify_HTML {
|
||||
// remove ws outside of all elements
|
||||
$html = preg_replace_callback(
|
||||
'/>([^<]+)</'
|
||||
,array('Minify_HTML', '_outsideTagCB')
|
||||
,array(self::$className, '_outsideTagCB')
|
||||
,$html);
|
||||
|
||||
// use newlines before 1st attribute in open tags (to limit line lengths)
|
||||
|
@@ -9,6 +9,7 @@
|
||||
*
|
||||
* @package Minify
|
||||
* @author Stephen Clay <steve@mrclay.org>
|
||||
* @author Adam Pedersen (Issue 55 fix)
|
||||
*/
|
||||
class Minify_Lines {
|
||||
|
||||
@@ -71,7 +72,13 @@ class Minify_Lines {
|
||||
if (false === $pos) {
|
||||
return $inComment;
|
||||
} else {
|
||||
if ($pos == 0
|
||||
|| ($inComment
|
||||
? substr($line, $pos, 3)
|
||||
: substr($line, $pos-1, 3)) != '*/*')
|
||||
{
|
||||
$inComment = ! $inComment;
|
||||
}
|
||||
$line = substr($line, $pos + 2);
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,13 @@
|
||||
* @package Minify
|
||||
*/
|
||||
|
||||
require 'class.JavaScriptPacker.php';
|
||||
if (false === (@include 'class.JavaScriptPacker.php')) {
|
||||
trigger_error(
|
||||
'The script "class.JavaScriptPacker.php" is required. Please see: http:'
|
||||
.'//code.google.com/p/minify/source/browse/trunk/min/lib/Minify/Packer.php'
|
||||
,E_USER_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Minify Javascript using Dean Edward's Packer
|
||||
|
2
min_unit_tests/_test_files/minify/lines_bugs.js
Normal file
2
min_unit_tests/_test_files/minify/lines_bugs.js
Normal file
@@ -0,0 +1,2 @@
|
||||
var triggerBug = {_default: "*/*"};
|
||||
var essentialFunctionality = true;
|
@@ -26,6 +26,12 @@
|
||||
/* 23 */ };
|
||||
/* 24 */ })();
|
||||
;
|
||||
/* lines_bugs.js */
|
||||
|
||||
/* 1 */ var triggerBug = {_default: "*/*"};
|
||||
/* 2 */ var essentialFunctionality = true;
|
||||
/* 3 */
|
||||
;
|
||||
/* QueryString.js */
|
||||
|
||||
/* 1 */ var MrClay = window.MrClay || {};
|
||||
|
@@ -15,6 +15,7 @@ function test_Lines()
|
||||
,'encodeOutput' => false
|
||||
,'files' => array(
|
||||
"{$thisDir}/_test_files/minify/email.js"
|
||||
,"{$thisDir}/_test_files/minify/lines_bugs.js"
|
||||
,"{$thisDir}/_test_files/minify/QueryString.js"
|
||||
,"{$thisDir}/_test_files/js/before.js"
|
||||
)
|
||||
|
@@ -20,6 +20,20 @@ function test_environment()
|
||||
{
|
||||
global $thisDir;
|
||||
|
||||
// check DOCROOT
|
||||
$noSlash = assertTrue(
|
||||
0 === preg_match('@[\\\\/]$@', $_SERVER['DOCUMENT_ROOT'])
|
||||
,'environment : DOCUMENT_ROOT should not end in trailing slash'
|
||||
);
|
||||
$goodRoot = assertTrue(
|
||||
0 === strpos(realpath(__FILE__), realpath($_SERVER['DOCUMENT_ROOT']))
|
||||
,'environment : DOCUMENT_ROOT should be real path and contain this test file'
|
||||
);
|
||||
if (! $noSlash || ! $goodRoot) {
|
||||
echo "!NOTE: If you cannot modify DOCUMENT_ROOT, see this comment for a workaround:"
|
||||
,"\n http://code.google.com/p/minify/issues/detail?id=68#c6\n";
|
||||
}
|
||||
|
||||
$thisUrl = 'http://'
|
||||
. $_SERVER['HTTP_HOST'] // avoid redirects when SERVER_NAME doesn't match
|
||||
. ('80' === $_SERVER['SERVER_PORT'] ? '' : ":{$_SERVER['SERVER_PORT']}")
|
||||
|
Reference in New Issue
Block a user