1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-23 06:02:51 +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

@@ -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