Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 57b5d24

Browse files
keanmattt
authored andcommitted
Display globals on the home pages (fixes #69)
1 parent e88d5a4 commit 57b5d24

File tree

1 file changed

+59
-16
lines changed

1 file changed

+59
-16
lines changed

Sources/swift-doc/Supporting Types/Pages/HomePage.swift

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,67 @@ struct HomePage: Page {
112112
return #"""
113113
<section id=\#(heading.lowercased())>
114114
<h2>\#(heading)</h2>
115-
<dl>
116-
\#(symbols.sorted().map { symbol -> HypertextLiteral.HTML in
117-
let descriptor = String(describing: type(of: symbol.api)).lowercased()
118-
return #"""
119-
<dt class="\#(descriptor)">
120-
<a href=\#(path(for: symbol)) title="\#(descriptor) - \#(symbol.id.description)">
121-
\#(softbreak(symbol.id.description))
122-
</a>
123-
</dt>
124-
<dd>
125-
\#(commonmark: symbol.documentation?.summary ?? "")
126-
</dd>
127-
"""# as HypertextLiteral.HTML
128-
})
129-
</dl>
115+
\#(listHTML(symbols: symbols))
130116
</section>
131-
"""# as HypertextLiteral.HTML
117+
"""#
118+
})
119+
\#(globalsHTML)
120+
"""#
121+
}
122+
123+
private var globalsHTML: HypertextLiteral.HTML {
124+
guard !globalTypealias.isEmpty ||
125+
!globalFunctions.isEmpty ||
126+
!globalVariables.isEmpty else {
127+
return ""
128+
}
129+
130+
let heading = "Globals"
131+
return #"""
132+
<section id=\#(heading.lowercased())>
133+
<h2>\#(heading)</h2>
134+
\#(globalsListHTML)
135+
</section>
136+
"""#
137+
}
138+
139+
private var globalsListHTML: HypertextLiteral.HTML {
140+
let globals = [
141+
("Typealiases", globalTypealias),
142+
("Functions", globalFunctions),
143+
("Variables", globalVariables),
144+
]
145+
return #"""
146+
\#(globals.compactMap { (heading, symbols) -> HypertextLiteral.HTML? in
147+
guard !symbols.isEmpty else { return nil }
148+
149+
return #"""
150+
<section id=\#(heading.lowercased())>
151+
<h3>\#(heading)</h3>
152+
\#(listHTML(symbols: symbols))
153+
</section>
154+
"""#
132155
})
133156
"""#
134157
}
158+
159+
private func listHTML(symbols: [Symbol]) -> HypertextLiteral.HTML {
160+
#"""
161+
<dl>
162+
\#(symbols.sorted().map { symbol -> HypertextLiteral.HTML in
163+
let descriptor = String(describing: type(of: symbol.api)).lowercased()
164+
return #"""
165+
<dt class="\#(descriptor)">
166+
<a href=\#(path(for: symbol)) title="\#(descriptor) - \#(symbol.id.description)">
167+
\#(softbreak(symbol.id.description))
168+
</a>
169+
</dt>
170+
<dd>
171+
\#(commonmark: symbol.documentation?.summary ?? "")
172+
</dd>
173+
"""#
174+
})
175+
</dl>
176+
"""#
177+
}
135178
}

0 commit comments

Comments
 (0)