Skip to content

Commit 79ddf8b

Browse files
melguMelvin Gundlach
and
Melvin Gundlach
authored
Improve composition (#37)
By moving the @TagBuilder property wrapper to the protocol, we don't need to write it every time. Co-authored-by: Melvin Gundlach <[email protected]>
1 parent 5df8183 commit 79ddf8b

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,15 @@ public extension Guid {
182182

183183
There are other built-in type-safe attribute modifiers available on tags.
184184

185-
185+
186186
## Composing tags
187187

188188
You can come up with your own `Tag` composition system by introducing a new protocol.
189189

190190
```swift
191191
protocol TagRepresentable {
192192

193+
@TagBuilder
193194
func build() -> Tag
194195
}
195196

@@ -201,7 +202,6 @@ struct ListComponent: TagRepresentable {
201202
self.items = items
202203
}
203204

204-
@TagBuilder
205205
func build() -> Tag {
206206
Ul {
207207
for item in items {

Tests/SwiftHtmlTests/TagCompositionTests.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import XCTest
99
@testable import SwiftHtml
1010

1111
protocol TagRepresentable {
12-
12+
@TagBuilder
1313
func build() -> Tag
1414
}
1515

@@ -32,7 +32,6 @@ struct ListComponent: TagRepresentable {
3232
self.items = items
3333
}
3434

35-
@TagBuilder
3635
func build() -> Tag {
3736
Ul {
3837
for item in items {

0 commit comments

Comments
 (0)