You are here

private function SassRuleNode::mergeSequence in Sassy 7.3

Same name and namespace in other branches
  1. 7 phamlp/sass/tree/SassRuleNode.php \SassRuleNode::mergeSequence()

Merges selector sequences

Parameters

string the extender selector:

string selector to extend:

Return value

array the merged sequences

1 call to SassRuleNode::mergeSequence()
SassRuleNode::extend in phpsass/tree/SassRuleNode.php
Extend this nodes selectors $extendee is the subject of the @extend directive $extender is the selector that contains the @extend directive $selector a selector or selector sequence that is to be extended

File

phpsass/tree/SassRuleNode.php, line 169

Class

SassRuleNode
SassRuleNode class. Represents a CSS rule. @package PHamlP @subpackage Sass.tree

Code

private function mergeSequence($extender, $selector) {
  $extender = explode(' ', $extender);
  $end = array_pop($extender);
  $selector = explode(' ', $selector);
  array_pop($selector);
  $common = array();
  if (count($extender) && count($selector)) {
    while (trim($extender[0]) === trim($selector[0])) {
      $common[] = array_shift($selector);
      array_shift($extender);
      if (!count($extender)) {
        break;
      }
    }
  }
  $begining = !empty($common) ? join(' ', $common) . ' ' : '';

  # Richard Lyon - 2011-10-25 - removes duplicates by uniquing and trimming.

  # regex removes whitespace from start and and end of string as well as removing

  # whitespace following whitespace. slightly quicker than a trim and simpler replace
  return array_unique(array(
    preg_replace('/(^\\s+|(\\s)\\s+|\\s+$)/', '$2', $begining . join(' ', $selector) . ' ' . join(' ', $extender) . ' ' . $end),
    preg_replace('/(^\\s+|(\\s)\\s+|\\s+$)/', '$2', $begining . join(' ', $extender) . ' ' . join(' ', $selector) . ' ' . $end),
  ));
}