Beispiel #1
0
 public function __construct($sText, Settings $oParserSettings = null)
 {
     $this->iCurrentPosition = 0;
     if ($oParserSettings === null) {
         $oParserSettings = Settings::create();
     }
     $this->oParserSettings = $oParserSettings;
     if ($this->oParserSettings->bMultibyteSupport) {
         $this->aText = preg_split('//u', $sText, null, PREG_SPLIT_NO_EMPTY);
     } else {
         if ($sText === '') {
             $this->aText = array();
         } else {
             $this->aText = str_split($sText);
         }
     }
     $this->blockRules = explode('/', AtRule::BLOCK_RULES);
     foreach (explode('/', Size::ABSOLUTE_SIZE_UNITS . '/' . Size::RELATIVE_SIZE_UNITS . '/' . Size::NON_SIZE_UNITS) as $val) {
         $iSize = strlen($val);
         if (!isset($this->aSizeUnits[$iSize])) {
             $this->aSizeUnits[$iSize] = array();
         }
         $this->aSizeUnits[$iSize][strtolower($val)] = $val;
     }
     ksort($this->aSizeUnits, SORT_NUMERIC);
 }
 public function testLocaleTrap()
 {
     setlocale(LC_ALL, "pt_PT", "no");
     $sFile = dirname(__FILE__) . '/../../../files' . DIRECTORY_SEPARATOR . "-fault-tolerance.css";
     $oParser = new Parser(file_get_contents($sFile), Settings::create()->withLenientParsing(true));
     $oResult = $oParser->parse();
     $this->assertSame('.test1 {}' . "\n" . '.test2 {hello: 2.2;hello: 2000000000000.2;}' . "\n" . '#test {}' . "\n" . '#test2 {help: none;}', $oResult->render());
 }
Beispiel #3
0
 public function __construct($sText, Settings $oParserSettings = null)
 {
     $this->sText = $sText;
     $this->iCurrentPosition = 0;
     if ($oParserSettings === null) {
         $oParserSettings = Settings::create();
     }
     $this->oParserSettings = $oParserSettings;
     $this->blockRules = explode('/', AtRule::BLOCK_RULES);
 }
Beispiel #4
0
 public function __construct($sText, Settings $oParserSettings = null)
 {
     $this->sText = $sText;
     $this->iCurrentPosition = 0;
     if ($oParserSettings === null) {
         $oParserSettings = Settings::create();
     }
     $this->oParserSettings = $oParserSettings;
     $this->blockRules = explode('/', AtRule::BLOCK_RULES);
     foreach (explode('/', Size::ABSOLUTE_SIZE_UNITS . '/' . Size::RELATIVE_SIZE_UNITS . '/' . Size::NON_SIZE_UNITS) as $val) {
         $iSize = strlen($val);
         if (!isset($this->aSizeUnits[$iSize])) {
             $this->aSizeUnits[$iSize] = array();
         }
         $this->aSizeUnits[$iSize][strtolower($val)] = $val;
     }
     ksort($this->aSizeUnits, SORT_NUMERIC);
 }
Beispiel #5
0
 /**
  * Use CssParser to go through and convert all relative paths to absolute
  *
  * @param string $content
  * @param string $originalFile
  *
  * @return string
  */
 protected function fixRelativePaths($content, $originalFile)
 {
     $cssParserSettings = CssSettings::create()->withMultibyteSupport(false);
     $cssParser = new CssParser($content, $cssParserSettings);
     $cssDocument = $cssParser->parse();
     $cssBlocks = $cssDocument->getAllValues();
     $this->fixUrls($cssBlocks, $originalFile);
     return $cssDocument->render();
 }
Beispiel #6
0
 /**
  * Constructor.
  *
  * @param string $css The CSS content.
  */
 public function __construct($css)
 {
     $settings = \Sabberworm\CSS\Settings::create();
     $settings->withLenientParsing();
     parent::__construct($css, $settings);
 }
 /**
  * @expectedException Sabberworm\CSS\Parsing\UnexpectedTokenException
  */
 function testMicrosoftFilterStrictParsing()
 {
     $oDoc = $this->parsedStructureForFile('ms-filter', Settings::create()->beStrict());
 }
Beispiel #8
0
 function testEmptyFileMbOff()
 {
     $oDoc = $this->parsedStructureForFile('-empty', Settings::create()->withMultibyteSupport(false));
     $sExpected = '';
     $this->assertSame($sExpected, $oDoc->render());
 }
Beispiel #9
0
 /**
  * 
  * @param string $file css file path
  */
 function __construct($file = "style.css")
 {
     $this->origenl_css = file_get_contents($file);
     $this->parser = new CSS\Parser($this->origenl_css, CSS\Settings::create()->withMultibyteSupport(false));
     $this->document = $this->parser->parse();
 }