wip
This commit is contained in:
37
Sources/CliDoc2/Nodes/Group.swift
Normal file
37
Sources/CliDoc2/Nodes/Group.swift
Normal file
@@ -0,0 +1,37 @@
|
||||
public struct Group: TextNode {
|
||||
@usableFromInline
|
||||
var content: [any TextNode]
|
||||
|
||||
@usableFromInline
|
||||
var separator: any TextNode
|
||||
|
||||
@usableFromInline
|
||||
init(
|
||||
content: [any TextNode],
|
||||
separator: any TextNode = "\n"
|
||||
) {
|
||||
self.content = content
|
||||
self.separator = separator
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public init(
|
||||
separator: any TextNode = "\n",
|
||||
@TextBuilder content: () -> any TextNode
|
||||
) {
|
||||
let content = content()
|
||||
if let many = content as? NodeContainer {
|
||||
self.content = many.nodes
|
||||
} else {
|
||||
self.content = [content]
|
||||
}
|
||||
self.separator = separator
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public var body: some TextNode {
|
||||
content.reduce("") {
|
||||
$0 + $1.render() + separator.render()
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Sources/CliDoc2/Nodes/Label.swift
Normal file
19
Sources/CliDoc2/Nodes/Label.swift
Normal file
@@ -0,0 +1,19 @@
|
||||
public struct Label<Content: TextNode>: TextNode {
|
||||
@usableFromInline
|
||||
let content: Content
|
||||
|
||||
@inlinable
|
||||
public init(@TextBuilder _ content: () -> Content) {
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public init(_ content: Content) {
|
||||
self.content = content
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public var body: some TextNode {
|
||||
content
|
||||
}
|
||||
}
|
||||
51
Sources/CliDoc2/Nodes/Note.swift
Normal file
51
Sources/CliDoc2/Nodes/Note.swift
Normal file
@@ -0,0 +1,51 @@
|
||||
import Rainbow
|
||||
|
||||
public struct Note<Label: TextNode, Content: TextNode>: TextNode {
|
||||
@usableFromInline
|
||||
let label: Label
|
||||
|
||||
@usableFromInline
|
||||
let content: Content
|
||||
|
||||
@usableFromInline
|
||||
var separator: any TextNode = " "
|
||||
|
||||
@inlinable
|
||||
public init(
|
||||
separator: any TextNode = " ",
|
||||
@TextBuilder _ label: () -> Label,
|
||||
@TextBuilder content: () -> Content
|
||||
) {
|
||||
self.separator = separator
|
||||
self.label = label()
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public var body: some TextNode {
|
||||
Group(content: [label, content], separator: separator)
|
||||
}
|
||||
}
|
||||
|
||||
public extension Note where Label == String {
|
||||
|
||||
@inlinable
|
||||
init(
|
||||
separator: any TextNode = " ",
|
||||
_ label: String = "NOTE:".yellow.bold,
|
||||
@TextBuilder content: () -> Content
|
||||
) {
|
||||
self.separator = separator
|
||||
self.label = label
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
static func important(
|
||||
separator: any TextNode = " ",
|
||||
_ label: String = "IMPORTANT NOTE:".red.underline,
|
||||
@TextBuilder content: () -> Content
|
||||
) {
|
||||
self.init(separator: separator, label, content: content)
|
||||
}
|
||||
|
||||
}
|
||||
21
Sources/CliDoc2/Nodes/ShellCommand.swift
Normal file
21
Sources/CliDoc2/Nodes/ShellCommand.swift
Normal file
@@ -0,0 +1,21 @@
|
||||
public struct ShellCommand<Content: TextNode>: TextNode {
|
||||
|
||||
@usableFromInline
|
||||
var symbol: any TextNode
|
||||
|
||||
@usableFromInline
|
||||
var content: Content
|
||||
|
||||
@inlinable
|
||||
public init(
|
||||
symbol: any TextNode = "$",
|
||||
@TextBuilder content: () -> Content
|
||||
) {
|
||||
self.symbol = symbol
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
public var body: some TextNode {
|
||||
Group(content: [symbol, content], separator: " ")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user