Example #1
0
 public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat)
 {
     $sResult = '';
     $bIsFirst = true;
     $oNextLevel = $oOutputFormat;
     if (!$this->isRootList()) {
         $oNextLevel = $oOutputFormat->nextLevel();
     }
     foreach ($this->aContents as $oContent) {
         $sRendered = $oOutputFormat->safely(function () use($oNextLevel, $oContent) {
             return $oContent->render($oNextLevel);
         });
         if ($sRendered === null) {
             continue;
         }
         if ($bIsFirst) {
             $bIsFirst = false;
             $sResult .= $oNextLevel->spaceBeforeBlocks();
         } else {
             $sResult .= $oNextLevel->spaceBetweenBlocks();
         }
         $sResult .= $sRendered;
     }
     if (!$bIsFirst) {
         // Had some output
         $sResult .= $oOutputFormat->spaceAfterBlocks();
     }
     return $sResult;
 }
Example #2
0
 public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat)
 {
     $sResult = "@{$this->vendorKeyFrame} {$this->animationName}{$oOutputFormat->spaceBeforeOpeningBrace()}{";
     $sResult .= parent::render($oOutputFormat);
     $sResult .= '}';
     return $sResult;
 }
Example #3
0
 public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat)
 {
     // Shorthand RGB color values
     if ($oOutputFormat->getRGBHashNotation() && implode('', array_keys($this->aComponents)) === 'rgb') {
         $sResult = sprintf('%02x%02x%02x', $this->aComponents['r']->getSize(), $this->aComponents['g']->getSize(), $this->aComponents['b']->getSize());
         return '#' . ($sResult[0] == $sResult[1] && $sResult[2] == $sResult[3] && $sResult[4] == $sResult[5] ? "{$sResult['0']}{$sResult['2']}{$sResult['4']}" : $sResult);
     }
     return parent::render($oOutputFormat);
 }
Example #4
0
 public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat)
 {
     $sArgs = $this->sArgs;
     if ($sArgs) {
         $sArgs = ' ' . $sArgs;
     }
     $sResult = "@{$this->sType}{$sArgs}{$oOutputFormat->spaceBeforeOpeningBrace()}{";
     $sResult .= parent::render($oOutputFormat);
     $sResult .= '}';
     return $sResult;
 }
Example #5
0
 public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat)
 {
     $sResult = "{$this->sRule}:{$oOutputFormat->spaceAfterRuleName()}";
     if ($this->mValue instanceof Value) {
         //Can also be a ValueList
         $sResult .= $this->mValue->render($oOutputFormat);
     } else {
         $sResult .= $this->mValue;
     }
     if ($this->bIsImportant) {
         $sResult .= ' !important';
     }
     $sResult .= ';';
     return $sResult;
 }
Example #6
0
 public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat)
 {
     if (count($this->aSelectors) === 0) {
         // If all the selectors have been removed, this declaration block becomes invalid
         throw new OutputException("Attempt to print declaration block with missing selector");
     }
     $sResult = $oOutputFormat->implode($oOutputFormat->spaceBeforeSelectorSeparator() . ',' . $oOutputFormat->spaceAfterSelectorSeparator(), $this->aSelectors) . $oOutputFormat->spaceBeforeOpeningBrace() . '{';
     $sResult .= parent::render($oOutputFormat);
     $sResult .= '}';
     return $sResult;
 }
Example #7
0
 public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat)
 {
     return $oOutputFormat->implode($oOutputFormat->spaceBeforeListArgumentSeparator($this->sSeparator) . $this->sSeparator . $oOutputFormat->spaceAfterListArgumentSeparator($this->sSeparator), $this->aComponents);
 }
Example #8
0
 public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat)
 {
     $sResult = '';
     $bIsFirst = true;
     foreach ($this->aRules as $aRules) {
         foreach ($aRules as $oRule) {
             $sRendered = $oOutputFormat->safely(function () use($oRule, $oOutputFormat) {
                 return $oRule->render($oOutputFormat->nextLevel());
             });
             if ($sRendered === null) {
                 continue;
             }
             if ($bIsFirst) {
                 $bIsFirst = false;
                 $sResult .= $oOutputFormat->nextLevel()->spaceBeforeRules();
             } else {
                 $sResult .= $oOutputFormat->nextLevel()->spaceBetweenRules();
             }
             $sResult .= $sRendered;
         }
     }
     if (!$bIsFirst) {
         // Had some output
         $sResult .= $oOutputFormat->spaceAfterRules();
     }
     return $oOutputFormat->removeLastSemicolon($sResult);
 }
 /**
  * Sanitizes input.
  *
  * @return array
  */
 public function sanitize()
 {
     $input = $this->all();
     $parser = new \Sabberworm\CSS\Parser($input['boardCustomCSS']);
     $style = $parser->parse()->render(\Sabberworm\CSS\OutputFormat::createPretty());
     $input['boardCustomCSS'] = $style;
     $this->replace($input);
 }
