CHGenerator/Sources/Generator/Templates/TemplateFactory.swift

107 lines
2.5 KiB
Swift
Raw Permalink 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
2022-12-08 17:16:54 +01:00
let largeImage: EnlargeableImageTemplate
let video: PageVideoTemplate
// MARK: Slideshow
let slideshows: SlideshowsTemplate
let slideshow: SlideshowTemplate
let slideshowImage: SlideshowImageTemplate
// 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-08 17:16:54 +01:00
func create<T>() throws -> T where T: Template {
try .init(in: templateFolder, results: results)
}
self.backNavigation = try create()
self.pageHead = try create()
self.topBar = try create()
self.overviewSection = try create()
self.overviewSectionClean = try create()
self.box = try create()
self.pageLink = try create()
self.largeThumbnail = try create()
self.squareThumbnail = try create()
self.smallThumbnail = try create()
self.leftHeader = try create()
self.centeredHeader = try create()
self.page = try create()
self.image = try create()
self.largeImage = try create()
self.video = try create()
self.slideshow = try create()
self.slideshows = try create()
self.slideshowImage = try create()
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
}