Esempio n. 1
0
 /**
  * @covers generateCss
  */
 public function testGenerateCss()
 {
     $env = new Context();
     $output = new StandardOutput();
     $s = new SelectorNode([new ElementNode('', 'foobar')], []);
     $s->generateCss($env, $output);
     $this->assertEquals(" foobar", $output->toString());
 }
Esempio n. 2
0
 /**
  * Format arguments to be used for exception message.
  *
  * @param array $args
  *
  * @return string
  */
 private function formatArgs($args)
 {
     $context = new Context();
     $message = $argsFormatted = [];
     $message[] = trim($this->selector->toCSS($context));
     if ($args) {
         $message[] = '(';
         foreach ($args as $a) {
             $argValue = '';
             if (isset($a['name'])) {
                 $argValue .= $a['name'] . ':';
             }
             if ($a['value'] instanceof GenerateCSSInterface) {
                 $argValue .= $a['value']->toCSS($context);
             } else {
                 $argValue .= '???';
             }
             $argsFormatted[] = $argValue;
         }
         $message[] = implode(', ', $argsFormatted);
         $message[] = ')';
     }
     return implode('', $message);
 }
Esempio n. 3
0
 /**
  * Matches with other node?
  *
  * @param SelectorNode $other
  * @return integer
  */
 public function match(SelectorNode $other)
 {
     $other->cacheElements();
     $count = count($this->elements);
     $olen = count($other->cachedElements);
     if ($olen === 0 || $count < $olen) {
         return 0;
     } else {
         for ($i = 0; $i < $olen; $i++) {
             if ($this->elements[$i]->value !== $other->cachedElements[$i]) {
                 return 0;
             }
         }
     }
     return $olen;
     // return number of matched elements
 }
Esempio n. 4
0
 /**
  * @param $beginningPath
  * @param $addPath
  * @param ElementNode $replacedElement
  * @param SelectorNode $originalSelector
  *
  * @return array
  */
 private function addReplacementIntoPath($beginningPath, $addPath, ElementNode $replacedElement, SelectorNode $originalSelector)
 {
     // our new selector path
     $newSelectorPath = [];
     // construct the joined selector - if & is the first thing this will be empty,
     // if not newJoinedSelector will be the last set of elements in the selector
     if (count($beginningPath) > 0) {
         $newSelectorPath = $beginningPath;
         $lastSelector = array_pop($newSelectorPath);
         $newJoinedSelector = $originalSelector->createDerived($lastSelector->elements);
     } else {
         $newJoinedSelector = $originalSelector->createDerived([]);
     }
     if (count($addPath) > 0) {
         $combinator = $replacedElement->combinator;
         $parentEl = $addPath[0]->elements[0];
         /* @var $parentEl ElementNode */
         if ($combinator->emptyOrWhitespace && !$parentEl->combinator->emptyOrWhitespace) {
             $combinator = $parentEl->combinator;
         }
         $newJoinedSelector->elements[] = new ElementNode($combinator, $parentEl->value, $replacedElement->index, $replacedElement->currentFileInfo);
         $newJoinedSelector->elements = array_merge($newJoinedSelector->elements, array_slice($addPath[0]->elements, 1));
     }
     // now add the joined selector - but only if it is not empty
     if (count($newJoinedSelector->elements) !== 0) {
         $newSelectorPath[] = $newJoinedSelector;
     }
     if (count($addPath) > 1) {
         $newSelectorPath = array_merge($newSelectorPath, array_slice($addPath, 1));
     }
     return $newSelectorPath;
 }
Esempio n. 5
0
 /**
  * Constructor.
  *
  * @param string $name The name
  * @param array|string $value The value
  * @param RulesetNode|null|array $rules
  * @param int $index The index
  * @param FileInfo $currentFileInfo Current file info
  * @param DebugInfo $debugInfo The debug information
  * @param bool $isReferenced Is referenced?
  * @param bool $isRooted Is rooted?
  */
 public function __construct($name, $value, $rules = null, $index = 0, FileInfo $currentFileInfo = null, DebugInfo $debugInfo = null, $isReferenced = false, $isRooted = false)
 {
     $this->name = $name;
     parent::__construct($value);
     if (null !== $rules) {
         if (is_array($rules)) {
             $this->rules = $rules;
         } else {
             $this->rules = [$rules];
             $selectors = new SelectorNode([], [], null, $index, $currentFileInfo);
             $this->rules[0]->selectors = $selectors->createEmptySelectors();
         }
         for ($i = 0; $i < count($this->rules); ++$i) {
             $this->rules[$i]->allowImports = true;
         }
     } else {
         // null
         $this->rules = $rules;
     }
     $this->index = $index;
     $this->currentFileInfo = $currentFileInfo;
     $this->debugInfo = $debugInfo;
     $this->isReferenced = $isReferenced;
     $this->isRooted = $isRooted;
 }
Esempio n. 6
0
 /**
  * Compiles top media
  *
  * @param Context $context
  * @return RulesetNode
  */
 public function compileTop(Context $context)
 {
     $result = $this;
     if (count($context->mediaBlocks) > 1) {
         $selector = new SelectorNode([], [], null, $this->index, $this->currentFileInfo);
         $selectors = $selector->createEmptySelectors();
         $result = new RulesetNode($selectors, $context->mediaBlocks);
         $result->multiMedia = true;
     }
     $context->mediaBlocks = [];
     $context->mediaPath = [];
     return $result;
 }
Esempio n. 7
0
 /**
  * Compiles the node
  *
  * @param Context $context The context
  * @param array|null $arguments Array of arguments
  * @param boolean|null $important Important flag
  * @return ExtendNode
  */
 public function compile(Context $context, $arguments = null, $important = null)
 {
     return new ExtendNode($this->selector->compile($context), $this->option, $this->index);
 }