Add labels block
This commit is contained in:
@ -43,6 +43,7 @@ struct ButtonsBlock: BlockLineProcessor {
|
||||
}
|
||||
|
||||
struct ButtonBlock: KeyedBlockProcessor {
|
||||
|
||||
enum Key: String, Equatable {
|
||||
case icon
|
||||
case file
|
||||
@ -117,12 +118,11 @@ struct ButtonBlock: KeyedBlockProcessor {
|
||||
|
||||
results.externalLink(to: url)
|
||||
results.require(icon: icon)
|
||||
return .init(icon: icon, filePath: url, text: text)
|
||||
return .init(icon: icon, filePath: encodedUrl, text: text)
|
||||
}
|
||||
|
||||
private func action(event: String, icon: PageIcon, text: String) -> ContentButtons.Item? {
|
||||
results.require(icon: icon)
|
||||
|
||||
return .init(icon: icon, filePath: nil, text: text, onClickText: event)
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ enum ContentBlock: String, CaseIterable {
|
||||
|
||||
case buttons
|
||||
|
||||
case labels
|
||||
|
||||
var processor: BlockProcessor.Type {
|
||||
switch self {
|
||||
case .audio: return AudioBlock.self
|
||||
@ -18,6 +20,7 @@ enum ContentBlock: String, CaseIterable {
|
||||
case .video: return VideoBlock.self
|
||||
case .button: return ButtonBlock.self
|
||||
case .buttons: return ButtonsBlock.self
|
||||
case .labels: return LabelsBlock.self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
31
CHDataManagement/Generator/Blocks/LabelsBlock.swift
Normal file
31
CHDataManagement/Generator/Blocks/LabelsBlock.swift
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
struct LabelsBlock: OrderedKeyBlockProcessor {
|
||||
|
||||
typealias Key = PageIcon
|
||||
|
||||
static let blockId: ContentBlock = .labels
|
||||
|
||||
let content: Content
|
||||
|
||||
let results: PageGenerationResults
|
||||
|
||||
let language: ContentLanguage
|
||||
|
||||
init(content: Content, results: PageGenerationResults, language: ContentLanguage) {
|
||||
self.content = content
|
||||
self.results = results
|
||||
self.language = language
|
||||
}
|
||||
|
||||
func process(_ arguments: [(key: PageIcon, value: String)], markdown: Substring) -> String {
|
||||
let labels: [ContentLabel] = arguments.compactMap { (icon, value) in
|
||||
guard value != "" else {
|
||||
invalid(markdown)
|
||||
return nil
|
||||
}
|
||||
results.require(icon: icon)
|
||||
return .init(icon: icon, value: value)
|
||||
}
|
||||
return ContentLabels(labels: labels).content
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user