Permalink
Browse files

Mixin and fragment arg() function can now be nested

query() can now reference mixins
Updated composer.json and Changelog
  • Loading branch information...
1 parent b88638b commit 83542a3079395f2ebe501f6811accd1f2a90ae3a @peteboere committed Aug 1, 2012
Showing with 67 additions and 26 deletions.
  1. +4 −1 CHANGELOG.txt
  2. +1 −1 CssCrush.php
  3. +15 −2 composer.json
  4. +26 −10 lib/Mixin.php
  5. +2 −1 lib/Regex.php
  6. +19 −11 lib/Rule.php
View
@@ -1,8 +1,11 @@
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 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
View
@@ -7,7 +7,7 @@
* @version 1.6
* @link https://github.com/peteboere/css-crush
* @license http://www.opensource.org/licenses/mit-license.php (MIT)
- * @copyright Copyright 2010-2012 Pete Boere
+ * @copyright (c) 2010-2012 Pete Boere
*
*/
View
@@ -1,11 +1,24 @@
{
- "name": "CssCrush/CssCrush",
+ "name": "css-crush/css-crush",
"type": "library",
"description": "CSS preprocessor",
"keywords": ["css", "preprocessor"],
"homepage": "http://github.com/peteboere/css-crush",
"license": "MIT",
+ "authors": [
+ {
+ "name": "Pete Boere",
+ "email": "pete@the-echoplex.net"
+ },
+ {
+ "name": "GitHub contributors",
+ "homepage": "https://github.com/peteboere/css-crush/contributors"
+ }
+ ],
"require": {
- "php": ">=5.12"
+ "php": ">=5.2.4"
+ },
+ "autoload": {
+ "files": ["CssCrush.php"]
}
}
View
@@ -11,6 +11,8 @@ class csscrush_mixin {
public $arguments;
+ public $data = array();
+
public function __construct ( $block ) {
// Strip comment markers
@@ -51,6 +53,14 @@ public function __construct ( $block ) {
$this->declarationsTemplate[] = $declaration;
}
}
+
+ // Create data table for the mixin.
+ // Values that use arg() are excluded
+ foreach ( $this->declarationsTemplate as &$declaration ) {
+ if ( ! preg_match( csscrush_regex::$patt->argToken, $declaration['value'] ) ) {
+ $this->data[ $declaration['property'] ] = $declaration['value'];
+ }
+ }
return '';
}
@@ -145,7 +155,6 @@ public static function parseSingleValue ( $message ) {
$args = array();
if ( $message !== '' ) {
$args = csscrush_util::splitDelimList( $message, ',', true, true );
- // $args = array_map( 'trim', $args->list );
$args = $args->list;
}
@@ -265,9 +274,22 @@ public function store ( $raw_argument ) {
return "___arg{$position_match}___";
}
- public function getDefaultValue ( $index ) {
+ public function getArgValue ( $index, &$args ) {
+
+ // First lookup a passed value
+ if ( isset( $args[ $index ] ) && $args[ $index ] !== 'default' ) {
+ return $args[ $index ];
+ }
+
+ // Get a default value
+ $default = isset( $this->defaults[ $index ] ) ? $this->defaults[ $index ] : '';
- return isset( $this->defaults[ $index ] ) ? $this->defaults[ $index ] : '';
+ // Recurse for nested arg() calls
+ if ( preg_match( csscrush_regex::$patt->argToken, $default, $m ) ) {
+
+ $default = $this->getArgValue( (int) $m[1], $args );
+ }
+ return $default;
}
public function getSubstitutions ( $args ) {
@@ -281,13 +303,7 @@ public function getSubstitutions ( $args ) {
foreach ( $argIndexes as $index ) {
$find[] = "___arg{$index}___";
-
- if ( isset( $args[ $index ] ) && $args[ $index ] !== 'default' ) {
- $replace[] = $args[ $index ];
- }
- else {
- $replace[] = $this->getDefaultValue( $index );
- }
+ $replace[] = $this->getArgValue( $index, $args );
}
return array( $find, $replace );
View
@@ -56,6 +56,7 @@ public static function init () {
$patt->ruleToken = '!___r\d+___!';
$patt->parenToken = '!___p\d+___!';
$patt->urlToken = '!___u\d+___!';
+ $patt->argToken = '!___arg(\d+)___!';
// Functions
$patt->varFunction = '!(?:
@@ -68,8 +69,8 @@ public static function init () {
// Specific functions
$patt->argFunction = csscrush_regex::createFunctionMatchPatt( array( 'arg' ) );
+ $patt->queryFunction = csscrush_regex::createFunctionMatchPatt( array( 'query' ) );
$patt->thisFunction = csscrush_regex::createFunctionMatchPatt( array( 'this' ) );
- $patt->referenceFunction = csscrush_regex::createFunctionMatchPatt( array( 'this', 'query' ) );
// Misc.
$patt->vendorPrefix = '!^-([a-z]+)-([a-z-]+)!';
View
@@ -33,6 +33,15 @@ public function declarationCheckin ( $prop, $value, &$pairs ) {
if ( $prop !== '' && $value !== '' ) {
+ // First resolve query() calls that reference earlier rules
+ if ( preg_match( csscrush_regex::$patt->queryFunction, $value ) ) {
+
+ csscrush_function::executeCustomFunctions( $value,
+ csscrush_regex::$patt->queryFunction, array(
+ 'query' => array( $this, 'cssQueryFunction' ),
+ ), $prop );
+ }
+
if ( strpos( $prop, 'data-' ) === 0 ) {
// If it's with data prefix, we don't want to print it
@@ -57,10 +66,7 @@ public function declarationCheckin ( $prop, $value, &$pairs ) {
if ( preg_match( csscrush_regex::$patt->thisFunction, $value ) ) {
unset( $this->localData[ $prop ] );
-
- if ( isset( $this->data[ $prop ] ) ) {
- unset( $this->data[ $prop ] );
- }
+ unset( $this->data[ $prop ] );
}
}
}
@@ -146,7 +152,7 @@ public function __construct ( $selector_string = null, $declarations_string ) {
}
elseif ( $prop === 'extends' ) {
- // Extends is a special case
+ // Extends are also a special case
$this->setExtendSelectors( $value );
}
else {
@@ -160,11 +166,10 @@ public function __construct ( $selector_string = null, $declarations_string ) {
list( $prop, $value ) = $pair;
- // Resolve this() references
+ // Resolve self references, aka this()
csscrush_function::executeCustomFunctions( $value,
- csscrush_regex::$patt->referenceFunction, array(
+ csscrush_regex::$patt->thisFunction, array(
'this' => array( $this, 'cssThisFunction' ),
- 'query' => array( $this, 'cssQueryFunction' ),
), $prop );
if ( trim( $value ) !== '' ) {
@@ -174,8 +179,6 @@ public function __construct ( $selector_string = null, $declarations_string ) {
$this->addDeclaration( $prop, $value );
}
}
- // csscrush::log( $this->localData, 'LocalData' );
- // csscrush::log( $this->data, 'Data' );
// localData no longer required
$this->localData = null;
@@ -226,6 +229,7 @@ public function cssQueryFunction ( $input, $fn_name, $call_property ) {
}
$abstracts =& csscrush::$process->abstracts;
+ $mixins =& csscrush::$process->mixins;
$selectorRelationships =& csscrush::$process->selectorRelationships;
// Resolve arguments
@@ -246,11 +250,15 @@ public function cssQueryFunction ( $input, $fn_name, $call_property ) {
// Try to match a abstract rule first
if ( preg_match( csscrush_regex::$patt->name, $name ) ) {
- // Search order: abstracts, rules
+ // Search order: abstracts, mixins, rules
if ( isset( $abstracts[ $name ]->data[ $property ] ) ) {
$result = $abstracts[ $name ]->data[ $property ];
}
+ elseif ( isset( $mixins[ $name ]->data[ $property ] ) ) {
+
+ $result = $mixins[ $name ]->data[ $property ];
+ }
elseif ( isset( $selectorRelationships[ $name ]->data[ $property ] ) ) {
$result = $selectorRelationships[ $name ]->data[ $property ];

0 comments on commit 83542a3

Please sign in to comment.