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

Commit 3df4fac

Browse files
authored
Merge pull request #55 from SwiftDocOrg/mattt/commonmark-output-improvements
CommonMark output improvements
2 parents 0b2291a + 5a68134 commit 3df4fac

File tree

4 files changed

+54
-28
lines changed

4 files changed

+54
-28
lines changed

Sources/SwiftDoc/SourceFile.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,14 @@ public struct SourceFile: Hashable, Codable {
112112
}
113113

114114
override func visit(_ node: EnumCaseDeclSyntax) -> SyntaxVisitorContinueKind {
115-
for `case` in Enumeration.Case.cases(from: node) {
115+
let cases = node.elements.compactMap { element in
116+
Enumeration.Case(element.withRawValue(nil))
117+
}
118+
119+
for `case` in cases {
116120
push(symbol(node, api: `case`))
117121
}
122+
118123
return .skipChildren
119124
}
120125

@@ -179,9 +184,14 @@ public struct SourceFile: Hashable, Codable {
179184
}
180185

181186
override func visit(_ node: VariableDeclSyntax) -> SyntaxVisitorContinueKind {
182-
for variable in Variable.variables(from: node) {
187+
let variables = node.bindings.compactMap { binding in
188+
Variable(binding.withInitializer(nil))
189+
}
190+
191+
for variable in variables {
183192
push(symbol(node, api: variable))
184193
}
194+
185195
return .skipChildren
186196
}
187197

Sources/swift-doc/Subcommands/Generate.swift

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extension SwiftDoc {
1717
var inputs: [String]
1818

1919
@Option(name: [.long, .customShort("n")],
20-
help: "The name of the module")
20+
help: "The name of the module")
2121
var moduleName: String
2222

2323
@Option(name: .shortAndLong,
@@ -47,15 +47,6 @@ extension SwiftDoc {
4747

4848
var pages: [String: Page] = [:]
4949

50-
switch format {
51-
case .commonmark:
52-
pages["Home"] = HomePage(module: module)
53-
pages["_Sidebar"] = SidebarPage(module: module)
54-
pages["_Footer"] = FooterPage()
55-
case .html:
56-
pages["Home"] = HomePage(module: module)
57-
}
58-
5950
var globals: [String: [Symbol]] = [:]
6051
for symbol in module.interface.topLevelSymbols.filter({ $0.isPublic }) {
6152
switch symbol.api {
@@ -76,19 +67,43 @@ extension SwiftDoc {
7667
pages[path(for: name)] = GlobalPage(module: module, name: name, symbols: symbols)
7768
}
7869

79-
try pages.map { $0 }.parallelForEach {
70+
guard !pages.isEmpty else { return }
71+
72+
if pages.count == 1, let page = pages.first?.value {
8073
let filename: String
8174
switch format {
8275
case .commonmark:
83-
filename = "\($0.key).md"
84-
case .html where $0.key == "Home":
85-
filename = "index.html"
76+
filename = "Home.md"
8677
case .html:
87-
filename = "\($0.key)/index.html"
78+
filename = "index.html"
8879
}
8980

9081
let url = outputDirectoryURL.appendingPathComponent(filename)
91-
try $0.value.write(to: url, format: format)
82+
try page.write(to: url, format: format)
83+
} else {
84+
switch format {
85+
case .commonmark:
86+
pages["Home"] = HomePage(module: module)
87+
pages["_Sidebar"] = SidebarPage(module: module)
88+
pages["_Footer"] = FooterPage()
89+
case .html:
90+
pages["Home"] = HomePage(module: module)
91+
}
92+
93+
try pages.map { $0 }.parallelForEach {
94+
let filename: String
95+
switch format {
96+
case .commonmark:
97+
filename = "\($0.key).md"
98+
case .html where $0.key == "Home":
99+
filename = "index.html"
100+
case .html:
101+
filename = "\($0.key)/index.html"
102+
}
103+
104+
let url = outputDirectoryURL.appendingPathComponent(filename)
105+
try $0.value.write(to: url, format: format)
106+
}
92107
}
93108
} catch {
94109
logger.error("\(error)")

Sources/swift-doc/Supporting Types/Components/Members.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,14 @@ struct Members: Component {
4949
ForEach(in: sections) { section -> BlockConvertible in
5050
Section {
5151
Heading { section.title }
52-
ForEach(in: section.members) { member in
53-
Heading { member.name }
54-
Documentation(for: member, in: module)
52+
53+
Section {
54+
ForEach(in: section.members) { member in
55+
Heading {
56+
Code { member.name }
57+
}
58+
Documentation(for: member, in: module)
59+
}
5560
}
5661
}
5762
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@ struct GlobalPage: Page {
2222

2323
var document: CommonMark.Document {
2424
return Document {
25-
Heading { name }
26-
27-
Section {
28-
ForEach(in: symbols) { symbol in
29-
Heading { symbol.id.description }
30-
Documentation(for: symbol, in: module)
31-
}
25+
ForEach(in: symbols) { symbol in
26+
Heading { symbol.id.description }
27+
Documentation(for: symbol, in: module)
3228
}
3329
}
3430
}

0 commit comments

Comments
 (0)