1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-30 17:19:54 +02:00

Added Minify_Lines to test suite, full docs on added methods in Minify & Minify_Lines.

This commit is contained in:
Steve Clay
2008-06-30 19:46:23 +00:00
parent e77a1cf82c
commit 6cdfb77083
5 changed files with 298 additions and 35 deletions

View File

@@ -98,6 +98,10 @@ class Minify {
* E.g. ($_SERVER['REQUEST_TIME'] + 86400 * 365) for 1yr
* Note this has nothing to do with server-side caching.
*
* 'debug' : set to true to minify all sources with the 'Lines' controller, which
* eases the debugging of combined files. This also prevents 304 responses.
* @see Minify_Lines::minify()
*
* 'minifiers' : to override Minify's default choice of minifier function for
* a particular content-type, specify your callback under the key of the
* content-type:
@@ -305,13 +309,16 @@ class Minify {
* Set up sources to use Minify_Lines
*
* @param array $sources Minify_Source instances
*
* @return null
*/
protected static function _setupDebug($sources)
{
foreach ($sources as $source) {
$source->minifier = array('Minify_Lines', 'minify');
$id = $source->getId();
$source->minifyOptions = array(
'id' => $source->getId()
'id' => (is_file($id) ? basename($id) : $id)
);
}
}

View File

@@ -14,12 +14,16 @@ 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.
*
* @param string $content
*
* @param array $options available options:
*
* 'id': (optional) short string to identify file. E.g. "jqp" for plugins.jquery.js
* 'id': (optional) string to identify file. E.g. file name/path
*
* @return string
*/
@@ -37,11 +41,10 @@ class Minify_Lines {
$padTo = strlen($numLines);
$inComment = false;
$i = 0;
$newLines = array();
while (null !== ($line = array_shift($lines))) {
if (('' !== $id) && (0 == $i % 50)) {
$newLines[] = '';
$newLines[] = "/* {$id} */";
$newLines[] = '';
array_push($newLines, '', "/* {$id} */", '');
}
++$i;
$newLines[] = self::_addNote($line, $i, $inComment, $padTo);
@@ -71,6 +74,16 @@ class Minify_Lines {
: "\n";
}
/**
* 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)
{
while (strlen($line)) {
@@ -88,6 +101,20 @@ class Minify_Lines {
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)
{
return $inComment