File tree Expand file tree Collapse file tree 3 files changed +55
-15
lines changed Expand file tree Collapse file tree 3 files changed +55
-15
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
28
28
29
29
### Fixed
30
30
31
+ - Render rules in line and column number order (#1059 )
31
32
- Create ` Size ` with correct types in ` expandBackgroundShorthand ` (#814 )
32
33
- Parse ` @font-face ` ` src ` property as comma-delimited list (#794 )
33
34
Original file line number Diff line number Diff line change @@ -287,22 +287,20 @@ protected function renderRules(OutputFormat $oOutputFormat)
287
287
$ sResult = '' ;
288
288
$ bIsFirst = true ;
289
289
$ oNextLevel = $ oOutputFormat ->nextLevel ();
290
- foreach ($ this ->aRules as $ aRules ) {
291
- foreach ($ aRules as $ oRule ) {
292
- $ sRendered = $ oNextLevel ->safely (function () use ($ oRule , $ oNextLevel ) {
293
- return $ oRule ->render ($ oNextLevel );
294
- });
295
- if ($ sRendered === null ) {
296
- continue ;
297
- }
298
- if ($ bIsFirst ) {
299
- $ bIsFirst = false ;
300
- $ sResult .= $ oNextLevel ->spaceBeforeRules ();
301
- } else {
302
- $ sResult .= $ oNextLevel ->spaceBetweenRules ();
303
- }
304
- $ sResult .= $ sRendered ;
290
+ foreach ($ this ->getRules () as $ oRule ) {
291
+ $ sRendered = $ oNextLevel ->safely (function () use ($ oRule , $ oNextLevel ) {
292
+ return $ oRule ->render ($ oNextLevel );
293
+ });
294
+ if ($ sRendered === null ) {
295
+ continue ;
296
+ }
297
+ if ($ bIsFirst ) {
298
+ $ bIsFirst = false ;
299
+ $ sResult .= $ oNextLevel ->spaceBeforeRules ();
300
+ } else {
301
+ $ sResult .= $ oNextLevel ->spaceBetweenRules ();
305
302
}
303
+ $ sResult .= $ sRendered ;
306
304
}
307
305
308
306
if (!$ bIsFirst ) {
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Sabberworm \CSS \Tests \Functional \RuleSet ;
6
+
7
+ use PHPUnit \Framework \TestCase ;
8
+ use Sabberworm \CSS \OutputFormat ;
9
+ use Sabberworm \CSS \Property \Selector ;
10
+ use Sabberworm \CSS \Rule \Rule ;
11
+ use Sabberworm \CSS \RuleSet \DeclarationBlock ;
12
+
13
+ /**
14
+ * @covers \Sabberworm\CSS\RuleSet\DeclarationBlock
15
+ */
16
+ final class DeclarationBlockTest extends TestCase
17
+ {
18
+ /**
19
+ * @test
20
+ */
21
+ public function rendersRulesInOrderProvided ()
22
+ {
23
+ $ declarationBlock = new DeclarationBlock ();
24
+ $ declarationBlock ->setSelectors ([new Selector ('.test ' )]);
25
+
26
+ $ rule1 = new Rule ('background-color ' );
27
+ $ rule1 ->setValue ('transparent ' );
28
+ $ declarationBlock ->addRule ($ rule1 );
29
+
30
+ $ rule2 = new Rule ('background ' );
31
+ $ rule2 ->setValue ('#222 ' );
32
+ $ declarationBlock ->addRule ($ rule2 );
33
+
34
+ $ rule3 = new Rule ('background-color ' );
35
+ $ rule3 ->setValue ('#fff ' );
36
+ $ declarationBlock ->addRule ($ rule3 );
37
+
38
+ $ expectedRendering = 'background-color: transparent;background: #222;background-color: #fff ' ;
39
+ self ::assertContains ($ expectedRendering , $ declarationBlock ->render (new OutputFormat ()));
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments