import Foundation struct OverviewPageGenerator { private let factory: LocalizedSiteTemplate private let results: GenerationResultsHandler init(factory: LocalizedSiteTemplate, results: GenerationResultsHandler) { self.factory = factory self.results = results } func generate( section: Element, language: String) { let path = section.localizedPath(for: language) let metadata = section.localized(for: language) var content = [PageTemplate.Key : String]() content[.head] = factory.pageHead.generate(page: section, language: language) let languageButton = section.nextLanguage(for: language) content[.topBar] = factory.topBar.generate( sectionUrl: section.sectionUrl(for: language), languageButton: languageButton, page: section) content[.language] = language content[.contentClass] = "overview" content[.header] = makeHeader(page: section, metadata: metadata, language: language) content[.content] = makeContent(section: section, language: language) content[.footer] = results.getContentOfOptionalFile(at: section.additionalFooterContentPath, source: section.path) factory.page.generate(content, to: path, source: section.path) } private func makeContent(section: Element, language: String) -> String { if section.hasNestingElements { return factory.overviewSection.generate( sections: section.sortedItems, in: section, language: language, sectionItemCount: section.overviewItemCount) } else { return factory.overviewSection.generate(section: section, language: language) } } private func makeHeader(page: Element, metadata: Element.LocalizedMetadata, language: String) -> String { let content = factory.makeHeaderContent(page: page, metadata: metadata, language: language) return factory.factory.centeredHeader.generate(content) } }