feat: Removes old version / files

This commit is contained in:
2024-12-03 21:23:54 -05:00
parent 590df275cc
commit 0a18b57dc8
25 changed files with 206 additions and 606 deletions

View File

@@ -1,18 +0,0 @@
/// A type erased node.
public struct AnyNode: Node {
private var renderNode: () -> String
public init<N: NodeRepresentable>(_ node: N) {
self.renderNode = node.render
}
public var body: some Node {
renderNode()
}
}
public extension Node {
func eraseToAnyNode() -> AnyNode {
.init(self)
}
}

View File

@@ -1,18 +0,0 @@
import Rainbow
public struct Colored: Node {
var color: NamedColor
var node: any Node
public init(
color: NamedColor,
@NodeBuilder build: () -> any Node
) {
self.color = color
self.node = build()
}
public var body: some Node {
node.render().applyingColor(color)
}
}

View File

@@ -0,0 +1,40 @@
import Rainbow
public struct Examples<Header: TextNode, Label: TextNode>: TextNode {
public typealias Example = (label: String, example: String)
@usableFromInline
let examples: [Example]
@usableFromInline
let header: Header
@usableFromInline
let label: Label
public init(
examples: [Example],
@TextBuilder header: () -> Header,
@TextBuilder label: () -> Label
) {
self.examples = examples
self.header = header()
self.label = label()
}
public var body: some TextNode {
Group(separator: "") {
Group(separator: " ", content: [header.color(.yellow).style(.bold), label, "\n"])
"\n"
Group(
separator: "\n\n",
content: self.examples.map { example in
Group(separator: "\n") {
CliDoc.Label(example.label.green.bold)
ShellCommand { example.example.italic }
}
}
)
}
}
}

View File

@@ -1,28 +1,41 @@
/// A group container holding one or more nodes.
public struct Group: Node {
var nodes: [any Node]
var separator: String
public struct Group: TextNode {
@usableFromInline
var content: [any TextNode]
init(_ nodes: [any Node], separator: String = "\n") {
self.nodes = nodes
@usableFromInline
var separator: any TextNode
@inlinable
public init(
separator: any TextNode = "\n",
content: [any TextNode]
) {
self.content = content
self.separator = separator
}
@inlinable
public init(
separator: String = " ",
@NodeBuilder build: () -> any Node
separator: any TextNode = "\n",
@TextBuilder content: () -> any TextNode
) {
let node = build()
if var group = node as? Self {
group.separator = separator
self = group
// Check if the content is a NodeContainer, typically is when
// using the TextBuilder with more than one text node.
//
// We need to take over the contents, so we can control the separator.
let content = content()
if let many = content as? NodeContainer {
self.content = many.nodes
} else {
self.init([node], separator: separator)
// We didn't get a NodeContainer, so fallback to just storing
// the content.
self.content = [content]
}
self.separator = separator
}
public var body: some Node {
nodes.map { $0.render() }.joined(separator: separator)
@inlinable
public var body: some TextNode {
content.map { $0.render() }.joined(separator: separator.render())
}
}

View File

@@ -1,45 +1,19 @@
import Rainbow
public struct Label<Content: TextNode>: TextNode {
@usableFromInline
let content: Content
public struct Label: Node {
var color: NamedColor?
var styles: [Style]
let node: any Node
public init(
_ label: String,
color: NamedColor? = nil,
style styles: Style...
) {
self.color = color
self.node = label
self.styles = styles
@inlinable
public init(@TextBuilder _ content: () -> Content) {
self.content = content()
}
public init(
_ label: String,
color: NamedColor? = nil,
style styles: [Style] = []
) {
self.color = color
self.node = label
self.styles = styles
@inlinable
public init(_ content: Content) {
self.content = content
}
public init(
color: NamedColor? = nil,
styles: [Style] = [],
@NodeBuilder _ build: () -> any Node
) {
self.color = color
self.styles = styles
self.node = build()
@inlinable
public var body: some TextNode {
content
}
public var body: some Node {
let output = styles.reduce(node.render()) { $0.applyingStyle($1) }
guard let color else { return output }
return output.applyingColor(color)
}
}

View File

@@ -1,31 +1,58 @@
public struct Note<Label: Node, Content: Node>: Node {
import Rainbow
var separator: String
var label: Label
var content: Content
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: String = " ",
@NodeBuilder label: () -> Label,
@NodeBuilder content: () -> Content
separator: any TextNode = " ",
@TextBuilder _ label: () -> Label,
@TextBuilder content: () -> Content
) {
self.separator = separator
self.label = label()
self.content = content()
}
public var body: some Node {
Group([label, content], separator: separator)
@inlinable
public var body: some TextNode {
Group(separator: separator, content: [label, content])
}
}
public extension Note where Label == CliDoc.Label {
public extension Note where Label == String {
@inlinable
init(
separator: String = " ",
label: String = "NOTE:",
@NodeBuilder content: () -> Content
separator: any TextNode = " ",
_ label: String = "NOTE:".yellow.bold,
@TextBuilder content: () -> Content
) {
self.init(separator: separator, label: { CliDoc.Label(label) }, 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 {
self.init(separator: separator, label, content: content)
}
static func seeAlso(
separator: any TextNode = " ",
_ label: String = "SEE ALSO:".yellow.bold,
@TextBuilder content: () -> Content
) -> Self {
self.init(separator: separator, label, content: content)
}
}

View File

@@ -1,20 +1,21 @@
public struct ShellCommand<Content: Node>: Node {
public struct ShellCommand<Content: TextNode>: TextNode {
public var symbol: String
public var content: Content
@usableFromInline
var symbol: any TextNode
@usableFromInline
var content: Content
@inlinable
public init(
symbol: String = "$",
@NodeBuilder content: () -> Content
symbol: any TextNode = "$",
@TextBuilder content: () -> Content
) {
self.symbol = symbol
self.content = content()
}
public var body: some Node {
Group(separator: " ") {
symbol
content
}
public var body: some TextNode {
Group(separator: " ", content: [symbol, content])
}
}