Skip to content

Commit 289c9a4

Browse files
authored
Add Github URLs (#12)
1 parent f23e1d6 commit 289c9a4

File tree

32 files changed

+460
-108
lines changed

32 files changed

+460
-108
lines changed

Sources/CLI/CLI.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ public struct CLICore {
158158
InputModuleInfo(
159159
name: "Hylo",
160160
rootFolderPath: modulePaths[0],
161-
astId: coreLibraryId
161+
astId: coreLibraryId,
162+
openSourceUrlBase: URL(string: "https://github.com/hylo-lang/hylo/blob/main/StandardLibrary/Sources/")!
162163
)
163164
],
164165
ast
@@ -192,7 +193,8 @@ public struct CLICore {
192193

193194
return InputModuleInfo(
194195
name: "\(sourceURL.lastPathComponent)",
195-
rootFolderPath: sourceURL, astId: rootModuleId
196+
rootFolderPath: sourceURL, astId: rootModuleId,
197+
openSourceUrlBase: nil // todo: allow input of open source url base
196198
)
197199
}
198200

Sources/DocExtractor/RealAssetScanner.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ public struct InputModuleInfo {
88
public let name: String
99
public let rootFolderPath: URL
1010
public let astId: ModuleDecl.ID
11+
public let openSourceUrlBase: URL?
1112

12-
public init(name: String, rootFolderPath: URL, astId: ModuleDecl.ID) {
13+
public init(name: String, rootFolderPath: URL, astId: ModuleDecl.ID, openSourceUrlBase: URL?) {
1314
self.name = name
1415
self.rootFolderPath = rootFolderPath
1516
self.astId = astId
17+
self.openSourceUrlBase = openSourceUrlBase
1618
}
1719
}
1820

@@ -22,7 +24,8 @@ extension ModuleInfo {
2224
name: inputInfo.name,
2325
rootFolderPath: inputInfo.rootFolderPath,
2426
astId: inputInfo.astId,
25-
rootFolder: rootFolderId
27+
rootFolder: rootFolderId,
28+
openSourceUrlBase: inputInfo.openSourceUrlBase
2629
)
2730
}
2831
}
@@ -177,7 +180,7 @@ public struct DocDBBuildingAssetScanner<SFDocumentor: SourceFileDocumentor>: Ass
177180

178181
public mutating func build() -> Result<DocumentationDatabase, DocExtractionError<Self>> {
179182
modules
180-
.map { module in
183+
.map { (module: InputModuleInfo) in
181184
recursivelyVisitFolder(
182185
folderPath: module.rootFolderPath.absoluteURL,
183186
visitor: &self,
@@ -186,7 +189,7 @@ public struct DocDBBuildingAssetScanner<SFDocumentor: SourceFileDocumentor>: Ass
186189
.map { (module, rootFolderId: $0) }
187190
}
188191
.collectResults()
189-
.map { extendedModuleInfos in
192+
.map { (extendedModuleInfos: [(module: InputModuleInfo, rootFolderId: FolderAsset.ID)]) in
190193
DocumentationDatabase(
191194
assets: assets,
192195
symbols: symbolDocs,

Sources/DocumentationDB/ModuleInfo.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ public struct ModuleInfo: IdentifiedEntity {
66
public let rootFolderPath: URL
77
public let rootFolder: FolderAsset.ID
88
public let astId: ModuleDecl.ID
9+
/// The base URL for the open source repository where we should link to the source code.
10+
///
11+
/// E.g. https://github.com/hylo-lang/hylo/blob/main/StandardLibrary/Sources/
12+
public let openSourceUrlBase: URL?
913

10-
public init(name: String, rootFolderPath: URL, astId: ModuleDecl.ID, rootFolder: FolderAsset.ID) {
14+
public init(name: String, rootFolderPath: URL, astId: ModuleDecl.ID, rootFolder: FolderAsset.ID, openSourceUrlBase: URL?) {
1115
self.name = name
1216
self.rootFolderPath = rootFolderPath
1317
self.rootFolder = rootFolder
1418
self.astId = astId
19+
self.openSourceUrlBase = openSourceUrlBase
1520
}
1621
}

Sources/WebsiteGen/Generation/GeneratePages.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,15 @@ public func generateModuleIndex(_ context: inout GenerationContext) throws {
162162
public func generateTree(_ stencil: inout Environment, _ documentation: DocumentationContext) throws
163163
-> String
164164
{
165-
return try documentation.targetResolver.rootTargets.map {
166-
documentation.targetResolver.navigationItemFromTarget(targetId: $0)
167-
}
168-
.filter { $0 != nil }
169-
.map {
170-
try stencil.renderTemplate(name: "page_components/tree_item.html", context: ["item": $0 as Any])
171-
}
172-
.joined(separator: "\n")
165+
return try documentation.targetResolver.rootTargets
166+
.compactMap {
167+
documentation.targetResolver.navigationItemFromTarget(targetId: $0)
168+
}
169+
.map {
170+
try stencil.renderTemplate(
171+
name: "page_components/tree_item.html",
172+
context: ["item": $0 as Any]
173+
)
174+
}
175+
.joined(separator: "\n")
173176
}

Sources/WebsiteGen/Resolution/Navigation.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public struct NavigationItem {
66
let name: String
77
let url: URL
88
let cssClassOfTarget: String
9+
let openSourceUrl: URL?
910

1011
// Relations
1112
let children: [NavigationItem]

0 commit comments

Comments
 (0)