V 3.5 RC 1

This commit is contained in:
Romain Neutron
2011-12-05 00:23:28 +01:00
parent 6f1ee368aa
commit 4c5b7eb658
5563 changed files with 466984 additions and 985416 deletions

View File

@@ -1,6 +1,6 @@
<?php
/**
* Class Minify_Lines
* Class Minify_Lines
* @package Minify
*/
@@ -9,6 +9,7 @@
*
* @package Minify
* @author Stephen Clay <steve@mrclay.org>
* @author Adam Pedersen (Issue 55 fix)
*/
class Minify_Lines {
@@ -16,18 +17,24 @@ class Minify_Lines {
* Add line numbers in C-style comments
*
* This uses a very basic parser easily fooled by comment tokens inside
* strings or regexes, but, otherwise, generally clean code will not be
* mangled.
*
* strings or regexes, but, otherwise, generally clean code will not be
* mangled. URI rewriting can also be performed.
*
* @param string $content
*
*
* @param array $options available options:
*
*
* 'id': (optional) string to identify file. E.g. file name/path
*
* @return string
*
* 'currentDir': (default null) if given, this is assumed to be the
* directory of the current CSS file. Using this, minify will rewrite
* all relative URIs in import/url declarations to correctly point to
* the desired files, and prepend a comment with debugging information about
* this process.
*
* @return string
*/
public static function minify($content, $options = array())
public static function minify($content, $options = array())
{
$id = (isset($options['id']) && $options['id'])
? $options['id']
@@ -48,17 +55,34 @@ class Minify_Lines {
$newLines[] = self::_addNote($line, $i, $inComment, $padTo);
$inComment = self::_eolInComment($line, $inComment);
}
return implode("\n", $newLines) . "\n";
$content = implode("\n", $newLines) . "\n";
// check for desired URI rewriting
if (isset($options['currentDir'])) {
require_once 'Minify/CSS/UriRewriter.php';
Minify_CSS_UriRewriter::$debugText = '';
$content = Minify_CSS_UriRewriter::rewrite(
$content
,$options['currentDir']
,isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT']
,isset($options['symlinks']) ? $options['symlinks'] : array()
);
$content = "/* Minify_CSS_UriRewriter::\$debugText\n\n"
. Minify_CSS_UriRewriter::$debugText . "*/\n"
. $content;
}
return $content;
}
/**
* Is the parser within a C-style comment at the end of this line?
*
* @param string $line current line of code
*
*
* @param bool $inComment was the parser in a comment at the
* beginning of the line?
*
*
* @return bool
*/
private static function _eolInComment($line, $inComment)
@@ -71,25 +95,32 @@ class Minify_Lines {
if (false === $pos) {
return $inComment;
} else {
$inComment = ! $inComment;
if ($pos == 0
|| ($inComment
? substr($line, $pos, 3)
: substr($line, $pos-1, 3)) != '*/*')
{
$inComment = ! $inComment;
}
$line = substr($line, $pos + 2);
}
}
return $inComment;
}
/**
* Prepend a comment (or note) to the given line
*
* @param string $line current line of code
*
* @param string $note content of note/comment
*
*
* @param bool $inComment was the parser in a comment at the
* beginning of the line?
*
* @param int $padTo minimum width of comment
*
*
* @return string
*/
private static function _addNote($line, $note, $inComment, $padTo)