Beispiel #1
0
 /**
  * @inheritdoc
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     if ($this->value === '%') {
         throw new Exception('Invalid % without number');
     }
     $output->add($this->value);
 }
Beispiel #2
0
 /**
  * @inheritdoc
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     if ($context->strictUnits && !$this->unit->isSingular()) {
         throw new CompilerException(sprintf('Multiple units in dimension. Correct the units or use the unit function. Bad unit: %s', $this->unit->toString()));
     }
     $value = Util::round($context, $this->value);
     $strValue = (string) $value;
     if ($value !== 0 && $value < 1.0E-6 && $value > -1.0E-6) {
         $strValue = Math::toFixed($value, 20);
     }
     // remove trailing zeros
     $strValue = Math::clean($strValue);
     // Zero values doesn't need a unit
     if ($context->compress) {
         if ($value == 0 && $this->unit->isLength()) {
             $output->add($strValue);
             return;
         }
         // Float values doesn't need a leading zero
         if ($value > 0 && $value < 1) {
             $strValue = substr($strValue, 1);
         }
     }
     $output->add($strValue);
     // pass to unit
     $this->unit->generateCSS($context, $output);
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     if ($this->debugInfo) {
         $output->add(self::getDebugInfo($context, $this), $this->currentFileInfo, $this->index);
     }
     $output->add($this->value);
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     $output->add($this->key . '=');
     if ($this->value instanceof GenerateCSSInterface) {
         $this->value->generateCSS($context, $output);
     } else {
         $output->add($this->value);
     }
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     $output->add('alpha(opacity=');
     if ($this->value instanceof GenerateCSSInterface) {
         $this->value->generateCSS($context, $output);
     } else {
         $output->add((string) $this->value);
     }
     $output->add(')');
 }
Beispiel #6
0
 /**
  * @inheritdoc
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     if (!$this->escaped) {
         $output->add($this->quote, $this->currentFileInfo, $this->index);
     }
     $output->add($this->value);
     if (!$this->escaped) {
         $output->add($this->quote);
     }
 }
Beispiel #7
0
 /**
  * Generate the CSS and put it in the output container
  *
  * @param Context $context The context
  * @param OutputInterface $output The output
  * @return void
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     $output->add($this->value);
 }
Beispiel #8
0
 /**
  * @inheritdoc
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     $spaceOrEmpty = $context->compress || isset($this->noSpaceCombinators[$this->value]) ? '' : ' ';
     $output->add($spaceOrEmpty . $this->value . $spaceOrEmpty);
 }
Beispiel #9
0
 /**
  * @inheritdoc
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     // handle IE filters, cannot accept shortened colors
     if (strpos($this->name, 'progid:') === 0) {
         $canShortenColors = $context->canShortenColors;
         $context->canShortenColors = false;
     }
     $output->add($this->name . '(', $this->currentFileInfo, $this->index);
     for ($i = 0, $count = count($this->args); $i < $count; $i++) {
         $this->args[$i]->generateCSS($context, $output);
         if ($i + 1 < $count) {
             $output->add(', ');
         }
     }
     if (isset($canShortenColors)) {
         // put it back
         $context->canShortenColors = $canShortenColors;
     }
     $output->add(')');
 }
Beispiel #10
0
 /**
  * @inheritdoc
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     if (!$context->firstSelector && $this->elements[0]->combinator->value === '') {
         $output->add(' ', $this->currentFileInfo, $this->index);
     }
     foreach ($this->elements as $e) {
         /* @var $e ElementNode */
         $e->generateCSS($context, $output);
     }
 }
