feat: Adds section and section style, needs tests
This commit is contained in:
51
Sources/CliDoc/Nodes/ExampleSection.swift
Normal file
51
Sources/CliDoc/Nodes/ExampleSection.swift
Normal file
@@ -0,0 +1,51 @@
|
||||
import Rainbow
|
||||
|
||||
public struct ExampleSection<Header: TextNode, Label: TextNode>: TextNode {
|
||||
public typealias Example = (label: String, example: String)
|
||||
|
||||
@usableFromInline
|
||||
let examples: [Example]
|
||||
|
||||
@usableFromInline
|
||||
let header: Header
|
||||
|
||||
@usableFromInline
|
||||
let label: Label
|
||||
|
||||
@inlinable
|
||||
public init(
|
||||
examples: [Example],
|
||||
@TextBuilder header: () -> Header,
|
||||
@TextBuilder label: () -> Label
|
||||
) {
|
||||
self.examples = examples
|
||||
self.header = header()
|
||||
self.label = label()
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public var body: some TextNode {
|
||||
style(.default())
|
||||
}
|
||||
}
|
||||
|
||||
public extension ExampleSection where Header == String, Label == String {
|
||||
@inlinable
|
||||
init(
|
||||
header: String = "Examples:".yellow.bold,
|
||||
label: String = "Some common usage examples.",
|
||||
examples: [Example]
|
||||
) {
|
||||
self.init(examples: examples) { header } label: { label }
|
||||
}
|
||||
|
||||
@inlinable
|
||||
init(
|
||||
header: String = "Examples:".yellow.bold,
|
||||
label: String = "Some common usage examples.",
|
||||
examples: Example...
|
||||
) {
|
||||
self.init(header: header, label: label, examples: examples)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user