diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d7ac5d5..6a32053c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,13 @@ This project adheres to [Semantic Versioning](https://semver.org/). ### Added +- `OutputFormat` properties for space around specific list separators (#880) + ### Changed ### Deprecated +- `OutputFormat` properties for space around list separators as an array (#880) - Deprecate `OutputFormat::level()` (#870) ### Removed diff --git a/src/OutputFormat.php b/src/OutputFormat.php index 2ce257fb..366fca3f 100644 --- a/src/OutputFormat.php +++ b/src/OutputFormat.php @@ -96,17 +96,39 @@ class OutputFormat public $sSpaceAfterSelectorSeparator = ' '; /** - * This is what’s printed after the comma of value lists + * This is what’s inserted before the separator in value lists, by default. * - * @var string + * `array` is deprecated in version 8.8.0, and will be removed in version 9.0.0. + * To set the spacing for specific separators, use {@see $aSpaceBeforeListArgumentSeparators} instead. + * + * @var string|array */ public $sSpaceBeforeListArgumentSeparator = ''; /** - * @var string + * Keys are separators (e.g. `,`). Values are the space sequence to insert, or an empty string. + * + * @var array + */ + public $aSpaceBeforeListArgumentSeparators = []; + + /** + * This is what’s inserted after the separator in value lists, by default. + * + * `array` is deprecated in version 8.8.0, and will be removed in version 9.0.0. + * To set the spacing for specific separators, use {@see $aSpaceAfterListArgumentSeparators} instead. + * + * @var string|array */ public $sSpaceAfterListArgumentSeparator = ''; + /** + * Keys are separators (e.g. `,`). Values are the space sequence to insert, or an empty string. + * + * @var array + */ + public $aSpaceAfterListArgumentSeparators = []; + /** * @var string */ @@ -343,7 +365,7 @@ public static function createPretty() $format->set('Space*Rules', "\n") ->set('Space*Blocks', "\n") ->setSpaceBetweenBlocks("\n\n") - ->set('SpaceAfterListArgumentSeparator', ['default' => '', ',' => ' ']) + ->set('SpaceAfterListArgumentSeparators', [',' => ' ']) ->setRenderComments(true); return $format; } diff --git a/src/OutputFormatter.php b/src/OutputFormatter.php index 7af3af05..3844383d 100644 --- a/src/OutputFormatter.php +++ b/src/OutputFormatter.php @@ -117,6 +117,11 @@ public function spaceAfterSelectorSeparator() */ public function spaceBeforeListArgumentSeparator($sSeparator) { + $spaceForSeparator = $this->oFormat->getSpaceBeforeListArgumentSeparators(); + if (isset($spaceForSeparator[$sSeparator])) { + return $spaceForSeparator[$sSeparator]; + } + return $this->space('BeforeListArgumentSeparator', $sSeparator); } @@ -127,6 +132,11 @@ public function spaceBeforeListArgumentSeparator($sSeparator) */ public function spaceAfterListArgumentSeparator($sSeparator) { + $spaceForSeparator = $this->oFormat->getSpaceAfterListArgumentSeparators(); + if (isset($spaceForSeparator[$sSeparator])) { + return $spaceForSeparator[$sSeparator]; + } + return $this->space('AfterListArgumentSeparator', $sSeparator); } diff --git a/tests/OutputFormatTest.php b/tests/OutputFormatTest.php index ff543a9c..2fb6df99 100644 --- a/tests/OutputFormatTest.php +++ b/tests/OutputFormatTest.php @@ -104,8 +104,11 @@ public function spaceAfterListArgumentSeparator() /** * @test + * + * @deprecated since version 8.8.0; will be removed in version 9.0. + * Use `setSpaceAfterListArgumentSeparators()` to set different spacing per separator. */ - public function spaceAfterListArgumentSeparatorComplex() + public function spaceAfterListArgumentSeparatorComplexDeprecated() { $this->setUpTestcase(); @@ -121,6 +124,28 @@ public function spaceAfterListArgumentSeparatorComplex() ); } + /** + * @test + */ + public function spaceAfterListArgumentSeparatorComplex() + { + $this->setUpTestcase(); + + self::assertSame( + '.main, .test {font: italic normal bold 16px/1.2 "Helvetica", Verdana, sans-serif;background: white;}' + . "\n@media screen {.main {background-size: 100% 100%;font-size: 1.3em;background-color: #fff;}}", + $this->oDocument->render( + OutputFormat::create() + ->setSpaceAfterListArgumentSeparator(' ') + ->setSpaceAfterListArgumentSeparators([ + ',' => "\t", + '/' => '', + ' ' => '', + ]) + ) + ); + } + /** * @test */