Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Some tweaks to improve un-cached performance.

  • Loading branch information...
commit 041b1e5b670caeca5c7a6e98bbad6877574ea2fc 1 parent 157b188
@peteboere authored
Showing with 152 additions and 193 deletions.
  1. +106 −105 CHANGELOG.txt
  2. +1 −1  README.md
  3. +12 −8 lib/Core.php
  4. +4 −0 lib/Regex.php
  5. +29 −79 lib/Util.php
View
211 CHANGELOG.txt
@@ -1,183 +1,184 @@
1.7
------
-Updated plugin API
-Added options for enabling and disabling plugins at runtime
-Added support for SASS-like @include/@extend syntax for invoking mixins and extends
-Added property sorter plugin
-Boilerplate option now accepts a filename string as a boilerplate template
-CssCrush::string() now uses document_root as a default context for finding linked resources
-Updated command line appication
-Updated aliases and initial value files
-Fixed parsing issue introduced in 1.6.1
+---
+Added trace option to output SASS compatible debug-info stubs for use with tools like FireSass.
+Updated plugin API.
+Added options for enabling and disabling plugins at runtime.
+Added property sorter plugin.
+Added support for SASS-like @include/@extend syntax for invoking mixins and extends.
+Boilerplate option now accepts a filename string as a boilerplate template.
+CssCrush::string() now uses document_root as a default context for finding linked resources.
+Updated command line appication.
+Updated aliases and initial value files.
+Fixed parsing issue introduced in 1.6.1.
1.6.1
-----
-Resolved issue #35
-Resolved issue #34
+Resolved issue #35.
+Resolved issue #34.
1.6
---
-Inheritance model improved to support adoption of pseudo classes and elements (see wiki)
-Added rule self-referencing function this() and complimentary data-* properties
-Added rule referencing function query()
-Added default value argument for variables
-Added hsl-adjust() and hsla-adjust() color functions
-Mixin and fragment arg() function can now be nested
-Commas are now optional when specifying arguments for most custom functions
-Double-colon plugin moved to core
-Option rewrite_import_urls now defaults to true
+Inheritance model improved to support adoption of pseudo classes and elements (see wiki).
+Added rule self-referencing function this() and complimentary data-* properties.
+Added rule referencing function query().
+Added default value argument for variables.
+Added hsl-adjust() and hsla-adjust() color functions.
+Mixin and fragment arg() function can now be nested.
+Commas are now optional when specifying arguments for most custom functions.
+Double-colon plugin moved to core.
+Option rewrite_import_urls now defaults to true.
1.5.3
-----
-Refactoring
-Fixed some test cases
+Refactoring.
+Fixed some test cases.
1.5.2
-----
-Resolved issue #32
-csscrush::inline method now defaults to not printing a boilerplate
-Updated aliases file
+Resolved issue #32.
+csscrush::inline method now defaults to not printing a boilerplate.
+Updated aliases file.
1.5.1
-----
-Extended mixins to work with abstract rules and regular rules
-Fixed issue with selector grouping and inheritance in combination
+Extended mixins to work with abstract rules and regular rules.
+Fixed issue with selector grouping and inheritance in combination.
1.5
---
-New feature: Rule inheritance / abstract rules
-New feature: Block nesting
-New feature: Mixins
-New feature: Fragments
-Abstracted IO interface
-Added some error reporting
-Added spiffing.css plugin
-csscrush_tag method now uses media type 'all' by default
-Updated alias and initial-value tables
-Internal refactoring
-Resolved issue #23
-Resolved issue #24
-Resolved issue #27
-Resolved issue #28
-Resolved issue #29
+New feature: Rule inheritance / abstract rules.
+New feature: Block nesting.
+New feature: Mixins.
+New feature: Fragments.
+Abstracted IO interface.
+Added some error reporting.
+Added spiffing.css plugin.
+csscrush_tag method now uses media type 'all' by default.
+Updated alias and initial-value tables.
+Internal refactoring.
+Resolved issue #23.
+Resolved issue #24.
+Resolved issue #27.
+Resolved issue #28.
+Resolved issue #29.
1.4.2
-----
-Fixed bug with @import statement parsing
-Some minor under the hood changes
+Fixed bug with @import statement parsing.
+Some minor under the hood changes.
1.4.1
-----
-Added command line application
-Added 'rewrite_import_urls' option - Ability to rewrite relative url references inside imported css files
-Added Prepend.css - Optionally prepend css to every input
-Fix for issue #21
-Reorganized aliases file with some additions
-Initial-values updated
-Updated csscrush::string method to correctly handle import statements
+Added command line application.
+Added 'rewrite_import_urls' option - Ability to rewrite relative url references inside imported css files.
+Added Prepend.css - Optionally prepend css to every input.
+Fix for issue #21.
+Reorganized aliases file with some additions.
+Initial-values updated.
+Updated csscrush::string method to correctly handle import statements.
1.4
---
-Added initial-keyword plugin (shim for the CSS3 keyword)
-Added inline method (Issue #18)
-Added ability to escape declarations from aliasing or plugins by prefixing with tilde
-Added procedural style public API to mirror the static class API
-Deprecated @variables syntax for @define. @variables still supported
-Adjusted color functions to accept a space delimiter (as well as comma) in the arguments list
-Surpressed some benign PHP warning messages
-Some internal cleaning up
-Disabled IE6 min-height plugin by default
-
-
+Added initial-keyword plugin (shim for the CSS3 keyword).
+Added inline method (Issue #18).
+Added ability to escape declarations from aliasing or plugins by prefixing with tilde.
+Added procedural style public API to mirror the static class API.
+Deprecated @variables syntax for @define. @variables still supported.
+Adjusted color functions to accept a space delimiter (as well as comma) in the arguments list.
+Surpressed some benign PHP warning messages.
+Some internal cleaning up.
+Disabled IE6 min-height plugin by default.
+
+.
1.3.6
-----
-Improved color functions
-Added a-adjust function for altering a color's opacity
-Deprecated hsl-adjust function (you can use nested color functions instead)
-Added the ability to use local versions of alias and plugin files so pull updates don't clobber local settings
-
+Improved color functions.
+Added a-adjust function for altering a color's opacity.
+Deprecated hsl-adjust function (you can use nested color functions instead).
+Added the ability to use local versions of alias and plugin files so pull updates don't clobber local settings.
+.
1.3.5
-----
-Added hook system for plugins
-Plugins split into seperate files
-Aliases and Plugins files renamed with '.ini' file extensions to be editor friendly
-Added opacity plugin
-Updated filter plugin
-Fixed nested custom function parsing (issue #14)
+Added hook system for plugins.
+Plugins split into seperate files.
+Aliases and Plugins files renamed with '.ini' file extensions to be editor friendly.
+Added opacity plugin.
+Updated filter plugin.
+Fixed nested custom function parsing (issue #14).
1.3.4
-----
-Added output_filename option
-Added vendor_target option
-Renamed 'macros' to the more general 'plugins' and split them into their own files
-Removed superfluous outer containing directory (update your include paths)
+Added output_filename option.
+Added vendor_target option.
+Renamed 'macros' to the more general 'plugins' and split them into their own files.
+Removed superfluous outer containing directory (update your include paths).
1.3.3
-----
-Fixed regression with absolute URL file imports (issue #12)
-Fixed minification bug (issue #13)
+Fixed regression with absolute URL file imports (issue #12).
+Fixed minification bug (issue #13).
1.3.2
-----
-Updated variable syntax
-Fixed minification bug
+Updated variable syntax.
+Fixed minification bug.
1.3.1
-----
-Added support for svg and svgz data uris
-Added animation shorthand alias
-Added user-select alias
+Added support for svg and svgz data uris.
+Added animation shorthand alias.
+Added user-select alias.
1.3
---
-Added the public function CssCrush::string for processing raw strings of CSS
-Added color functions
-Added aliases for IE10
+Added the public function CssCrush::string for processing raw strings of CSS.
+Added color functions.
+Added aliases for IE10.
1.2
---
-Rewritten the file importer
+Rewritten the file importer.
1.1
---
-Added global variables support
-Added support for variable interpolation within string literals
-Added 'tag' method for outputting an html link tag instead of returning a filename
-Added values aliases, dynamic 'runtime' variables
-Added RGBA macro
-Added IE clip macro
-Added data uri function
-Minor correction to WAMP support
-Minor fix to rule API
+Added global variables support.
+Added support for variable interpolation within string literals.
+Added 'tag' method for outputting an html link tag instead of returning a filename.
+Added values aliases, dynamic 'runtime' variables.
+Added RGBA macro.
+Added IE clip macro.
+Added data uri function.
+Minor correction to WAMP support.
+Minor fix to rule API.
1.0
---
-Major refactoring
-Custom functions
-Optional boilerplate
-Double colon syntax shim
-Resolved document root issues
-Minification improvements
+Major refactoring.
+Custom functions.
+Optional boilerplate.
+Double colon syntax shim.
+Resolved document root issues.
+Minification improvements.
0.9
---
-Initial release
+Initial release.
View
2  README.md
@@ -1,5 +1,5 @@
CSS Crush
-=====
+===================================
CSS Crush is an extensible PHP based CSS preprocessor that aims to alleviate many of the hacks and workarounds necessary in modern CSS development.
View
20 lib/Core.php
@@ -618,10 +618,11 @@ public static function prepareStream ( &$stream ) {
if ( ! $balanced_curlies ) {
$parse_errors[] = "Unmatched '{' in $current_file.";
}
+
if ( $parse_errors ) {
foreach ( $parse_errors as $error_msg ) {
csscrush::logError( $error_msg );
- trigger_error( "$error_msg\n", E_USER_NOTICE );
+ trigger_error( "$error_msg\n", E_USER_WARNING );
}
return false;
}
@@ -871,6 +872,9 @@ protected static function compile ( $stream ) {
}
// Remove option disabled plugins from the list, and disable them.
+ if ( $options->disable === 'all' ) {
+ $options->disable = array_keys( $config->plugins );
+ }
if ( is_array( $options->disable ) ) {
foreach ( $options->disable as $plugin_name ) {
csscrush_plugin::disable( $plugin_name );
@@ -930,12 +934,6 @@ protected static function compile ( $stream ) {
// Print it all back
self::display( $stream );
- // Release memory
- self::$storage = null;
- $process->mixins = null;
- $process->abstracts = null;
- $process->selectorRelationships = null;
-
// Add in boilerplate
if ( $options->boilerplate ) {
$stream = self::getBoilerplate() . "\n$stream";
@@ -946,6 +944,12 @@ protected static function compile ( $stream ) {
$stream = "@charset $process->charset;\n" . $stream;
}
+ // Release memory
+ self::$storage = null;
+ $process->mixins = null;
+ $process->abstracts = null;
+ $process->selectorRelationships = null;
+
return $stream;
}
@@ -1148,7 +1152,7 @@ protected static function prefixSelectors ( &$stream ) {
$arguments = $arguments->list;
$curly_match = csscrush_util::matchBrackets(
- $stream, $brackets = array( '{', '}' ), $match_start_pos, true );
+ $stream, array( '{', '}' ), $match_start_pos, true );
if ( ! $curly_match || empty( $raw_argument ) ) {
// Couldn't match the block
View
4 lib/Regex.php
@@ -50,6 +50,10 @@ public static function init () {
\{([^{}]*)\} # The declaration block
!xS';
+ // Balanced bracket matching.
+ $patt->balancedParens = '!\( (?: (?: (?>[^()]+) | (?R) )* ) \)!xS';
+ $patt->balancedCurlies = '!\{ (?: (?: (?>[^{}]+) | (?R) )* ) \}!xS';
+
// Tokens
$patt->commentToken = '!___c\d+___!';
$patt->stringToken = '!___s\d+___!';
View
108 lib/Util.php
@@ -178,71 +178,41 @@ public static function splitDelimList ( $str, $delim, $fold_in = false, $trim =
}
- public static function matchBrackets ( $str, $brackets = array( '(', ')' ), $search_pos = 0, $capture_text = false ) {
+ public static function matchBrackets ( $str, $brackets = array( '(', ')' ), $offset = 0, $capture_text = false ) {
list( $opener, $closer ) = $brackets;
- $openings = array();
- $closings = array();
- $brake = 50; // Set a limit in the case of errors
$match = (object) array();
- $start_index = strpos( $str, $opener, $search_pos );
- $close_index = strpos( $str, $closer, $search_pos );
-
- if ( $start_index === false ) {
-
+ if ( strpos( $str, $opener, $offset ) === false ) {
return false;
}
- if ( substr_count( $str, $opener ) !== substr_count( $str, $closer ) ) {
- $sample = substr( $str, 0, 25 );
+ if ( substr_count( $str, $opener ) !== substr_count( $str, $closer ) ) {
+ $sample = substr( $str, 0, 25 );
trigger_error( __METHOD__ . ": Unmatched token near '$sample'.\n", E_USER_WARNING );
return false;
}
- while (
- ( $start_index !== false || $close_index !== false ) && $brake--
- ) {
- if ( $start_index !== false && $close_index !== false ) {
- $search_pos = min( $start_index, $close_index );
- if ( $start_index < $close_index ) {
- $openings[] = $start_index;
- }
- else {
- $closings[] = $close_index;
- }
- }
- elseif ( $start_index !== false ) {
- $search_pos = $start_index;
- $openings[] = $start_index;
- }
- else {
- $search_pos = $close_index;
- $closings[] = $close_index;
- }
- $search_pos += 1; // Advance
-
- if ( count( $closings ) === count( $openings ) ) {
+ $patt = csscrush_regex::$patt->balancedParens;
+ if ( $opener === '{' ) {
+ $patt = csscrush_regex::$patt->balancedCurlies;
+ }
- $match->openings = $openings;
- $match->start = $start = $openings[0];
- $match->closings = $closings;
- $match->end = $closings[ count( $closings ) - 1 ] + 1;
+ if ( preg_match( $patt, $str, $m, PREG_OFFSET_CAPTURE, $offset ) ) {
- if ( $capture_text ) {
- // Text capturing is optional to avoid using memory when not necessary
- $match->inside = substr( $str, $start + 1, $match->end - $start - 2 );
- $match->after = substr( $str, $match->end );
- }
+ $match->start = $start = $m[0][1];
+ $match->end = $start + strlen( $m[0][0] );
- return $match;
+ if ( $capture_text ) {
+ // Text capturing is optional to avoid using memory when not necessary.
+ $match->inside = substr( $str, $start + 1, $match->end - $start - 2 );
+ $match->after = substr( $str, $match->end );
}
- $start_index = strpos( $str, $opener, $search_pos );
- $close_index = strpos( $str, $closer, $search_pos );
+ return $match;
}
- trigger_error( __METHOD__ . ": Reached brake limit of '$brake'. Exiting.\n", E_USER_WARNING );
+ trigger_error( __METHOD__ . ": Could not match '$opener'. Exiting.\n", E_USER_WARNING );
return false;
}
@@ -250,45 +220,25 @@ public static function matchBrackets ( $str, $brackets = array( '(', ')' ), $sea
public static function matchAllBrackets ( $str, $pair = '()', $offset = 0 ) {
$match_obj = (object) array();
- $match_obj->string = $str;
- $match_obj->raw = $str;
$match_obj->matches = array();
list( $opener, $closer ) = str_split( $pair, 1 );
- // Return early if there's no match
- if ( false === ( $first_offset = strpos( $str, $opener, $offset ) ) ) {
+ // Return early if there's no match.
+ if ( false === strpos( $str, $opener, $offset ) ) {
+ $match_obj->string = $str;
return $match_obj;
}
- // Step through the string one character at a time storing offsets
- $paren_score = -1;
- $inside_paren = false;
- $match_start = 0;
- $offsets = array();
-
- for ( $index = $first_offset; $index < strlen( $str ); $index++ ) {
- $char = $str[ $index ];
-
- if ( $opener === $char ) {
- if ( ! $inside_paren ) {
- $paren_score = 1;
- $match_start = $index;
- }
- else {
- $paren_score++;
- }
- $inside_paren = true;
- }
- elseif ( $closer === $char ) {
- $paren_score--;
- }
+ $patt = csscrush_regex::$patt->balancedParens;
+ if ( $opener === '{' ) {
+ $patt = csscrush_regex::$patt->balancedCurlies;
+ }
- if ( 0 === $paren_score ) {
- $inside_paren = false;
- $paren_score = -1;
- $offsets[] = array( $match_start, $index + 1 );
- }
+ // Match balanced bracket pairs.
+ $offsets = array();
+ foreach ( csscrush_regex::matchAll( $patt, $str ) as $m ) {
+ $offsets[] = array( $m[0][1], $m[0][1] + strlen( $m[0][0] ) );
}
// Step backwards through the matches
@@ -304,7 +254,7 @@ public static function matchAllBrackets ( $str, $pair = '()', $offset = 0 ) {
$str = $before . $label . $after;
$match_obj->matches[] = $label;
- // Parens will be folded in later
+ // Parens will be folded in later.
csscrush::$storage->tokens->parens[ $label ] = $content;
}

0 comments on commit 041b1e5

Please sign in to comment.
Something went wrong with that request. Please try again.