Skip to content

Commit

Permalink
Unnest and pull bundle into a private let (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaandedeoglu authored Apr 12, 2021
1 parent 873063e commit ec1b7b0
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions Sources/Shark/SharkEnumBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
enum SharkEnumBuilder {
private static let bundleString = """
private static let bundle: Bundle = {
private let bundle: Bundle = {
class Custom {}
return Bundle(for: Custom.self)
}()
Expand All @@ -16,25 +16,40 @@ enum SharkEnumBuilder {

let declarationIndendationLevel = options.topLevelScope ? 0 : 1
let resourcesEnumsString = [imagesString, colorsString, fontsString, localizationsString]
.compactMap { $0 }
.compactMap({ $0?.indented(withLevel: declarationIndendationLevel) })
.joined(separator: "\n\n")

// bundleString + the I, C, F, L enums if present
let declarations = """
// // bundleString + the I, C, F, L enums if present
// let declarations = """
// \(bundleString)
//
// \(resourcesEnumsString)
// """
// .indented(withLevel: declarationIndendationLevel)
//
// if options.topLevelScope {
// return declarations
// } else {
// return """
// public enum \(options.topLevelEnumName) {
// \(declarations)
// }
// """
// }
//
var result = """
\(bundleString)
\(resourcesEnumsString)
"""
.indented(withLevel: declarationIndendationLevel)

if options.topLevelScope {
return declarations
result.append(resourcesEnumsString)
} else {
return """
public enum \(options.topLevelEnumName) {
\(declarations)
}
"""
result.append("public enum \(options.topLevelEnumName) {\n")
result.append(resourcesEnumsString)
result.append("\n}")
}
return result
}
}

0 comments on commit ec1b7b0

Please sign in to comment.