Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Please also have a look at our

### Added

- `OutputFormat` properties for space around specific list separators (#880)
- Partial support for CSS Color Module Level 4:
- `rgb` and `rgba`, and `hsl` and `hsla` are now aliases (#797}
- Parse color functions that use the "modern" syntax (#800)
Expand All @@ -26,6 +27,8 @@ Please also have a look at our

### Deprecated

- `OutputFormat` properties for space around list separators as an array (#880)

### Removed

- Remove `OutputFormat::level()` (#874)
Expand Down
30 changes: 26 additions & 4 deletions src/OutputFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,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<non-empty-string, string>
*/
public $sSpaceBeforeListArgumentSeparator = '';

/**
* @var string
* Keys are separators (e.g. `,`). Values are the space sequence to insert, or an empty string.
*
* @var array<non-empty-string, string>
*/
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<non-empty-string, string>
*/
public $sSpaceAfterListArgumentSeparator = '';

/**
* Keys are separators (e.g. `,`). Values are the space sequence to insert, or an empty string.
*
* @var array<non-empty-string, string>
*/
public $aSpaceAfterListArgumentSeparators = [];

/**
* @var string
*/
Expand Down Expand Up @@ -311,7 +333,7 @@ public static function createPretty(): self
$format->set('Space*Rules', "\n")
->set('Space*Blocks', "\n")
->setSpaceBetweenBlocks("\n\n")
->set('SpaceAfterListArgumentSeparator', ['default' => '', ',' => ' '])
->set('SpaceAfterListArgumentSeparators', [',' => ' '])
->setRenderComments(true);
return $format;
}
Expand Down
8 changes: 6 additions & 2 deletions src/OutputFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,19 @@ public function spaceAfterSelectorSeparator(): string
*/
public function spaceBeforeListArgumentSeparator($sSeparator): string
{
return $this->space('BeforeListArgumentSeparator', $sSeparator);
$spaceForSeparator = $this->oFormat->getSpaceBeforeListArgumentSeparators();

return $spaceForSeparator[$sSeparator] ?? $this->space('BeforeListArgumentSeparator', $sSeparator);
}

/**
* @param string $sSeparator
*/
public function spaceAfterListArgumentSeparator($sSeparator): string
{
return $this->space('AfterListArgumentSeparator', $sSeparator);
$spaceForSeparator = $this->oFormat->getSpaceAfterListArgumentSeparators();

return $spaceForSeparator[$sSeparator] ?? $this->space('AfterListArgumentSeparator', $sSeparator);
}

public function spaceBeforeOpeningBrace(): string
Expand Down
25 changes: 24 additions & 1 deletion tests/OutputFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ public function spaceAfterListArgumentSeparator(): void

/**
* @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(): void
public function spaceAfterListArgumentSeparatorComplexDeprecated(): void
{
self::assertSame(
'.main, .test {font: italic normal bold 16px/1.2 "Helvetica", Verdana, sans-serif;background: white;}'
Expand All @@ -113,6 +116,26 @@ public function spaceAfterListArgumentSeparatorComplex(): void
);
}

/**
* @test
*/
public function spaceAfterListArgumentSeparatorComplex(): void
{
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->document->render(
OutputFormat::create()
->setSpaceAfterListArgumentSeparator(' ')
->setSpaceAfterListArgumentSeparators([
',' => "\t",
'/' => '',
' ' => '',
])
)
);
}

/**
* @test
*/
Expand Down
54 changes: 54 additions & 0 deletions tests/Unit/OutputFormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,33 @@ public function setSpaceBeforeListArgumentSeparatorProvidesFluentInterface(): vo
self::assertSame($this->subject, $this->subject->setSpaceBeforeListArgumentSeparator(' '));
}

/**
* @test
*/
public function getSpaceBeforeListArgumentSeparatorsInitiallyReturnsEmptyArray(): void
{
self::assertSame([], $this->subject->getSpaceBeforeListArgumentSeparators());
}

/**
* @test
*/
public function setSpaceBeforeListArgumentSeparatorsSetsSpaceBeforeListArgumentSeparators(): void
{
$value = ['/' => ' '];
$this->subject->setSpaceBeforeListArgumentSeparators($value);

self::assertSame($value, $this->subject->getSpaceBeforeListArgumentSeparators());
}

/**
* @test
*/
public function setSpaceBeforeListArgumentSeparatorsProvidesFluentInterface(): void
{
self::assertSame($this->subject, $this->subject->setSpaceBeforeListArgumentSeparators([]));
}

/**
* @test
*/
Expand Down Expand Up @@ -468,6 +495,33 @@ public function setSpaceAfterListArgumentSeparatorProvidesFluentInterface(): voi
self::assertSame($this->subject, $this->subject->setSpaceAfterListArgumentSeparator(' '));
}

/**
* @test
*/
public function getSpaceAfterListArgumentSeparatorsInitiallyReturnsEmptyArray(): void
{
self::assertSame([], $this->subject->getSpaceAfterListArgumentSeparators());
}

/**
* @test
*/
public function setSpaceAfterListArgumentSeparatorsSetsSpaceAfterListArgumentSeparators(): void
{
$value = [',' => ' '];
$this->subject->setSpaceAfterListArgumentSeparators($value);

self::assertSame($value, $this->subject->getSpaceAfterListArgumentSeparators());
}

/**
* @test
*/
public function setSpaceAfterListArgumentSeparatorsProvidesFluentInterface(): void
{
self::assertSame($this->subject, $this->subject->setSpaceAfterListArgumentSeparators([]));
}

/**
* @test
*/
Expand Down