Skip to content

Commit

Permalink
Bundle support for framework (#16)
Browse files Browse the repository at this point in the history
* bundle support

* custom top level name

* adding bundle information for colors

* add bundle for NSLocalizedString

* bundle for NSLocalizedString
  • Loading branch information
quangDecember authored and kaandedeoglu committed Dec 21, 2019
1 parent 3302237 commit b1b95b7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Sources/Shark/ColorEnumBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ private enum ColorValue: Equatable, Comparable {
func declaration(indentLevel: Int) -> String {
switch self {
case .color(let name):
return #"\#(String(indentLevel: indentLevel))public static var \#(name.casenameSanitized): UIColor { return UIColor(named: "\#(name)")! }"#
return #"\#(String(indentLevel: indentLevel))public static var \#(name.casenameSanitized): UIColor { return UIColor(named: "\#(name)", in: \#(SharkEnumBuilder.topLevelEnumName).bundle, compatibleWith: nil)! }"#
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Shark/ImageEnumBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ private enum ImageValue: Equatable, Comparable {
func declaration(withBody body: String = "", indentLevel: Int) throws -> String {
switch self {
case .image(let name, let value):
return #"\#(String(indentLevel: indentLevel))public static var \#(name): UIImage { return UIImage(named:"\#(value)")! }"#
return #"\#(String(indentLevel: indentLevel))public static var \#(name): UIImage { return UIImage(named:"\#(value)", in: \#(SharkEnumBuilder.topLevelEnumName).bundle, compatibleWith: nil)! }"#
case .namespace(let name):
return #"""
\#(String(indentLevel: indentLevel))public enum \#(name) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Shark/LocalizationEnumBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private enum LocalizationValue: Comparable {
if interpolatedTypes.isEmpty == false {
result += interpolatedTypes.functionDeclaration(withName: name, key: key, indentLevel: indentLevel)
} else {
result += #"\#(String(indentLevel: indentLevel))public static var \#(name): String { return NSLocalizedString("\#(key)", comment: "") }"#
result += #"\#(String(indentLevel: indentLevel))public static var \#(name): String { return NSLocalizedString("\#(key)", bundle: \#(SharkEnumBuilder.topLevelEnumName).bundle, comment: "") }"#
}
}
return result
Expand Down Expand Up @@ -154,7 +154,7 @@ extension Array where Element == LocalizationValue.InterpolationType {

return #"""
\#(String(indentLevel: indentLevel))public static func \#(name)(\#(argumentsString)) -> String {
\#(String(indentLevel:indentLevel + 1))return String(format: NSLocalizedString("\#(key)", comment: ""), \#(formatValuesString))
\#(String(indentLevel:indentLevel + 1))return String(format: NSLocalizedString("\#(key)", bundle: \#(SharkEnumBuilder.topLevelEnumName).bundle, comment: ""), \#(formatValuesString))
\#(String(indentLevel: indentLevel))}
"""#
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/Shark/SharkEnumBuilder.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation

enum SharkEnumBuilder {
static var topLevelEnumName = "Shark"
static func sharkEnumString(forParseResult parseResult: Parser.Result) throws -> String {
SharkEnumBuilder.topLevelEnumName = parseResult.topLevelEnumName
let resourcePaths = try XcodeProjectHelper(parseResult: parseResult).resourcePaths()

let imagesString = try ImageEnumBuilder.imageEnumString(forFilesAtPaths: resourcePaths.assetsPaths, topLevelName: "I")
Expand All @@ -12,6 +14,8 @@ enum SharkEnumBuilder {

return """
public enum \(parseResult.topLevelEnumName) {
private class Custom {}
static var bundle: Bundle { return Bundle(for: Custom.self) }
\(declarations)
}
"""
Expand Down

0 comments on commit b1b95b7

Please sign in to comment.