1/// The top of every page: the project's name and the tabs that move between the
2/// coverage report and the test results (docs/DESIGN.md, D4).
3struct SiteHeader {
4 enum Tab {
5 case coverage
6 case tests
7 }
8
9 /// The project's name, shown as given.
10 let title: String
11 let currentTab: Tab
12 /// The Tests tab is left out when the site has no tests page to link.
13 let hasTestsPage: Bool
14 /// The path from the page's folder back to the site's root: empty beside the index,
15 /// `../` one folder down.
16 let rootPath: String
17
18 /// The heading and the tabs, for the page to put at the top of its `<header>`.
19105 var html: String {
20105 var tabs = [tabMarkup(.coverage, name: "Coverage", file: IndexPage.sitePath)]
21105 if hasTestsPage {
2225 tabs.append(tabMarkup(.tests, name: "Tests", file: TestsPage.sitePath))
2325 }
24105 return """
25105 <h1 class="site-title">\(escapingHTML(title))</h1>
26105 <nav class="tabs" aria-label="Report">\(tabs.joined())</nav>
27105 """
28105 }
29
30130 private func tabMarkup(_ tab: Tab, name: String, file: String) -> String {
31130 let current = tab == currentTab ? #" aria-current="page""# : ""
32130 return #"<a href="\#(rootPath)\#(file)"\#(current)>\#(name)</a>"#
33130 }
34}