Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 7 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
Commits on Nov 08, 2011
@peteboere Updated changelog a1a38ca
Commits on Nov 09, 2011
@peteboere Merge branch 'test' da4b97b
Commits on Jan 24, 2012
@peteboere Merge branch 'test' 43d1e00
Commits on Feb 10, 2012
@peteboere Some updates to the command line application, a little cleaning up a2c46f8
@peteboere Merge branch 'test'
* test:
  Some updates to the command line application, a little cleaning up
  Added command line application
d729cf8
Commits on Mar 12, 2012
@peteboere Fixed bug in the import regexp, minor underhood change to the cli app…
…lication
f181508
Commits on Mar 14, 2012
@peteboere Tweaking comments, bumped version string to 1.4.2, updated changelog 0084fed
View
3  Aliases.ini
@@ -201,6 +201,9 @@
calc[] = -webkit-calc
calc[] = -moz-calc
+ ; Element
+ element[] = -moz-element
+
; Gradients
linear-gradient[] = -webkit-linear-gradient
linear-gradient[] = -moz-linear-gradient
View
6 CHANGELOG
@@ -1,3 +1,9 @@
+1.4.2
+-----
+Fixed bug with @import statement parsing
+Some minor under the hood changes
+
+
1.4.1
-----
Added command line application
View
2  CssCrush.php
@@ -4,7 +4,7 @@
* CSS Crush
* Extensible CSS preprocessor
*
- * @version 1.4.1
+ * @version 1.4.2
* @license http://www.opensource.org/licenses/mit-license.php (MIT)
* @copyright Copyright 2010-2012 Pete Boere
*
View
42 cli.php
@@ -7,14 +7,12 @@
require_once 'CssCrush.php';
-// error_reporting('-1');
-
-// stdin
+// Get stdin input
$stdin = fopen( 'php://stdin', 'r' );
-stream_set_blocking( $stdin, false ) or die ( 'Failed to disable stdin blocking' );
$stdin_contents = stream_get_contents( $stdin );
+fclose( $stdin );
-// stdout
+// Open stdout handle
$stdout = fopen( 'php://stdout', 'w' );
@@ -133,14 +131,6 @@
exit( 1 );
}
-// Check if specified output file is valid before processing
-if ( $output_file ) {
- if ( ! file_exists( $output_file ) ) {
- fwrite( $stdout, "can't find output file\n\n" );
- exit( 0 );
- }
-}
-
##################################################################
## Processing
@@ -159,17 +149,37 @@
$import_context = $input_file ? dirname( realpath( $input_file ) ) : null;
-$output = csscrush::string( $input, $process_opts, $import_context );
+// If there is an import context set it to the document root
+if ( $import_context ) {
+ $old_doc_root = csscrush::$config->docRoot;
+ csscrush::$config->docRoot = $import_context;
+ $process_opts[ 'import_context' ] = $import_context;
+}
+
+// Process the stream
+$output = csscrush::string( $input, $process_opts );
+
+// Reset the document root after processing
+if ( $import_context ) {
+ csscrush::$config->docRoot = $old_doc_root;
+}
##################################################################
## Output
if ( $output_file ) {
- file_put_contents( $output_file, $output );
+ if ( ! @file_put_contents( $output_file, $output ) ) {
+ fwrite( $stdout, "Could not write to path '$output_file'\n" );
+ if ( strpos( $output_file, '~' ) === 0 ) {
+ fwrite( $stdout, "No tilde expansion\n" );
+ }
+ exit( 0 );
+ }
}
else {
- fwrite( $stdout, $output . "\n" );
+ $output .= "\n";
+ fwrite( $stdout, $output );
}
exit( 1 );
View
20 lib/Core.php
@@ -37,7 +37,11 @@ class csscrush {
public static $regex = array(
'import' => '!
@import\s+ # import at-rule
- (?:url)?\s*\(?\s*[\'"]?([^\'"\);]+)[\'"]?\s*\)? # url or quoted string
+ (?:
+ url\(\s*([^\)]+)\s*\) # url function
+ | # or
+ ([_s\d]+) # string token
+ )
\s*([^;]*);? # media argument
!x',
'variables' => '!@(?:variables|define)\s*([^\{]*)\{\s*(.*?)\s*\};?!s',
@@ -317,7 +321,7 @@ public static function tag ( $file, $options = null, $attributes = array() ) {
$attributes[ 'rel' ] = "stylesheet";
$attributes[ 'href' ] = $file;
$attr_string = csscrush_util::htmlAttributes( $attributes );
- return "<link $attr_string />\n";
+ return "<link$attr_string />\n";
}
else {
// Return an HTML comment with message on failure
@@ -361,17 +365,16 @@ public static function inline ( $file, $options = null, $attributes = array() )
*
* @param string $string CSS text
* @param mixed $options An array of options or null
- * @param string $import_context A context path for imports
* @return string CSS text
*/
- public static function string ( $string, $options = null, $import_context = null ) {
+ public static function string ( $string, $options = null ) {
// Reset for current process
self::reset();
self::getOptions( $options );
// Set the path context if one is given
- if ( $import_context ) {
- self::setPath( $import_context );
+ if ( isset( $options[ 'import_context' ] ) && ! empty( $options[ 'import_context' ] ) ) {
+ self::setPath( $options[ 'import_context' ] );
}
// It's not associated with a real file so we create an 'empty' hostfile object
@@ -380,6 +383,11 @@ public static function string ( $string, $options = null, $import_context = null
// Set the string on the object
$hostfile->string = $string;
+ // Import files may be ignored
+ if ( isset( $options[ 'no_import' ] ) ) {
+ $hostfile->importIgnore = true;
+ }
+
// Collate imports
$stream = csscrush_importer::hostfile( $hostfile );
View
6 lib/Function.php
@@ -335,10 +335,8 @@ public static function css_fn__data_uri ( $input ) {
$mime_type = $allowed_file_extensions[ $file_ext ];
$base64 = base64_encode( file_get_contents( $file ) );
$data_uri = "data:{$mime_type};base64,$base64";
- if ( strlen( $data_uri ) > 32000 ) {
- // Too big for IE
- }
- return "url($data_uri)";
+
+ return "url(\"$data_uri\")";
}
public static function css_fn__h_adjust ( $input ) {
View
22 lib/Importer.php
@@ -57,24 +57,34 @@ public static function hostfile ( $hostfile ) {
// Recurses until the nesting heirarchy is flattened and all files are combined
while ( preg_match( $regex->import, $stream, $match, PREG_OFFSET_CAPTURE, $searchOffset ) ) {
- $fullMatch = $match[0][0]; // Full match
- $matchStart = $match[0][1]; // Full match offset
+ $fullMatch = $match[0][0]; // Full match
+ $matchStart = $match[0][1]; // Full match offset
$matchEnd = $matchStart + strlen( $fullMatch );
- $mediaContext = trim( $match[2][0] ); // The media context if specified
$preStatement = substr( $stream, 0, $matchStart );
$postStatement = substr( $stream, $matchEnd );
+ // If just stripping the import statements
+ if ( isset( $hostfile->importIgnore ) ) {
+ $stream = $preStatement . $postStatement;
+ continue;
+ }
+
+ // The media context (if specified) at position 3 in the match
+ $mediaContext = trim( $match[3][0] );
+
+ // The url may be at position 1 or 2 in the match depending on the syntax used
$url = trim( $match[1][0] );
+ if ( ! $url ) {
+ $url = trim( $match[2][0] );
+ }
// Url may be a string token
if ( preg_match( $regex->token->string, $url ) ) {
$import_url_token = new csscrush_string( $url );
$url = $import_url_token->value;
- // $import_url_token = csscrush::$storage->tokens->strings[ $url ];
- // $url = trim( $import_url_token, '\'"' );
}
- // csscrush::log( $url );
+ // csscrush::log( $match );
// Pass over absolute urls
// Move the search pointer forward

No commit comments for this range

Something went wrong with that request. Please try again.