Example #10
0
 public function testIgnoreExceptionsOn()
 {
     $aBlocks = $this->oDocument->getAllDeclarationBlocks();
     $oFirstBlock = $aBlocks[0];
     $oFirstBlock->removeSelector('.main');
     $oFirstBlock->removeSelector('.test');
     $this->assertSame('@media screen {.main {background-size: 100% 100%;font-size: 1.3em;background-color: #fff;}}', $this->oDocument->render(OutputFormat::create()->setIgnoreExceptions(true)));
 }
Example #11
0
 public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat)
 {
     $sString = addslashes($this->sString);
     $sString = str_replace("\n", '\\A', $sString);
     return $oOutputFormat->getStringQuotingType() . $sString . $oOutputFormat->getStringQuotingType();
 }
Example #12
0
 /**
  * render the rtled css code, by defualt it will return a string
  * @param bool $save_to_file if true save the code in a rtl.css file
  */
 public function render($save_to_file = false)
 {
     return $this->document->render(CSS\OutputFormat::createPretty());
 }
Example #13
0
 /**
  * Executes the command
  *
  * @param InputInterface $input
  * @param OutputInterface $output 
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $src = $input->getArgument('src');
     $dst = $input->getArgument('dst');
     $selector = $input->getArgument('selector');
     $append = $input->getOption('append');
     // Create CSS dest object
     $dstCss = new \Sabberworm\CSS\Parser($append && file_exists($dst) ? file_get_contents($dst) : null);
     $dstCssDoc = $dstCss->parse();
     $finder = new Finder();
     $resources = $finder->files()->depth(0)->in($src)->name($selector . '.css');
     foreach ($resources as $res) {
         $output->writeln('CSS Found: ' . $res->getRealPath());
         $css = new \Sabberworm\CSS\Parser(file_get_contents($res->getRealPath()));
         $cssDoc = $css->parse();
         foreach ($cssDoc->getContents() as $block) {
             if ($block instanceof \Sabberworm\CSS\RuleSet\DeclarationBlock) {
                 /* @var $ruleset \Sabberworm\CSS\RuleSet\DeclarationBlock */
                 // Keep only the root CSS (ignore media queries)
                 $keepRules = array();
                 foreach ($block->getRules() as $rule) {
                     /* @var $rule \Sabberworm\CSS\Rule\Rule */
                     $value = $rule->getValue();
                     if (is_object($value)) {
                         // keep only object with size rem
                         $keepValue = false;
                         switch (get_class($value)) {
                             case 'Sabberworm\\CSS\\Value\\Size':
                                 /* @var $value \Sabberworm\CSS\Value\Size */
                                 if ($value->getUnit() == 'rem') {
                                     $value->setSize($value->getSize() * 10);
                                     $value->setUnit('px');
                                     $keepValue = true;
                                 }
                                 break;
                             case 'Sabberworm\\CSS\\Value\\RuleValueList':
                                 /* @var $value \Sabberworm\CSS\Value\RuleValueList */
                                 foreach ($value->getListComponents() as $c) {
                                     if ($c instanceof \Sabberworm\CSS\Value\Size) {
                                         if ($c->getUnit() == 'rem') {
                                             $c->setSize($c->getSize() * 10);
                                             $c->setUnit('px');
                                             $keepValue = true;
                                         }
                                     }
                                 }
                                 break;
                         }
                         if ($keepValue) {
                             $keepRules[] = $rule;
                         }
                     }
                 }
                 if (count($keepRules)) {
                     $oItem = new \Sabberworm\CSS\RuleSet\DeclarationBlock();
                     $oItem->setSelectors($block->getSelectors());
                     foreach ($keepRules as $rule) {
                         $oItem->addRule($rule);
                     }
                     $dstCssDoc->append($oItem);
                 }
             }
         }
     }
     $output->writeln('Write ' . $dst);
     file_put_contents($dst, $dstCssDoc->render(\Sabberworm\CSS\OutputFormat::createPretty()));
 }