/** * Ensure that the shorthand 'columns' is exploded correctly. */ public function test_columns_shorthand() { /** @var css_declaration[] $decls */ $decls = array(); $decl = new css_declaration('columns', '100px 3'); $decl->explode($decls); $this->assertEquals(count($decls), 2); $this->assertEquals($decls[0]->getProperty(), 'column-width'); $this->assertEquals($decls[0]->getValue(), '100px'); $this->assertEquals($decls[1]->getProperty(), 'column-count'); $this->assertEquals($decls[1]->getValue(), '3'); }
/** * @param $selector * @param $decls * @param null $media */ public function __construct($selector, $decls, $media = NULL) { $this->media = trim($media); //print ("\nNew rule: ".$media."\n"); //Debuging $this->selectors = explode(' ', $selector); $decls = trim($decls, '{}'); // Parse declarations $pos = 0; $end = strlen($decls); while ($pos < $end) { $colon = strpos($decls, ':', $pos); if ($colon === false) { break; } $semi = strpos($decls, ';', $colon + 1); if ($semi === false) { break; } $property = substr($decls, $pos, $colon - $pos); $property = trim($property); $value = substr($decls, $colon + 1, $semi - ($colon + 1)); $value = trim($value); $values = preg_split('/\\s+/', $value); $value = ''; foreach ($values as $part) { if ($part != '!important') { $value .= ' ' . $part; } } $value = trim($value); // Create new declaration $declaration = new css_declaration($property, $value); $this->declarations[] = $declaration; // Handle CSS shorthands, e.g. 'border' if ($declaration->isShorthand() === true) { $declaration->explode($this->declarations); } $pos = $semi + 1; } }