public function __construct($rawSelector) { // Look for rooting prefix. if (strpos($rawSelector, '^') === 0) { $rawSelector = ltrim($rawSelector, "^ \n\r\t"); $this->allowPrefix = false; } $this->readableValue = Selector::makeReadable($rawSelector); $this->value = Selector::expandAliases($rawSelector); }
public function __construct($name) { $this->name = $name; if (!preg_match(Regex::$patt->rooted_ident, $this->name)) { // Not a regular name: Some kind of selector so normalize it for later comparison. $this->name = Selector::makeReadable($this->name); // If applying the pseudo on output store. if (substr($this->name, -1) === '!') { $this->name = rtrim($this->name, ' !'); if (preg_match('~\\:\\:?[\\w-]+$~', $this->name, $m)) { $this->pseudo = $m[0]; } } } }
public static function call($message, $context = null) { $process = Crush::$process; $mixable = null; $message = trim($message); // Test for mixin or abstract rule. e.g: // named-mixin( 50px, rgba(0,0,0,0), left 100% ) // abstract-rule if (preg_match(Regex::make('~^(?<name>{{ident}}) {{parens}}?~xS'), $message, $message_match)) { $name = $message_match['name']; if (isset($process->mixins[$name])) { $mixable = $process->mixins[$name]; } elseif (isset($process->references[$name])) { $mixable = $process->references[$name]; } } // If no mixin or abstract rule matched, look for matching selector if (!$mixable) { $selector_test = Selector::makeReadable($message); if (isset($process->references[$selector_test])) { $mixable = $process->references[$selector_test]; } } // Avoid infinite recursion. if (!$mixable || $mixable === $context) { return false; } elseif ($mixable instanceof Mixin) { $args = array(); $raw_args = isset($message_match['parens_content']) ? trim($message_match['parens_content']) : null; if ($raw_args) { $args = Util::splitDelimList($raw_args); } return DeclarationList::parse($mixable->template->__invoke($args), array('flatten' => true, 'context' => $mixable)); } elseif ($mixable instanceof Rule) { return $mixable->declarations->store; } }
function fn__query($input, $context) { $args = Functions::parseArgs($input); // Context property is required. if (!count($args) || !isset($context->property)) { return ''; } list($target, $property, $fallback) = $args + array(null, $context->property, null); if (strtolower($property) === 'default') { $property = $context->property; } if (!preg_match(Regex::$patt->rooted_ident, $target)) { $target = Selector::makeReadable($target); } $targetRule = null; $references =& Crush::$process->references; switch (strtolower($target)) { case 'parent': $targetRule = $context->rule->parent; break; case 'previous': $targetRule = $context->rule->previous; break; case 'next': $targetRule = $context->rule->next; break; case 'top': $targetRule = $context->rule->parent; while ($targetRule && $targetRule->parent && ($targetRule = $targetRule->parent)) { } break; default: if (isset($references[$target])) { $targetRule = $references[$target]; } break; } $result = ''; if ($targetRule) { $targetRule->declarations->process(); $targetRule->declarations->expandData('queryData', $property); if (isset($targetRule->declarations->queryData[$property])) { $result = $targetRule->declarations->queryData[$property]; } } if ($result === '' && isset($fallback)) { $result = $fallback; } return $result; }