Skip to content
Browse files

Added support for SASS-like @include/@extend syntax for invoking mixi…

…ns and extends inside rules.

csscrush::string() now uses document_root as a default context for finding linked resources.
Boilerplate option now accepts a filename string.
  • Loading branch information...
1 parent b13156e commit 49c7de1b99c29870bbb2ff6047acae100f1e5879 @peteboere committed Sep 10, 2012
Showing with 61 additions and 19 deletions.
  1. +8 −2 CHANGELOG.txt
  2. +3 −0 Plugins.ini
  3. +30 −9 lib/Core.php
  4. +16 −8 lib/Rule.php
  5. +2 −0 misc/initial-values.ini
  6. +2 −0 misc/property-sorting.ini
View
10 CHANGELOG.txt
@@ -1,8 +1,14 @@
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
-Minor update to command line appication
-Updated aliases file
1.6.1
View
3 Plugins.ini
@@ -6,6 +6,9 @@
;
;----------------------------------------------------------------
+; Property sorting
+; plugins[] = property-sorter
+
; min-height shim for IE < 7
; plugins[] = ie-min-height
View
39 lib/Core.php
@@ -299,10 +299,10 @@ public static function file ( $file, $options = null ) {
}
}
- // Collate hostfile and imports
+ // Collate hostfile and imports.
$stream = csscrush_importer::hostfile( $process->input );
- // Compile
+ // Compile.
$stream = self::compile( $stream );
// Create file and return url. Return empty string on failure
@@ -413,12 +413,16 @@ public static function string ( $string, $options = null ) {
$process = self::$process;
$options = $process->options;
- // Set the path context if one is given
- if ( isset( $options->context ) && ! empty( $options->context ) ) {
+ // Set the path context if one is given.
+ // Fallback to document root.
+ if ( ! empty( $options->context ) ) {
self::setPath( $options->context );
}
+ else {
+ self::setPath( $config->docRoot );
+ }
- // It's not associated with a real file so we create an 'empty' input object
+ // It's not associated with a real file so we create an 'empty' input object.
$process->input = csscrush::io_call( 'getInput' );
// Set the string on the object
@@ -525,9 +529,21 @@ public static function prepareStream ( &$stream ) {
protected static function getBoilerplate () {
- $file = csscrush_util::find( 'CssCrush-local.boilerplate', 'CssCrush.boilerplate' );
+ $file = false;
+ $boilerplate_option = self::$process->options->boilerplate;
+
+ if ( $boilerplate_option === true ) {
+ $file = csscrush_util::find(
+ 'CssCrush-local.boilerplate', 'CssCrush.boilerplate' );
+ }
+ elseif ( is_string( $boilerplate_option ) ) {
+ if ( file_exists( $boilerplate_option ) ) {
+ $file = $boilerplate_option;
+ }
+ }
- if ( ! $file || ! self::$process->options->boilerplate ) {
+ // Return an empty string if no file is found.
+ if ( ! $file ) {
return '';
}
@@ -1093,17 +1109,22 @@ public static function processRules () {
// Reset the selector relationships
self::$process->selectorRelationships = array();
+ $aliases =& self::$config->aliases;
+
foreach ( self::$storage->tokens->rules as $rule ) {
// Store selector relationships
$rule->indexSelectors();
csscrush_hook::run( 'rule_prealias', $rule );
- if ( ! empty( self::$config->aliases ) ) {
-
+ if ( ! empty( $aliases[ 'properties' ] ) ) {
$rule->addPropertyAliases();
+ }
+ if ( ! empty( $aliases[ 'functions' ] ) ) {
$rule->addFunctionAliases();
+ }
+ if ( ! empty( $aliases[ 'values' ] ) ) {
$rule->addValueAliases();
}
View
24 lib/Rule.php
@@ -114,7 +114,7 @@ public function __construct ( $selector_string = null, $declarations_string ) {
// Parse the declarations chunk
// Need to split safely as there are semi-colons in data-uris
- $declarations_match = csscrush_util::splitDelimList( $declarations_string, ';', true );
+ $declarations_match = csscrush_util::splitDelimList( $declarations_string, ';', true, true );
// First create a simple array of all properties and value pairs in raw state
$pairs = array();
@@ -125,16 +125,24 @@ public function __construct ( $selector_string = null, $declarations_string ) {
// Strip comments around the property
$declaration = csscrush_util::stripComments( $declaration );
- // Extract the property part of the declaration
- $colonPos = strpos( $declaration, ':' );
- if ( $colonPos === false ) {
+ // Accept several different syntaxes for mixin and extends.
+ if ( preg_match( '!^(?:(@include|mixin)|(@?extends?))[\s\:]+!iS', $declaration, $m ) ) {
- continue; // If there's no colon it's malformed
+ $prop = isset( $m[2] ) ? 'extends' : 'mixin';
+ $value = substr( $declaration, strlen( $m[0] ) );
}
- $prop = trim( substr( $declaration, 0, $colonPos ) );
+ elseif ( ( $colonPos = strpos( $declaration, ':' ) ) !== false ) {
- // Extract the value part of the declaration
- $value = substr( $declaration, $colonPos + 1 );
+ $prop = trim( substr( $declaration, 0, $colonPos ) );
+ // Extract the value part of the declaration.
+ $value = substr( $declaration, $colonPos + 1 );
+ }
+ else {
+ // Must be malformed.
+ continue;
+ }
+
+ // Some cleanup.
$value = $value !== false ? trim( $value ) : $value;
if ( $prop === 'mixin' ) {
View
2 misc/initial-values.ini
@@ -19,6 +19,8 @@ background-color = "transparent"
background-image = "none"
background-origin = "padding-box"
background-position = "0 0"
+background-position-x = "0"
+background-position-y = "0"
background-repeat = "repeat"
background-size = "auto auto"
border = "0"
View
2 misc/property-sorting.ini
@@ -98,6 +98,8 @@ background-image
background-color
background-repeat
background-position
+background-position-x
+background-position-y
background-origin
background-size
background-clip

0 comments on commit 49c7de1

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