Skip to content

Commit

Permalink
Some updates to the command line application, a little cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
peteboere committed Feb 10, 2012
1 parent 0c51ab0 commit a2c46f8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
3 changes: 3 additions & 0 deletions Aliases.ini
Expand Up @@ -201,6 +201,9 @@
calc[] = -webkit-calc calc[] = -webkit-calc
calc[] = -moz-calc calc[] = -moz-calc


; Element
element[] = -moz-element

; Gradients ; Gradients
linear-gradient[] = -webkit-linear-gradient linear-gradient[] = -webkit-linear-gradient
linear-gradient[] = -moz-linear-gradient linear-gradient[] = -moz-linear-gradient
Expand Down
34 changes: 23 additions & 11 deletions cli.php
Expand Up @@ -133,14 +133,6 @@
exit( 1 ); 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 ## Processing
Expand All @@ -159,17 +151,37 @@


$import_context = $input_file ? dirname( realpath( $input_file ) ) : null; $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 ## Output


if ( $output_file ) { 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 { else {
fwrite( $stdout, $output . "\n" ); $output .= "\n";
fwrite( $stdout, $output );
} }
exit( 1 ); exit( 1 );


Expand Down
12 changes: 8 additions & 4 deletions lib/Core.php
Expand Up @@ -361,17 +361,16 @@ public static function inline ( $file, $options = null, $attributes = array() )
* *
* @param string $string CSS text * @param string $string CSS text
* @param mixed $options An array of options or null * @param mixed $options An array of options or null
* @param string $import_context A context path for imports
* @return string CSS text * @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 // Reset for current process
self::reset(); self::reset();
self::getOptions( $options ); self::getOptions( $options );


// Set the path context if one is given // Set the path context if one is given
if ( $import_context ) { if ( isset( $options[ 'import_context' ] ) && ! empty( $options[ 'import_context' ] ) ) {
self::setPath( $import_context ); self::setPath( $options[ 'import_context' ] );
} }


// It's not associated with a real file so we create an 'empty' hostfile object // It's not associated with a real file so we create an 'empty' hostfile object
Expand All @@ -380,6 +379,11 @@ public static function string ( $string, $options = null, $import_context = null
// Set the string on the object // Set the string on the object
$hostfile->string = $string; $hostfile->string = $string;


// Import files may be ignored
if ( isset( $options[ 'no_import' ] ) ) {
$hostfile->importIgnore = true;
}

// Collate imports // Collate imports
$stream = csscrush_importer::hostfile( $hostfile ); $stream = csscrush_importer::hostfile( $hostfile );


Expand Down
6 changes: 2 additions & 4 deletions lib/Function.php
Expand Up @@ -335,10 +335,8 @@ public static function css_fn__data_uri ( $input ) {
$mime_type = $allowed_file_extensions[ $file_ext ]; $mime_type = $allowed_file_extensions[ $file_ext ];
$base64 = base64_encode( file_get_contents( $file ) ); $base64 = base64_encode( file_get_contents( $file ) );
$data_uri = "data:{$mime_type};base64,$base64"; $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 ) { public static function css_fn__h_adjust ( $input ) {
Expand Down
6 changes: 6 additions & 0 deletions lib/Importer.php
Expand Up @@ -64,6 +64,12 @@ public static function hostfile ( $hostfile ) {
$preStatement = substr( $stream, 0, $matchStart ); $preStatement = substr( $stream, 0, $matchStart );
$postStatement = substr( $stream, $matchEnd ); $postStatement = substr( $stream, $matchEnd );


// If just stripping the import statements
if ( isset( $hostfile->importIgnore ) ) {
$stream = $preStatement . $postStatement;
continue;
}

$url = trim( $match[1][0] ); $url = trim( $match[1][0] );


// Url may be a string token // Url may be a string token
Expand Down

0 comments on commit a2c46f8

Please sign in to comment.