feat: Working on node builder

This commit is contained in:
2024-12-01 11:45:05 -05:00
parent 55d8888961
commit ff49b12198
20 changed files with 495 additions and 227 deletions

View File

@@ -0,0 +1,46 @@
public struct LabeledContent: NodeRepresentable {
@usableFromInline
let label: any NodeRepresentable
@usableFromInline
let content: any NodeRepresentable
@usableFromInline
let separator: any NodeRepresentable
@inlinable
public init(
separator: (any NodeRepresentable)? = nil,
@NodeBuilder label: () -> any NodeRepresentable,
@NodeBuilder content: () -> any NodeRepresentable
) {
self.separator = separator ?? "\n"
self.label = label()
self.content = content()
}
@inlinable
public func render() -> String {
Group(separator: separator) {
label
content
}.render()
}
}
public extension LabeledContent {
@inlinable
init(
_ label: String,
separator: (any NodeRepresentable)? = nil,
@NodeBuilder content: () -> any NodeRepresentable
) {
self.init(separator: separator) {
Text(label)
} content: {
content()
}
}
}