Skip to content

Commit 98c4b3a

Browse files
committed
Add support for grid line names
1 parent 0c74522 commit 98c4b3a

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Sabberworm\CSS\Value\Color;
2222
use Sabberworm\CSS\Value\URL;
2323
use Sabberworm\CSS\Value\CSSString;
24+
use Sabberworm\CSS\Value\LineName;
2425
use Sabberworm\CSS\Rule\Rule;
2526
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
2627
use Sabberworm\CSS\Comment\Comment;
@@ -447,6 +448,8 @@ private function parsePrimitiveValue() {
447448
$oValue = $this->parseStringValue();
448449
} else if ($this->comes("progid:") && $this->oParserSettings->bLenientParsing) {
449450
$oValue = $this->parseMicrosoftFilter();
451+
} else if ($this->comes("[")) {
452+
$oValue = $this->parseLineNameValue();
450453
} else {
451454
$oValue = $this->parseIdentifier(true, false);
452455
}
@@ -480,6 +483,16 @@ private function parseNumericValue($bForColor = false) {
480483
return new Size(floatval($sSize), $sUnit, $bForColor, $this->iLineNo);
481484
}
482485

486+
private function parseLineNameValue() {
487+
$this->consume('[');
488+
$sName = '';
489+
while(!$this->comes(']')) {
490+
$sName .= $this->consume(1);
491+
}
492+
$this->consume(']');
493+
return new LineName($sName, $this->iLineNo);
494+
}
495+
483496
private function parseColorValue() {
484497
$aColor = array();
485498
if ($this->comes('#')) {

lib/Sabberworm/CSS/Value/LineName.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Sabberworm\CSS\Value;
4+
5+
class LineName extends PrimitiveValue {
6+
private $sName;
7+
8+
public function __construct($sName, $iLineNo = 0) {
9+
parent::__construct($iLineNo);
10+
$this->sName = $sName;
11+
}
12+
13+
public function setName($sName) {
14+
$this->sName = $sName;
15+
}
16+
17+
public function getName() {
18+
return $this->sName;
19+
}
20+
21+
public function __toString() {
22+
return $this->render(new \Sabberworm\CSS\OutputFormat());
23+
}
24+
25+
public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) {
26+
return "[{$this->sName}]";
27+
}
28+
29+
}

tests/Sabberworm/CSS/ParserTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,12 @@ function testCalcInFile() {
394394
$this->assertSame($sExpected, $oDoc->render());
395395
}
396396

397+
function testGridLineNameInFile() {
398+
$oDoc = $this->parsedStructureForFile('grid-linename', Settings::create()->withMultibyteSupport(true));
399+
$sExpected = '.test {grid-template-columns: [linename] 100px;}';
400+
$this->assertSame($sExpected, $oDoc->render());
401+
}
402+
397403
/**
398404
* @expectedException Sabberworm\CSS\Parsing\UnexpectedTokenException
399405
*/

tests/files/grid-linename.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.test { grid-template-columns: [linename] 100px; }

0 commit comments

Comments
 (0)