Skip to content

Commit

Permalink
Add changes for demo; default diff is only modules, classes, protocol…
Browse files Browse the repository at this point in the history
…s, and structs; and include --show-all flag for more granular symbol diff (i.e. all symbols that have changed).
  • Loading branch information
emilyychenn committed May 20, 2024
1 parent b6081e7 commit 8fae025
Show file tree
Hide file tree
Showing 4 changed files with 455 additions and 3 deletions.
21 changes: 21 additions & 0 deletions Sources/SwiftDocC/Model/Rendering/RenderNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,26 @@ public struct RenderNode: VariantContainer {
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Unknown RenderNode.Kind: '\(unknown)'.")
}
}

// // Return the string representing this kind.
// // If the kind is a symbol, return the symbol kind.
// public func kindString() -> String {
// var kind = ""
//
// switch(self) {
// case .article:
// kind = "article"
// case .tutorial:
// kind = "tutorial"
// case .section:
// kind = "section"
// case .overview:
// kind = "overview"
// case .symbol:
// kind = "symbol"
// }
//
// return kind
// }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
This source file is part of the Swift.org open source project
This source file is part doccof the Swift.org open source project

Copyright (c) 2024 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception
Expand Down Expand Up @@ -36,7 +36,9 @@ extension Docc.ProcessArchive {
"\(frameworkName.localizedCapitalized)_ChangeLog.md": """
# \(frameworkName.localizedCapitalized) Updates
@Metadata { @PageColor(yellow) }
@Metadata {
@PageColor(yellow)
}
Learn about important changes to \(frameworkName.localizedCapitalized).
Expand Down Expand Up @@ -222,6 +224,48 @@ extension Docc.ProcessArchive {
}
}

// TODO: CONTINUE
// func findPageType(symbolPath: URL) throws -> URL? {
// struct ContainerWithPageType: Codable {
// var pageType: NavigatorIndex.PageType
// }
//
// let renderJSONData = try Data(contentsOf: symbolPath)
// let decoder = RenderJSONDecoder.makeDecoder()
//
// do {
// let identifier = try decoder.decode(NavigatorIndex.self, from: renderJSONData).
// return identifier.url
// } catch {
// return nil
// }
// }

func findClassName(symbolPath: URL) -> String {
return symbolPath.lastPathComponent
}

// func findClassName(symbolPath: URL) throws -> [[String]]? {
// struct ContainerWithRenderHierarchy: Codable {
// var hierarchy: RenderHierarchy
// }
//
// let renderJSONData = try Data(contentsOf: symbolPath)
// let decoder = RenderJSONDecoder.makeDecoder()
//
// do {
// let hierarchy = try decoder.decode(ContainerWithRenderHierarchy.self, from: renderJSONData).hierarchy
//
// if hierarchy != nil {
// return hierarchy.paths
// }
//
// return identifier.url
// } catch {
// return nil
// }
// }

/// Process lists of symbols to group them according to the highest level path component, split by spaces.
func groupSymbols(symbolLinks: Set<URL>, frameworkName: String) -> String {
// Sort list alphabetically
Expand All @@ -239,7 +283,7 @@ extension Docc.ProcessArchive {

// If there are no common path components, add a space. Then reset the first to find the next parent.
if parent.localizedLowercase.hasSuffix(frameworkName + "/") {
links.append("\n\n")
links.append("\n \n")
first = symbol
}

Expand All @@ -248,6 +292,37 @@ extension Docc.ProcessArchive {

return links
}

func addClassNames(allSymbolsString: String) -> String {
// let processedString = ""

// Split string into string array on a double newline
return longestCommonPrefix(of: allSymbolsString)
}

func longestCommonPrefix(of string: String) -> String {

let words = string.split(separator: " ")
// let words = string.split(separator: "\n\n")
guard let first = words.first else {
return ""
}

var (minWord, maxWord) = (first, first)
for word in words.dropFirst() {
if word < minWord {
print(word)
print(maxWord)
minWord = word
} else if word > maxWord {
print(word)
print(maxWord)
maxWord = word
}
}

return minWord.commonPrefix(with: maxWord)
}

}
}
Loading

0 comments on commit 8fae025

Please sign in to comment.