CHGenerator/Sources/Generator/Templates/TemplateFactory.swift
2022-12-08 17:16:54 +01:00

107 lines
2.5 KiB
Swift

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
let pageLink: PageLinkTemplate
let box: BoxTemplate
// 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
}
}
// MARK: Headers
let leftHeader: LeftHeaderTemplate
let centeredHeader: CenteredHeaderTemplate
// MARK: Pages
let page: PageTemplate
let image: PageImageTemplate
let largeImage: EnlargeableImageTemplate
let video: PageVideoTemplate
// MARK: Slideshow
let slideshows: SlideshowsTemplate
let slideshow: SlideshowTemplate
let slideshowImage: SlideshowImageTemplate
// MARK: HTML
let html: HTMLElementsGenerator
// MARK: Init
init(templateFolder: URL, results: GenerationResultsHandler) throws {
self.templateFolder = templateFolder
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()
}
// MARK: Convenience methods
func makePlaceholder(title: String, text: String) -> String {
box.generate([
.title: title,
.text: text])
}
}