Add availability to get keyPath from generated strings Key enumeration
Some checks are pending
gitea-openium/resgen.swift/pipeline/head Build started...
Some checks are pending
gitea-openium/resgen.swift/pipeline/head Build started...
This commit is contained in:
parent
beb28e652d
commit
844a8aec45
@ -133,7 +133,7 @@ class StringsFileGenerator {
|
||||
extensionSuffix: String) -> String {
|
||||
[
|
||||
Self.getHeader(stringsFilename: inputFilename, extensionClassname: extensionName),
|
||||
Self.getEnumKey(sections: sections, tags: tags, extensionSuffix: extensionSuffix),
|
||||
Self.getEnumKey(sections: sections, tags: tags, extensionClassname: extensionName, extensionSuffix: extensionSuffix),
|
||||
Self.getProperties(sections: sections, defaultLang: lang, tags: tags, staticVar: staticVar),
|
||||
Self.getFooter()
|
||||
]
|
||||
@ -154,9 +154,10 @@ class StringsFileGenerator {
|
||||
"""
|
||||
}
|
||||
|
||||
private static func getEnumKey(sections: [Section], tags: [String], extensionSuffix: String) -> String {
|
||||
private static func getEnumKey(sections: [Section], tags: [String], extensionClassname: String, extensionSuffix: String) -> String {
|
||||
var enumDefinition = "\n enum Key\(extensionSuffix.uppercasedFirst()): String {\n"
|
||||
|
||||
// Enum
|
||||
sections.forEach { section in
|
||||
// Check that at least one string will be generated
|
||||
guard section.hasOneOrMoreMatchingTags(tags: tags) else {
|
||||
@ -172,7 +173,27 @@ class StringsFileGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
enumDefinition += " }"
|
||||
// KeyPath accessors
|
||||
enumDefinition += "\n"
|
||||
enumDefinition += " var keyPath: KeyPath<\(extensionClassname), String> {\n"
|
||||
enumDefinition += " switch self {\n"
|
||||
sections.forEach { section in
|
||||
// Check that at least one string will be generated
|
||||
guard section.hasOneOrMoreMatchingTags(tags: tags) else {
|
||||
return // Go to next section
|
||||
}
|
||||
|
||||
section.definitions.forEach { definition in
|
||||
guard definition.hasOneOrMoreMatchingTags(inputTags: tags) == true else {
|
||||
return // Go to next definition
|
||||
}
|
||||
debugPrint("Found definition")
|
||||
enumDefinition += " case .\(definition.name): return \\\(extensionClassname).\(definition.name)\n"
|
||||
}
|
||||
}
|
||||
enumDefinition += " }\n" // Switch
|
||||
enumDefinition += " }\n" // var keyPath
|
||||
enumDefinition += " }" // Enum
|
||||
|
||||
return enumDefinition
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user