Beispiel #11
0
 /**
  * {@inheritdoc}
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     if (count($this->numerator) === 1) {
         $output->add($this->numerator[0]);
     } elseif (!$context->strictUnits && $this->backupUnit) {
         $output->add($this->backupUnit);
     } elseif (!$context->strictUnits && count($this->denominator)) {
         $output->add($this->denominator[0]);
     }
 }
Beispiel #12
0
 /**
  * @inheritdoc
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     $isNotReference = !isset($this->path->currentFileInfo) || !$this->path->currentFileInfo->reference;
     if ($this->css && $isNotReference) {
         $output->add('@import ');
         $this->path->generateCSS($context, $output);
         if ($this->features) {
             $output->add(' ');
             $this->features->generateCSS($context, $output);
         }
         $output->add(';');
     }
     return $output;
 }
Beispiel #13
0
 /**
  * {@inheritdoc}
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     $output->add($this->name . ($context->compress ? ':' : ': '), $this->currentFileInfo, $this->index);
     try {
         $this->value->generateCSS($context, $output);
     } catch (Exception $e) {
         if ($this->currentFileInfo) {
             $e->setCurrentFile($this->currentFileInfo, $this->index);
         }
         // rethrow
         throw $e;
     }
     $output->add($this->important . ($this->inline || $context->lastRule && $context->compress ? '' : ';'), $this->currentFileInfo, $this->index);
 }
Beispiel #14
0
 /**
  * @inheritdoc
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     $output->add($this->toCSS($context), $this->currentFileInfo, $this->index);
 }
Beispiel #15
0
 /**
  * @inheritdoc
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     $output->add($this->value, $this->currentFileInfo, $this->index, $this->mapLines);
 }
Beispiel #16
0
 /**
  * @inheritdoc
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     $output->add('@media ', $this->currentFileInfo, $this->index);
     $this->features->generateCSS($context, $output);
     $this->outputRuleset($context, $output, $this->rules);
 }
Beispiel #17
0
 /**
  * {@inheritdoc}
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     if (!$this->root) {
         ++$context->tabLevel;
     }
     $tabRuleStr = $tabSetStr = '';
     if (!$context->compress && $context->tabLevel) {
         $tabRuleStr = str_repeat('  ', $context->tabLevel);
         $tabSetStr = str_repeat('  ', $context->tabLevel - 1);
     }
     $ruleNodes = $rulesetNodes = $charsetRuleNodes = [];
     $charsetNodeIndex = 0;
     $importNodeIndex = 0;
     for ($i = 0; $i < count($this->rules); ++$i) {
         $rule = $this->rules[$i];
         if ($rule instanceof CommentNode) {
             if ($importNodeIndex === $i) {
                 ++$importNodeIndex;
             }
             array_push($ruleNodes, $rule);
         } elseif ($rule instanceof DirectiveNode && $rule->isCharset()) {
             array_splice($ruleNodes, $charsetNodeIndex, 0, [$rule]);
             ++$charsetNodeIndex;
             ++$importNodeIndex;
         } elseif ($rule instanceof ImportNode) {
             array_splice($ruleNodes, $importNodeIndex, 0, [$rule]);
             ++$importNodeIndex;
         } else {
             array_push($ruleNodes, $rule);
         }
     }
     $ruleNodes = array_merge($charsetRuleNodes, $ruleNodes);
     // If this is the root node, we don't render
     // a selector, or {}.
     if (!$this->root) {
         if ($this->debugInfo) {
             // debug?
             $debugInfo = self::getDebugInfo($context, $this, $tabSetStr);
             if ($debugInfo) {
                 $output->add($debugInfo)->add($tabSetStr);
             }
         }
         $sep = $context->compress ? ',' : ",\n" . $tabSetStr;
         for ($i = 0, $count = count($this->paths); $i < $count; ++$i) {
             $path = $this->paths[$i];
             /* @var $path SelectorNode */
             if (!($pathSubCnt = count($path))) {
                 continue;
             }
             if ($i > 0) {
                 $output->add($sep);
             }
             $context->firstSelector = true;
             $path[0]->generateCSS($context, $output);
             $context->firstSelector = false;
             for ($j = 1; $j < $pathSubCnt; ++$j) {
                 $path[$j]->generateCSS($context, $output);
             }
         }
         $output->add(($context->compress ? '{' : " {\n") . $tabRuleStr);
     }
     // Compile rules and rulesets
     for ($i = 0, $ruleNodesCount = count($ruleNodes); $i < $ruleNodesCount; ++$i) {
         $rule = $ruleNodes[$i];
         /* @var $rule RuleNode */
         if ($i + 1 === $ruleNodesCount) {
             $context->lastRule = true;
         }
         $currentLastRule = $context->lastRule;
         if ($rule->isRulesetLike()) {
             $context->lastRule = false;
         }
         if ($rule instanceof GenerateCSSInterface) {
             $rule->generateCSS($context, $output);
         } elseif ($rule->value) {
             $output->add((string) $rule->value);
         }
         $context->lastRule = $currentLastRule;
         if (!$context->lastRule) {
             $output->add($context->compress ? '' : "\n" . $tabRuleStr);
         } else {
             $context->lastRule = false;
         }
     }
     if (!$this->root) {
         $output->add($context->compress ? '}' : "\n" . $tabSetStr . '}');
         --$context->tabLevel;
     }
     if (!$output->isEmpty() && !$context->compress && $this->firstRoot) {
         $output->add("\n");
     }
 }
Beispiel #18
0
 /**
  * {@inheritdoc}
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     $value = $this->value;
     $rules = $this->rules;
     $output->add($this->name, $this->currentFileInfo, $this->index);
     if ($value) {
         $output->add(' ');
         $value->generateCSS($context, $output);
     }
     if (is_array($rules)) {
         $this->outputRuleset($context, $output, $rules);
     } else {
         $output->add(';');
     }
 }
Beispiel #19
0
 /**
  * {@inheritdoc}
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     $output->add('-');
     $this->value->generateCSS($context, $output);
 }
Beispiel #20
0
 /**
  * @inheritdoc
  */
 public function generateCSS(Context $context, OutputInterface $output)
 {
     // we do not care about compression flag here, so the developer knows whats going on
     $output->add('/* Sorry, unable to do javascript evaluation in PHP... With men it is impossible, but not with God: for with God all things are possible. Mark 10:27 */');
 }