Skip to content

Commit 032b86c

Browse files
committed
Extend output formatting with additional delimiter options
Allow content to be added before/after at-rule blocks. Also allow content to be added before a declaration block, after its selectors, and then after the declaration block.
1 parent 3780f73 commit 032b86c

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

lib/Sabberworm/CSS/CSSList/AtRuleBlockList.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) {
3535
if($sArgs) {
3636
$sArgs = ' ' . $sArgs;
3737
}
38-
$sResult = "@{$this->sType}$sArgs{$oOutputFormat->spaceBeforeOpeningBrace()}{";
38+
$sResult = $oOutputFormat->sBeforeAtRuleBlock;
39+
$sResult .= "@{$this->sType}$sArgs{$oOutputFormat->spaceBeforeOpeningBrace()}{";
3940
$sResult .= parent::render($oOutputFormat);
4041
$sResult .= '}';
42+
$sResult .= $oOutputFormat->sAfterAtRuleBlock;
4143
return $sResult;
4244
}
4345

lib/Sabberworm/CSS/OutputFormat.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class OutputFormat {
3535
public $sSpaceAfterBlocks = '';
3636
public $sSpaceBetweenBlocks = "\n";
3737

38+
// Content injected in and around @-rule blocks.
39+
public $sBeforeAtRuleBlock = '';
40+
public $sAfterAtRuleBlock = '';
41+
3842
// This is what’s printed before and after the comma if a declaration block contains multiple selectors.
3943
public $sSpaceBeforeSelectorSeparator = '';
4044
public $sSpaceAfterSelectorSeparator = ' ';
@@ -43,7 +47,12 @@ class OutputFormat {
4347
public $sSpaceAfterListArgumentSeparator = '';
4448

4549
public $sSpaceBeforeOpeningBrace = ' ';
46-
50+
51+
// Content injected in and around declaration blocks.
52+
public $sBeforeDeclarationBlock = '';
53+
public $sAfterDeclarationBlockSelectors = '';
54+
public $sAfterDeclarationBlock = '';
55+
4756
/**
4857
* Indentation
4958
*/

lib/Sabberworm/CSS/RuleSet/DeclarationBlock.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,13 @@ public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) {
610610
// If all the selectors have been removed, this declaration block becomes invalid
611611
throw new OutputException("Attempt to print declaration block with missing selector", $this->iLineNo);
612612
}
613-
$sResult = $oOutputFormat->implode($oOutputFormat->spaceBeforeSelectorSeparator() . ',' . $oOutputFormat->spaceAfterSelectorSeparator(), $this->aSelectors) . $oOutputFormat->spaceBeforeOpeningBrace() . '{';
613+
$sResult = $oOutputFormat->sBeforeDeclarationBlock;
614+
$sResult .= $oOutputFormat->implode($oOutputFormat->spaceBeforeSelectorSeparator() . ',' . $oOutputFormat->spaceAfterSelectorSeparator(), $this->aSelectors);
615+
$sResult .= $oOutputFormat->sAfterDeclarationBlockSelectors;
616+
$sResult .= $oOutputFormat->spaceBeforeOpeningBrace() . '{';
614617
$sResult .= parent::render($oOutputFormat);
615618
$sResult .= '}';
619+
$sResult .= $oOutputFormat->sAfterDeclarationBlock;
616620
return $sResult;
617621
}
618622

0 commit comments

Comments
 (0)