| 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). |
| 3 | | struct 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>`. |
| 19 | 105 | var html: String { |
| 20 | 105 | var tabs = [tabMarkup(.coverage, name: "Coverage", file: IndexPage.sitePath)] |
| 21 | 105 | if hasTestsPage { |
| 22 | 25 | tabs.append(tabMarkup(.tests, name: "Tests", file: TestsPage.sitePath)) |
| 23 | 25 | } |
| 24 | 105 | return """ |
| 25 | 105 | <h1 class="site-title">\(escapingHTML(title))</h1> |
| 26 | 105 | <nav class="tabs" aria-label="Report">\(tabs.joined())</nav> |
| 27 | 105 | """ |
| 28 | 105 | } |
| 29 | | |
| 30 | 130 | private func tabMarkup(_ tab: Tab, name: String, file: String) -> String { |
| 31 | 130 | let current = tab == currentTab ? #" aria-current="page""# : "" |
| 32 | 130 | return #"<a href="\#(rootPath)\#(file)"\#(current)>\#(name)</a>"# |
| 33 | 130 | } |
| 34 | | } |