CHGenerator/Sources/Generator/Templates/TemplateFactory.swift

90 lines
2.5 KiB
Swift
Raw Normal View History

2022-08-16 10:39:05 +02:00
import Foundation
final class TemplateFactory {
let templateFolder: URL
// MARK: Site Elements
let backNavigation: BackNavigationTemplate
let pageHead: PageHeadTemplate
let topBar: TopBarTemplate
let overviewSection: OverviewSectionTemplate
let overviewSectionClean: OverviewSectionCleanTemplate
2022-09-25 17:19:07 +02:00
let pageLink: PageLinkTemplate
2022-09-18 17:21:57 +02:00
let box: BoxTemplate
2022-08-16 10:39:05 +02:00
// MARK: Thumbnails
let largeThumbnail: LargeThumbnailTemplate
let squareThumbnail: SquareThumbnailTemplate
let smallThumbnail: SmallThumbnailTemplate
func thumbnail(style: ThumbnailStyle) -> ThumbnailTemplate {
switch style {
case .large:
return largeThumbnail
case .square:
return squareThumbnail
case .small:
return smallThumbnail
}
}
2022-08-16 12:27:13 +02:00
// MARK: Headers
let leftHeader: LeftHeaderTemplate
2022-08-16 10:39:05 +02:00
2022-08-16 12:27:13 +02:00
let centeredHeader: CenteredHeaderTemplate
// MARK: Pages
2022-08-16 10:39:05 +02:00
2022-08-16 12:27:13 +02:00
let page: PageTemplate
2022-08-16 10:39:05 +02:00
let image: PageImageTemplate
let video: PageVideoTemplate
// MARK: HTML
let html: HTMLElementsGenerator
2022-08-16 10:39:05 +02:00
// MARK: Init
2022-12-02 10:25:54 +01:00
init(templateFolder: URL, results: GenerationResultsHandler) throws {
2022-08-16 10:39:05 +02:00
self.templateFolder = templateFolder
2022-12-02 10:25:54 +01:00
self.backNavigation = try .init(in: templateFolder, results: results)
self.pageHead = try .init(in: templateFolder, results: results)
self.topBar = try .init(in: templateFolder, results: results)
self.overviewSection = try .init(in: templateFolder, results: results)
self.overviewSectionClean = try .init(in: templateFolder, results: results)
self.box = try .init(in: templateFolder, results: results)
self.pageLink = try .init(in: templateFolder, results: results)
self.largeThumbnail = try .init(in: templateFolder, results: results)
self.squareThumbnail = try .init(in: templateFolder, results: results)
self.smallThumbnail = try .init(in: templateFolder, results: results)
self.leftHeader = try .init(in: templateFolder, results: results)
self.centeredHeader = try .init(in: templateFolder, results: results)
self.page = try .init(in: templateFolder, results: results)
self.image = try .init(in: templateFolder, results: results)
self.video = try .init(in: templateFolder, results: results)
self.html = .init()
2022-08-16 10:39:05 +02:00
}
2022-09-18 17:21:57 +02:00
// MARK: Convenience methods
func makePlaceholder(title: String, text: String) -> String {
box.generate([
.title: title,
.text: text])
}
2022-08-16 10:39:05 +02:00
}