feat: Adds stack separators, removes some unused nodes from cli-doc module
All checks were successful
CI / Run tests. (push) Successful in 52s
All checks were successful
CI / Run tests. (push) Successful in 52s
This commit is contained in:
@@ -147,7 +147,7 @@ public struct DefaultExampleStyle: ExampleStyle {
|
||||
|
||||
@inlinable
|
||||
public func render(content: ExampleConfiguration) -> some TextNode {
|
||||
VStack(separator: .newLine(count: 2)) {
|
||||
VStack {
|
||||
content.examples.map { example in
|
||||
VStack {
|
||||
example.label.color(.green).bold()
|
||||
@@ -155,5 +155,6 @@ public struct DefaultExampleStyle: ExampleStyle {
|
||||
}
|
||||
}
|
||||
}
|
||||
.separator(.newLine(count: 2))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
import CliDocCore
|
||||
import Rainbow
|
||||
|
||||
// TODO: Use labeled content.
|
||||
public struct Note<Label: TextNode, Content: TextNode>: TextNode {
|
||||
@usableFromInline
|
||||
let label: Label
|
||||
|
||||
@usableFromInline
|
||||
let content: Content
|
||||
|
||||
@inlinable
|
||||
public init(
|
||||
@TextBuilder _ label: () -> Label,
|
||||
@TextBuilder content: () -> Content
|
||||
) {
|
||||
self.label = label()
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public var body: some TextNode {
|
||||
style(.default)
|
||||
}
|
||||
}
|
||||
|
||||
public extension Note where Label == String {
|
||||
|
||||
@inlinable
|
||||
init(
|
||||
_ label: @autoclosure () -> String = "NOTE:",
|
||||
@TextBuilder content: () -> Content
|
||||
) {
|
||||
self.init(label, content: content)
|
||||
}
|
||||
|
||||
static func important(
|
||||
_ label: String = "IMPORTANT NOTE:",
|
||||
@TextBuilder content: () -> Content
|
||||
) -> Self {
|
||||
self.init(label, content: content)
|
||||
}
|
||||
|
||||
static func seeAlso(
|
||||
_ label: String = "SEE ALSO:",
|
||||
@TextBuilder content: () -> Content
|
||||
) -> Self {
|
||||
self.init(label, content: content)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove the important and see also.
|
||||
public extension Note where Label == String, Content == String {
|
||||
|
||||
@inlinable
|
||||
init(
|
||||
_ label: String = "NOTE:",
|
||||
content: String
|
||||
) {
|
||||
self.init(label) { content }
|
||||
}
|
||||
|
||||
static func important(
|
||||
_ label: String = "IMPORTANT NOTE:",
|
||||
content: String
|
||||
) -> Self {
|
||||
self.init(label, content: content)
|
||||
}
|
||||
|
||||
static func seeAlso(
|
||||
_ label: String = "SEE ALSO:",
|
||||
content: String
|
||||
) -> Self {
|
||||
self.init(label, content: content)
|
||||
}
|
||||
}
|
||||
|
||||
public struct NoteStyleConfiguration {
|
||||
@usableFromInline
|
||||
let label: any TextNode
|
||||
|
||||
@usableFromInline
|
||||
let content: any TextNode
|
||||
|
||||
@usableFromInline
|
||||
init(label: any TextNode, content: any TextNode) {
|
||||
self.label = label
|
||||
self.content = content
|
||||
}
|
||||
}
|
||||
|
||||
public extension Note {
|
||||
@inlinable
|
||||
func style<S: NoteStyle>(_ modifier: S) -> some TextNode {
|
||||
modifier.render(content: NoteStyleConfiguration(label: label, content: content))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Style
|
||||
|
||||
public protocol NoteStyle: TextModifier where Content == NoteStyleConfiguration {}
|
||||
|
||||
public extension NoteStyle where Self == DefaultNoteStyle {
|
||||
static var `default`: Self {
|
||||
DefaultNoteStyle()
|
||||
}
|
||||
}
|
||||
|
||||
public struct DefaultNoteStyle: NoteStyle {
|
||||
|
||||
@inlinable
|
||||
public func render(content: NoteStyleConfiguration) -> some TextNode {
|
||||
HStack {
|
||||
content.label.color(.yellow).textStyle(.bold)
|
||||
content.content
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user