Add result handler to templates
This commit is contained in:
parent
6e24c27fdc
commit
6a52f62402
@ -10,4 +10,6 @@ struct BackNavigationTemplate: Template {
|
|||||||
static let templateName = "back.html"
|
static let templateName = "back.html"
|
||||||
|
|
||||||
let raw: String
|
let raw: String
|
||||||
|
|
||||||
|
let results: GenerationResultsHandler
|
||||||
}
|
}
|
||||||
|
@ -10,4 +10,6 @@ struct BoxTemplate: Template {
|
|||||||
static let templateName = "box.html"
|
static let templateName = "box.html"
|
||||||
|
|
||||||
var raw: String
|
var raw: String
|
||||||
|
|
||||||
|
let results: GenerationResultsHandler
|
||||||
}
|
}
|
||||||
|
@ -9,4 +9,6 @@ struct OverviewSectionCleanTemplate: Template {
|
|||||||
static let templateName = "overview-section-clean.html"
|
static let templateName = "overview-section-clean.html"
|
||||||
|
|
||||||
let raw: String
|
let raw: String
|
||||||
|
|
||||||
|
let results: GenerationResultsHandler
|
||||||
}
|
}
|
||||||
|
@ -12,4 +12,6 @@ struct OverviewSectionTemplate: Template {
|
|||||||
static let templateName = "overview-section.html"
|
static let templateName = "overview-section.html"
|
||||||
|
|
||||||
let raw: String
|
let raw: String
|
||||||
|
|
||||||
|
let results: GenerationResultsHandler
|
||||||
}
|
}
|
||||||
|
@ -12,5 +12,7 @@ struct PageHeadTemplate: Template {
|
|||||||
|
|
||||||
let raw: String
|
let raw: String
|
||||||
|
|
||||||
|
let results: GenerationResultsHandler
|
||||||
|
|
||||||
static let templateName = "head.html"
|
static let templateName = "head.html"
|
||||||
}
|
}
|
||||||
|
@ -15,4 +15,6 @@ struct PageImageTemplate: Template {
|
|||||||
|
|
||||||
let raw: String
|
let raw: String
|
||||||
|
|
||||||
|
let results: GenerationResultsHandler
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@ struct PageLinkTemplate: Template {
|
|||||||
|
|
||||||
let raw: String
|
let raw: String
|
||||||
|
|
||||||
|
let results: GenerationResultsHandler
|
||||||
|
|
||||||
func makePath(components: [String]) -> String {
|
func makePath(components: [String]) -> String {
|
||||||
components.joined(separator: " » ") //  » ")
|
components.joined(separator: " » ") //  » ")
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ struct PageVideoTemplate: Template {
|
|||||||
|
|
||||||
let raw: String
|
let raw: String
|
||||||
|
|
||||||
|
let results: GenerationResultsHandler
|
||||||
|
|
||||||
func generate<T>(sources: [VideoSource], options: T) -> String where T: Sequence, T.Element == VideoOption {
|
func generate<T>(sources: [VideoSource], options: T) -> String where T: Sequence, T.Element == VideoOption {
|
||||||
let sourcesCode = sources.map(makeSource).joined(separator: "\n")
|
let sourcesCode = sources.map(makeSource).joined(separator: "\n")
|
||||||
let optionCode = options.map { $0.rawValue }.joined(separator: " ")
|
let optionCode = options.map { $0.rawValue }.joined(separator: " ")
|
||||||
|
@ -20,6 +20,8 @@ struct LargeThumbnailTemplate: Template, ThumbnailTemplate {
|
|||||||
|
|
||||||
let raw: String
|
let raw: String
|
||||||
|
|
||||||
|
let results: GenerationResultsHandler
|
||||||
|
|
||||||
func makeCorner(text: String) -> String {
|
func makeCorner(text: String) -> String {
|
||||||
"<span class=\"corner\"><span>\(text)</span></span>"
|
"<span class=\"corner\"><span>\(text)</span></span>"
|
||||||
}
|
}
|
||||||
@ -36,6 +38,8 @@ struct SquareThumbnailTemplate: Template, ThumbnailTemplate {
|
|||||||
static let templateName = "thumbnail-square.html"
|
static let templateName = "thumbnail-square.html"
|
||||||
|
|
||||||
let raw: String
|
let raw: String
|
||||||
|
|
||||||
|
let results: GenerationResultsHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SmallThumbnailTemplate: Template, ThumbnailTemplate {
|
struct SmallThumbnailTemplate: Template, ThumbnailTemplate {
|
||||||
@ -45,5 +49,7 @@ struct SmallThumbnailTemplate: Template, ThumbnailTemplate {
|
|||||||
static let templateName = "thumbnail-small.html"
|
static let templateName = "thumbnail-small.html"
|
||||||
|
|
||||||
let raw: String
|
let raw: String
|
||||||
|
|
||||||
|
let results: GenerationResultsHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,4 +12,6 @@ struct TopBarTemplate: Template {
|
|||||||
static let templateName = "bar.html"
|
static let templateName = "bar.html"
|
||||||
|
|
||||||
var raw: String
|
var raw: String
|
||||||
|
|
||||||
|
let results: GenerationResultsHandler
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ struct LocalizedSiteTemplate {
|
|||||||
factory.page
|
factory.page
|
||||||
}
|
}
|
||||||
|
|
||||||
init(factory: TemplateFactory, language: String, site: Element) {
|
init(factory: TemplateFactory, language: String, site: Element, log: GenerationResultsHandler) {
|
||||||
self.author = site.author
|
self.author = site.author
|
||||||
self.factory = factory
|
self.factory = factory
|
||||||
|
|
||||||
@ -67,9 +67,11 @@ struct LocalizedSiteTemplate {
|
|||||||
sections: sections,
|
sections: sections,
|
||||||
topBarWebsiteTitle: site.topBarTitle)
|
topBarWebsiteTitle: site.topBarTitle)
|
||||||
self.pageHead = PageHeadGenerator(
|
self.pageHead = PageHeadGenerator(
|
||||||
factory: factory)
|
factory: factory,
|
||||||
|
log: log)
|
||||||
self.overviewSection = OverviewSectionGenerator(
|
self.overviewSection = OverviewSectionGenerator(
|
||||||
factory: factory)
|
factory: factory,
|
||||||
|
log: log)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Content
|
// MARK: Content
|
||||||
|
@ -19,6 +19,8 @@ struct CenteredHeaderTemplate: Template {
|
|||||||
|
|
||||||
let raw: String
|
let raw: String
|
||||||
|
|
||||||
|
let results: GenerationResultsHandler
|
||||||
|
|
||||||
static let templateName = "header-center.html"
|
static let templateName = "header-center.html"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,5 +30,7 @@ struct LeftHeaderTemplate: Template {
|
|||||||
|
|
||||||
let raw: String
|
let raw: String
|
||||||
|
|
||||||
|
let results: GenerationResultsHandler
|
||||||
|
|
||||||
static let templateName = "header-left.html"
|
static let templateName = "header-left.html"
|
||||||
}
|
}
|
||||||
|
@ -18,4 +18,6 @@ struct PageTemplate: Template {
|
|||||||
static let templateName = "page.html"
|
static let templateName = "page.html"
|
||||||
|
|
||||||
let raw: String
|
let raw: String
|
||||||
|
|
||||||
|
let results: GenerationResultsHandler
|
||||||
}
|
}
|
||||||
|
@ -8,25 +8,28 @@ protocol Template {
|
|||||||
|
|
||||||
var raw: String { get }
|
var raw: String { get }
|
||||||
|
|
||||||
init(raw: String)
|
var results: GenerationResultsHandler { get }
|
||||||
|
|
||||||
|
init(raw: String, results: GenerationResultsHandler)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Template {
|
extension Template {
|
||||||
|
|
||||||
init(in folder: URL) throws {
|
init(in folder: URL, results: GenerationResultsHandler) throws {
|
||||||
let url = folder.appendingPathComponent(Self.templateName)
|
let url = folder.appendingPathComponent(Self.templateName)
|
||||||
try self.init(from: url)
|
try self.init(from: url, results: results)
|
||||||
}
|
}
|
||||||
|
|
||||||
init(from url: URL) throws {
|
init(from url: URL, results: GenerationResultsHandler) throws {
|
||||||
let raw = try String(contentsOf: url)
|
let raw = try String(contentsOf: url)
|
||||||
self.init(raw: raw)
|
self.init(raw: raw, results: results)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generate(_ content: [Key : String], to url: URL) -> Bool {
|
func generate(_ content: [Key : String], to url: URL) -> Bool {
|
||||||
let content = generate(content)
|
let content = generate(content)
|
||||||
return files.write(content, to: url)
|
#warning("log.write(content, to: url, file: )")
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func generate(_ content: [Key : String], shouldIndent: Bool = false) -> String {
|
func generate(_ content: [Key : String], shouldIndent: Bool = false) -> String {
|
||||||
|
@ -59,23 +59,23 @@ final class TemplateFactory {
|
|||||||
|
|
||||||
// MARK: Init
|
// MARK: Init
|
||||||
|
|
||||||
init(templateFolder: URL) throws {
|
init(templateFolder: URL, results: GenerationResultsHandler) throws {
|
||||||
self.templateFolder = templateFolder
|
self.templateFolder = templateFolder
|
||||||
self.backNavigation = try .init(in: templateFolder)
|
self.backNavigation = try .init(in: templateFolder, results: results)
|
||||||
self.pageHead = try .init(in: templateFolder)
|
self.pageHead = try .init(in: templateFolder, results: results)
|
||||||
self.topBar = try .init(in: templateFolder)
|
self.topBar = try .init(in: templateFolder, results: results)
|
||||||
self.overviewSection = try .init(in: templateFolder)
|
self.overviewSection = try .init(in: templateFolder, results: results)
|
||||||
self.overviewSectionClean = try .init(in: templateFolder)
|
self.overviewSectionClean = try .init(in: templateFolder, results: results)
|
||||||
self.box = try .init(in: templateFolder)
|
self.box = try .init(in: templateFolder, results: results)
|
||||||
self.pageLink = try .init(in: templateFolder)
|
self.pageLink = try .init(in: templateFolder, results: results)
|
||||||
self.largeThumbnail = try .init(in: templateFolder)
|
self.largeThumbnail = try .init(in: templateFolder, results: results)
|
||||||
self.squareThumbnail = try .init(in: templateFolder)
|
self.squareThumbnail = try .init(in: templateFolder, results: results)
|
||||||
self.smallThumbnail = try .init(in: templateFolder)
|
self.smallThumbnail = try .init(in: templateFolder, results: results)
|
||||||
self.leftHeader = try .init(in: templateFolder)
|
self.leftHeader = try .init(in: templateFolder, results: results)
|
||||||
self.centeredHeader = try .init(in: templateFolder)
|
self.centeredHeader = try .init(in: templateFolder, results: results)
|
||||||
self.page = try .init(in: templateFolder)
|
self.page = try .init(in: templateFolder, results: results)
|
||||||
self.image = try .init(in: templateFolder)
|
self.image = try .init(in: templateFolder, results: results)
|
||||||
self.video = try .init(in: templateFolder)
|
self.video = try .init(in: templateFolder, results: results)
|
||||||
self.html = .init()
|
self.html = .init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user