Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit d8abe7e

Browse files
authored
Result Builder improvements (#2)
* add array input to buildBlock * support for control flows * public property name and value
1 parent 5577620 commit d8abe7e

4 files changed

Lines changed: 98 additions & 3 deletions

File tree

Sources/SwiftCss/Builders/PropertyBuilder.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,36 @@ public enum PropertyBuilder {
1010
public static func buildBlock(_ components: Property...) -> [Property] {
1111
components
1212
}
13+
14+
public static func buildBlock(_ components: [Property]) -> [Property] {
15+
components
16+
}
17+
18+
public static func buildBlock(_ components: [Property]...) -> [Property] {
19+
components.flatMap { $0 }
20+
}
21+
22+
public static func buildEither(first component: [Property]) -> [Property] {
23+
component
24+
}
25+
26+
public static func buildEither(second component: [Property]) -> [Property] {
27+
component
28+
}
29+
30+
public static func buildOptional(_ component: [Property]?) -> [Property] {
31+
component ?? []
32+
}
33+
34+
public static func buildExpression(_ expression: Property) -> [Property] {
35+
[expression]
36+
}
37+
38+
public static func buildExpression(_ expression: [Property]) -> [Property] {
39+
expression
40+
}
41+
42+
public static func buildArray(_ components: [[Property]]) -> [Property] {
43+
components.flatMap { $0 }
44+
}
1345
}

Sources/SwiftCss/Builders/RuleBuilder.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,36 @@ public enum RuleBuilder {
1010
public static func buildBlock(_ components: Rule...) -> [Rule] {
1111
components
1212
}
13+
14+
public static func buildBlock(_ components: [Rule]) -> [Rule] {
15+
components
16+
}
17+
18+
public static func buildBlock(_ components: [Rule]...) -> [Rule] {
19+
components.flatMap { $0 }
20+
}
21+
22+
public static func buildEither(first component: [Rule]) -> [Rule] {
23+
component
24+
}
25+
26+
public static func buildEither(second component: [Rule]) -> [Rule] {
27+
component
28+
}
29+
30+
public static func buildOptional(_ component: [Rule]?) -> [Rule] {
31+
component ?? []
32+
}
33+
34+
public static func buildExpression(_ expression: Rule) -> [Rule] {
35+
[expression]
36+
}
37+
38+
public static func buildExpression(_ expression: [Rule]) -> [Rule] {
39+
expression
40+
}
41+
42+
public static func buildArray(_ components: [[Rule]]) -> [Rule] {
43+
components.flatMap { $0 }
44+
}
1345
}

Sources/SwiftCss/Builders/SelectorBuilder.swift

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,36 @@ public enum SelectorBuilder {
1010
public static func buildBlock(_ components: Selector...) -> [Selector] {
1111
components
1212
}
13-
}
1413

14+
public static func buildBlock(_ components: [Selector]) -> [Selector] {
15+
components
16+
}
17+
18+
public static func buildBlock(_ components: [Selector]...) -> [Selector] {
19+
components.flatMap { $0 }
20+
}
21+
22+
public static func buildEither(first component: [Selector]) -> [Selector] {
23+
component
24+
}
25+
26+
public static func buildEither(second component: [Selector]) -> [Selector] {
27+
component
28+
}
29+
30+
public static func buildOptional(_ component: [Selector]?) -> [Selector] {
31+
component ?? []
32+
}
33+
34+
public static func buildExpression(_ expression: Selector) -> [Selector] {
35+
[expression]
36+
}
37+
38+
public static func buildExpression(_ expression: [Selector]) -> [Selector] {
39+
expression
40+
}
41+
42+
public static func buildArray(_ components: [[Selector]]) -> [Selector] {
43+
components.flatMap { $0 }
44+
}
45+
}

Sources/SwiftCss/Components/Property.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
/// https://www.w3schools.com/cssref/
99
public struct Property {
10-
var name: String
11-
var value: String
10+
public var name: String
11+
public var value: String
1212
var isImportant: Bool = false
1313

1414
public init(name: String, value: String, isImportant: Bool = false) {

0 commit comments

Comments
 (0)