From 254a040a16ad8af4c446b63439432fedd1227990 Mon Sep 17 00:00:00 2001 From: David Jennes Date: Sat, 19 Aug 2017 15:08:42 +0200 Subject: [PATCH 1/5] pod install --- Podfile.lock | 2 +- Pods/Manifest.lock | 2 +- Pods/StencilSwiftKit/README.md | 2 +- .../Sources/Filters+Strings.swift | 78 +++++++++++++------ .../Sources/SwiftIdentifier.swift | 64 ++++++++------- 5 files changed, 97 insertions(+), 51 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 5b0715a..e2755b4 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -15,7 +15,7 @@ EXTERNAL SOURCES: CHECKOUT OPTIONS: StencilSwiftKit: - :commit: 3ba083dea79a953156a3f128dcad0452f62a8132 + :commit: fe07cd4c1f081565948d29963491748f2709d0e2 :git: https://github.com/SwiftGen/StencilSwiftKit SPEC CHECKSUMS: diff --git a/Pods/Manifest.lock b/Pods/Manifest.lock index 5b0715a..e2755b4 100644 --- a/Pods/Manifest.lock +++ b/Pods/Manifest.lock @@ -15,7 +15,7 @@ EXTERNAL SOURCES: CHECKOUT OPTIONS: StencilSwiftKit: - :commit: 3ba083dea79a953156a3f128dcad0452f62a8132 + :commit: fe07cd4c1f081565948d29963491748f2709d0e2 :git: https://github.com/SwiftGen/StencilSwiftKit SPEC CHECKSUMS: diff --git a/Pods/StencilSwiftKit/README.md b/Pods/StencilSwiftKit/README.md index 32d78fc..2b18725 100644 --- a/Pods/StencilSwiftKit/README.md +++ b/Pods/StencilSwiftKit/README.md @@ -36,7 +36,7 @@ * `removeNewlines`: Removes newlines and other whitespace characters, depending on the mode ("all" or "leading"). * `replace`: Replaces instances of a substring with a new string. * `snakeToCamelCase`: Transforms text from snake_case to camelCase. By default it keeps leading underscores, unless a single optional argument is set to "true", "yes" or "1". - * `swiftIdentifier`: Transforms an arbitrary string into a valid Swift identifier (using only valid characters for a Swift identifier as defined in the Swift language reference) + * `swiftIdentifier`: Transforms an arbitrary string into a valid Swift identifier (using only valid characters for a Swift identifier as defined in the Swift language reference). In "pretty" mode, it will also apply the snakeToCamelCase filter afterwards, and other manipulations if needed for a "prettier" but still valid identifier. * `upperFirstLetter`: Uppercases only the first character * [Number filters](Documentation/filters-numbers.md): * `int255toFloat` diff --git a/Pods/StencilSwiftKit/Sources/Filters+Strings.swift b/Pods/StencilSwiftKit/Sources/Filters+Strings.swift index a6133db..b4671b4 100644 --- a/Pods/StencilSwiftKit/Sources/Filters+Strings.swift +++ b/Pods/StencilSwiftKit/Sources/Filters+Strings.swift @@ -11,6 +11,10 @@ enum RemoveNewlinesModes: String { case all, leading } +enum SwiftIdentifierModes: String { + case normal, pretty +} + extension Filters { enum Strings { fileprivate static let reservedKeywords = [ @@ -50,9 +54,29 @@ extension Filters { return source.replacingOccurrences(of: substring, with: replacement) } - static func swiftIdentifier(_ value: Any?) throws -> Any? { - guard let value = value as? String else { throw Filters.Error.invalidInputType } - return StencilSwiftKit.swiftIdentifier(from: value, replaceWithUnderscores: true) + /// Converts an arbitrary string to a valid swift identifier. Takes an optional Mode argument: + /// - normal (default): uppercase the first character, prefix with an underscore if starting + /// with a number, replace invalid characters by underscores + /// - leading: same as the above, but apply the snaceToCamelCase filter first for a nicer + /// identifier + /// + /// - Parameters: + /// - value: the value to be processed + /// - arguments: the arguments to the function; expecting zero or one mode argument + /// - Returns: the identifier string + /// - Throws: FilterError.invalidInputType if the value parameter isn't a string + static func swiftIdentifier(_ value: Any?, arguments: [Any?]) throws -> Any? { + guard var string = value as? String else { throw Filters.Error.invalidInputType } + let mode = try Filters.parseEnum(from: arguments, default: SwiftIdentifierModes.normal) + + switch mode { + case .normal: + return SwiftIdentifier.identifier(from: string, replaceWithUnderscores: true) + case .pretty: + string = SwiftIdentifier.identifier(from: string, replaceWithUnderscores: true) + string = try snakeToCamelCase(string, stripLeading: true) + return SwiftIdentifier.prefixWithUnderscoreIfNeeded(string: string) + } } /// Lowers the first letter of the string @@ -112,25 +136,7 @@ extension Filters { let stripLeading = try Filters.parseBool(from: arguments, required: false) ?? false guard let string = value as? String else { throw Filters.Error.invalidInputType } - let unprefixed: String - if try containsAnyLowercasedChar(string) { - let comps = string.components(separatedBy: "_") - unprefixed = comps.map { titlecase($0) }.joined(separator: "") - } else { - let comps = try snakecase(string).components(separatedBy: "_") - unprefixed = comps.map { $0.capitalized }.joined(separator: "") - } - - // only if passed true, strip the prefix underscores - var prefixUnderscores = "" - if !stripLeading { - for scalar in string.unicodeScalars { - guard scalar == "_" else { break } - prefixUnderscores += "_" - } - } - - return prefixUnderscores + unprefixed + return try snakeToCamelCase(string, stripLeading: stripLeading) } /// Converts camelCase to snake_case. Takes an optional Bool argument for making the string lower case, @@ -253,6 +259,34 @@ extension Filters { return String(chars) } + /// Converts snake_case to camelCase, stripping prefix underscores if needed + /// + /// - Parameters: + /// - string: the value to be processed + /// - stripLeading: if false, will preserve leading underscores + /// - Returns: the camel case string + static func snakeToCamelCase(_ string: String, stripLeading: Bool) throws -> String { + let unprefixed: String + if try containsAnyLowercasedChar(string) { + let comps = string.components(separatedBy: "_") + unprefixed = comps.map { titlecase($0) }.joined(separator: "") + } else { + let comps = try snakecase(string).components(separatedBy: "_") + unprefixed = comps.map { $0.capitalized }.joined(separator: "") + } + + // only if passed true, strip the prefix underscores + var prefixUnderscores = "" + if !stripLeading { + for scalar in string.unicodeScalars { + guard scalar == "_" else { break } + prefixUnderscores += "_" + } + } + + return prefixUnderscores + unprefixed + } + /// This returns the string with its first parameter uppercased. /// - note: This is quite similar to `capitalise` except that this filter doesn't /// lowercase the rest of the string but keeps it untouched. diff --git a/Pods/StencilSwiftKit/Sources/SwiftIdentifier.swift b/Pods/StencilSwiftKit/Sources/SwiftIdentifier.swift index 68d9e5e..b470e9d 100644 --- a/Pods/StencilSwiftKit/Sources/SwiftIdentifier.swift +++ b/Pods/StencilSwiftKit/Sources/SwiftIdentifier.swift @@ -32,7 +32,7 @@ private let tailRanges: [CountableClosedRange] = [ 0x30...0x39, 0x300...0x36F, 0x1dc0...0x1dff, 0x20d0...0x20ff, 0xfe20...0xfe2f ] -private func identifierCharacterSets() -> (head: NSMutableCharacterSet, tail: NSMutableCharacterSet) { +private func identifierCharacterSets(exceptions: String) -> (head: NSMutableCharacterSet, tail: NSMutableCharacterSet) { let addRange: (NSMutableCharacterSet, CountableClosedRange) -> Void = { (mcs, range) in mcs.addCharacters(in: NSRange(location: range.lowerBound, length: range.count)) } @@ -41,6 +41,7 @@ private func identifierCharacterSets() -> (head: NSMutableCharacterSet, tail: NS for range in headRanges { addRange(head, range) } + head.removeCharacters(in: exceptions) guard let tail = head.mutableCopy() as? NSMutableCharacterSet else { fatalError("Internal error: mutableCopy() should have returned a valid NSMutableCharacterSet") @@ -48,35 +49,46 @@ private func identifierCharacterSets() -> (head: NSMutableCharacterSet, tail: NS for range in tailRanges { addRange(tail, range) } + tail.removeCharacters(in: exceptions) return (head, tail) } -func swiftIdentifier(from string: String, - forbiddenChars exceptions: String = "", - replaceWithUnderscores underscores: Bool = false) -> String { +enum SwiftIdentifier { + static func identifier(from string: String, + forbiddenChars exceptions: String = "", + replaceWithUnderscores underscores: Bool = false) -> String { - let (head, tail) = identifierCharacterSets() - head.removeCharacters(in: exceptions) - tail.removeCharacters(in: exceptions) + let (_, tail) = identifierCharacterSets(exceptions: exceptions) + + let parts = string.components(separatedBy: tail.inverted) + let replacement = underscores ? "_" : "" + let mappedParts = parts.map({ (string: String) -> String in + // Can't use capitalizedString here because it will lowercase all letters after the first + // e.g. "SomeNiceIdentifier".capitalizedString will because "Someniceidentifier" which is not what we want + let ns = NSString(string: string) + if ns.length > 0 { + let firstLetter = ns.substring(to: 1) + let rest = ns.substring(from: 1) + return firstLetter.uppercased() + rest + } else { + return "" + } + }) - let chars = string.unicodeScalars - let firstChar = chars[chars.startIndex] - - let prefix = !head.longCharacterIsMember(firstChar.value) && tail.longCharacterIsMember(firstChar.value) ? "_" : "" - let parts = string.components(separatedBy: tail.inverted) - let replacement = underscores ? "_" : "" - let mappedParts = parts.map({ (string: String) -> String in - // Can't use capitalizedString here because it will lowercase all letters after the first - // e.g. "SomeNiceIdentifier".capitalizedString will because "Someniceidentifier" which is not what we want - let ns = NSString(string: string) - if ns.length > 0 { - let firstLetter = ns.substring(to: 1) - let rest = ns.substring(from: 1) - return firstLetter.uppercased() + rest - } else { - return "" - } - }) - return prefix + mappedParts.joined(separator: replacement) + let result = mappedParts.joined(separator: replacement) + return prefixWithUnderscoreIfNeeded(string: result, forbiddenChars: exceptions) + } + + static func prefixWithUnderscoreIfNeeded(string: String, + forbiddenChars exceptions: String = "") -> String { + + let (head, _) = identifierCharacterSets(exceptions: exceptions) + + let chars = string.unicodeScalars + let firstChar = chars[chars.startIndex] + let prefix = !head.longCharacterIsMember(firstChar.value) ? "_" : "" + + return prefix + string + } } From 49a7a75cf4d056563a7ddcba8339a75cc7165d66 Mon Sep 17 00:00:00 2001 From: David Jennes Date: Sat, 19 Aug 2017 15:36:16 +0200 Subject: [PATCH 2/5] update the templates to use the new filter option --- Tests/Expected/Colors/swift2-context-multiple.swift | 2 +- .../swift2-context-all-customname.swift | 6 +++--- .../swift2-context-all-ignore-module.swift | 6 +++--- .../Storyboards-iOS/swift2-context-all.swift | 6 +++--- templates/colors/literals-swift3.stencil | 4 ++-- templates/colors/literals-swift4.stencil | 4 ++-- templates/colors/swift2.stencil | 4 ++-- templates/colors/swift3.stencil | 4 ++-- templates/colors/swift4.stencil | 4 ++-- templates/fonts/swift2.stencil | 4 ++-- templates/fonts/swift3.stencil | 4 ++-- templates/fonts/swift4.stencil | 4 ++-- templates/storyboards/swift2.stencil | 8 ++++---- templates/storyboards/swift3.stencil | 8 ++++---- templates/storyboards/swift4.stencil | 8 ++++---- templates/strings/flat-swift2.stencil | 6 +++--- templates/strings/flat-swift3.stencil | 6 +++--- templates/strings/flat-swift4.stencil | 6 +++--- templates/strings/structured-swift2.stencil | 8 ++++---- templates/strings/structured-swift3.stencil | 8 ++++---- templates/strings/structured-swift4.stencil | 8 ++++---- templates/xcassets/swift2.stencil | 12 ++++++------ templates/xcassets/swift3.stencil | 12 ++++++------ templates/xcassets/swift4.stencil | 12 ++++++------ 24 files changed, 77 insertions(+), 77 deletions(-) diff --git a/Tests/Expected/Colors/swift2-context-multiple.swift b/Tests/Expected/Colors/swift2-context-multiple.swift index 0cf338b..812c468 100644 --- a/Tests/Expected/Colors/swift2-context-multiple.swift +++ b/Tests/Expected/Colors/swift2-context-multiple.swift @@ -54,7 +54,7 @@ struct ColorName { static let ArticleTitle = ColorName(rgbaValue: 0x33fe66ff) /// /// Alpha: 100%
(0xff66ccff) - static let Cyan_Color = ColorName(rgbaValue: 0xff66ccff) + static let CyanColor = ColorName(rgbaValue: 0xff66ccff) /// /// Alpha: 80%
(0xffffffcc) static let NamedValue = ColorName(rgbaValue: 0xffffffcc) diff --git a/Tests/Expected/Storyboards-iOS/swift2-context-all-customname.swift b/Tests/Expected/Storyboards-iOS/swift2-context-all-customname.swift index 69e7bf2..17e5767 100644 --- a/Tests/Expected/Storyboards-iOS/swift2-context-all-customname.swift +++ b/Tests/Expected/Storyboards-iOS/swift2-context-all-customname.swift @@ -92,13 +92,13 @@ enum XCTStoryboardsScene { static let initialScene = InitialSceneType(Wizard.self) - static let Accept_CGU = SceneType(Wizard.self, identifier: "Accept-CGU") + static let AcceptCGU = SceneType(Wizard.self, identifier: "Accept-CGU") static let CreateAccount = SceneType(Wizard.self, identifier: "CreateAccount") static let Preferences = SceneType(Wizard.self, identifier: "Preferences") - static let Validate_Password = SceneType(Wizard.self, identifier: "Validate_Password") + static let ValidatePassword = SceneType(Wizard.self, identifier: "Validate_Password") } } @@ -110,7 +110,7 @@ enum XCTStoryboardsSegue { case CustomBack case Embed case NonCustom - case Show_NavCtrl = "Show-NavCtrl" + case ShowNavCtrl = "Show-NavCtrl" } enum Wizard: String, SegueType { case ShowPassword diff --git a/Tests/Expected/Storyboards-iOS/swift2-context-all-ignore-module.swift b/Tests/Expected/Storyboards-iOS/swift2-context-all-ignore-module.swift index 408a5bb..c97d266 100644 --- a/Tests/Expected/Storyboards-iOS/swift2-context-all-ignore-module.swift +++ b/Tests/Expected/Storyboards-iOS/swift2-context-all-ignore-module.swift @@ -91,13 +91,13 @@ enum StoryboardScene { static let initialScene = InitialSceneType(Wizard.self) - static let Accept_CGU = SceneType(Wizard.self, identifier: "Accept-CGU") + static let AcceptCGU = SceneType(Wizard.self, identifier: "Accept-CGU") static let CreateAccount = SceneType(Wizard.self, identifier: "CreateAccount") static let Preferences = SceneType(Wizard.self, identifier: "Preferences") - static let Validate_Password = SceneType(Wizard.self, identifier: "Validate_Password") + static let ValidatePassword = SceneType(Wizard.self, identifier: "Validate_Password") } } @@ -109,7 +109,7 @@ enum StoryboardSegue { case CustomBack case Embed case NonCustom - case Show_NavCtrl = "Show-NavCtrl" + case ShowNavCtrl = "Show-NavCtrl" } enum Wizard: String, SegueType { case ShowPassword diff --git a/Tests/Expected/Storyboards-iOS/swift2-context-all.swift b/Tests/Expected/Storyboards-iOS/swift2-context-all.swift index b8f27a1..a2f30d4 100644 --- a/Tests/Expected/Storyboards-iOS/swift2-context-all.swift +++ b/Tests/Expected/Storyboards-iOS/swift2-context-all.swift @@ -92,13 +92,13 @@ enum StoryboardScene { static let initialScene = InitialSceneType(Wizard.self) - static let Accept_CGU = SceneType(Wizard.self, identifier: "Accept-CGU") + static let AcceptCGU = SceneType(Wizard.self, identifier: "Accept-CGU") static let CreateAccount = SceneType(Wizard.self, identifier: "CreateAccount") static let Preferences = SceneType(Wizard.self, identifier: "Preferences") - static let Validate_Password = SceneType(Wizard.self, identifier: "Validate_Password") + static let ValidatePassword = SceneType(Wizard.self, identifier: "Validate_Password") } } @@ -110,7 +110,7 @@ enum StoryboardSegue { case CustomBack case Embed case NonCustom - case Show_NavCtrl = "Show-NavCtrl" + case ShowNavCtrl = "Show-NavCtrl" } enum Wizard: String, SegueType { case ShowPassword diff --git a/templates/colors/literals-swift3.stencil b/templates/colors/literals-swift3.stencil index ee1b107..3e35229 100644 --- a/templates/colors/literals-swift3.stencil +++ b/templates/colors/literals-swift3.stencil @@ -20,12 +20,12 @@ extension {{enumName}} { {% macro enumBlock colors sp %} {{sp}} {% for color in colors %} {{sp}} /// 0x{{color.red}}{{color.green}}{{color.blue}}{{color.alpha}} (r: {{color.red|hexToInt}}, g: {{color.green|hexToInt}}, b: {{color.blue|hexToInt}}, a: {{color.alpha|hexToInt}}) -{{sp}} static let {{color.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}} = #colorLiteral(red: {% call h2f color.red %}, green: {% call h2f color.green %}, blue: {% call h2f color.blue %}, alpha: {% call h2f color.alpha %}) +{{sp}} static let {{color.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = #colorLiteral(red: {% call h2f color.red %}, green: {% call h2f color.green %}, blue: {% call h2f color.blue %}, alpha: {% call h2f color.alpha %}) {{sp}} {% endfor %} {% endmacro %} {% if palettes.count > 1 %} {% for palette in palettes %} - enum {{palette.name|swiftIdentifier|titlecase|snakeToCamelCase|escapeReservedKeywords}} { + enum {{palette.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% call enumBlock palette.colors " " %} } {% endfor %} diff --git a/templates/colors/literals-swift4.stencil b/templates/colors/literals-swift4.stencil index ee1b107..3e35229 100644 --- a/templates/colors/literals-swift4.stencil +++ b/templates/colors/literals-swift4.stencil @@ -20,12 +20,12 @@ extension {{enumName}} { {% macro enumBlock colors sp %} {{sp}} {% for color in colors %} {{sp}} /// 0x{{color.red}}{{color.green}}{{color.blue}}{{color.alpha}} (r: {{color.red|hexToInt}}, g: {{color.green|hexToInt}}, b: {{color.blue|hexToInt}}, a: {{color.alpha|hexToInt}}) -{{sp}} static let {{color.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}} = #colorLiteral(red: {% call h2f color.red %}, green: {% call h2f color.green %}, blue: {% call h2f color.blue %}, alpha: {% call h2f color.alpha %}) +{{sp}} static let {{color.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = #colorLiteral(red: {% call h2f color.red %}, green: {% call h2f color.green %}, blue: {% call h2f color.blue %}, alpha: {% call h2f color.alpha %}) {{sp}} {% endfor %} {% endmacro %} {% if palettes.count > 1 %} {% for palette in palettes %} - enum {{palette.name|swiftIdentifier|titlecase|snakeToCamelCase|escapeReservedKeywords}} { + enum {{palette.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% call enumBlock palette.colors " " %} } {% endfor %} diff --git a/templates/colors/swift2.stencil b/templates/colors/swift2.stencil index e966b68..97d424c 100644 --- a/templates/colors/swift2.stencil +++ b/templates/colors/swift2.stencil @@ -35,12 +35,12 @@ struct {{enumName}} { {{sp}} {% for color in colors %} {{sp}} /// {{sp}} /// Alpha: {{color.alpha|hexToInt|int255toFloat|percent}}
(0x{{color.red}}{{color.green}}{{color.blue}}{{color.alpha}}) -{{sp}} static let {{color.name|swiftIdentifier|escapeReservedKeywords}} = {{enumName}}(rgbaValue: {% call rgbaValue color %}) +{{sp}} static let {{color.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} = {{enumName}}(rgbaValue: {% call rgbaValue color %}) {{sp}} {% endfor %} {% endmacro %} {% if palettes.count > 1 %} {% for palette in palettes %} - enum {{palette.name|swiftIdentifier|titlecase|snakeToCamelCase|escapeReservedKeywords}} { + enum {{palette.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% call enumBlock palette.colors " " %} } {% endfor %} diff --git a/templates/colors/swift3.stencil b/templates/colors/swift3.stencil index c91467d..2a09016 100644 --- a/templates/colors/swift3.stencil +++ b/templates/colors/swift3.stencil @@ -35,12 +35,12 @@ struct {{enumName}} { {{sp}} {% for color in colors %} {{sp}} /// {{sp}} /// Alpha: {{color.alpha|hexToInt|int255toFloat|percent}}
(0x{{color.red}}{{color.green}}{{color.blue}}{{color.alpha}}) -{{sp}} static let {{color.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}(rgbaValue: {% call rgbaValue color %}) +{{sp}} static let {{color.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}(rgbaValue: {% call rgbaValue color %}) {{sp}} {% endfor %} {% endmacro %} {% if palettes.count > 1 %} {% for palette in palettes %} - enum {{palette.name|swiftIdentifier|titlecase|snakeToCamelCase|escapeReservedKeywords}} { + enum {{palette.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% call enumBlock palette.colors " " %} } {% endfor %} diff --git a/templates/colors/swift4.stencil b/templates/colors/swift4.stencil index c91467d..2a09016 100644 --- a/templates/colors/swift4.stencil +++ b/templates/colors/swift4.stencil @@ -35,12 +35,12 @@ struct {{enumName}} { {{sp}} {% for color in colors %} {{sp}} /// {{sp}} /// Alpha: {{color.alpha|hexToInt|int255toFloat|percent}}
(0x{{color.red}}{{color.green}}{{color.blue}}{{color.alpha}}) -{{sp}} static let {{color.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}(rgbaValue: {% call rgbaValue color %}) +{{sp}} static let {{color.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}(rgbaValue: {% call rgbaValue color %}) {{sp}} {% endfor %} {% endmacro %} {% if palettes.count > 1 %} {% for palette in palettes %} - enum {{palette.name|swiftIdentifier|titlecase|snakeToCamelCase|escapeReservedKeywords}} { + enum {{palette.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% call enumBlock palette.colors " " %} } {% endfor %} diff --git a/templates/fonts/swift2.stencil b/templates/fonts/swift2.stencil index d45478e..3b7bd83 100644 --- a/templates/fonts/swift2.stencil +++ b/templates/fonts/swift2.stencil @@ -58,9 +58,9 @@ extension Font { {% endfilter %}{% endmacro %} enum {{param.enumName|default:"FontFamily"}} { {% for family in families %} - enum {{family.name|swiftIdentifier|snakeToCamelCase:"true"|escapeReservedKeywords}} { + enum {{family.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% for font in family.fonts %} - static let {{font.style|swiftIdentifier|snakeToCamelCase:"true"|escapeReservedKeywords}} = FontConvertible("{{font.name}}", family: "{{family.name}}", path: "{% call transformPath font.path %}") + static let {{font.style|swiftIdentifier:"pretty"|escapeReservedKeywords}} = FontConvertible("{{font.name}}", family: "{{family.name}}", path: "{% call transformPath font.path %}") {% endfor %} } {% endfor %} diff --git a/templates/fonts/swift3.stencil b/templates/fonts/swift3.stencil index 09f5b88..6759f1e 100644 --- a/templates/fonts/swift3.stencil +++ b/templates/fonts/swift3.stencil @@ -58,9 +58,9 @@ extension Font { {% endfilter %}{% endmacro %} enum {{param.enumName|default:"FontFamily"}} { {% for family in families %} - enum {{family.name|swiftIdentifier|snakeToCamelCase:"true"|escapeReservedKeywords}} { + enum {{family.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% for font in family.fonts %} - static let {{font.style|swiftIdentifier|snakeToCamelCase:"true"|lowerFirstWord|escapeReservedKeywords}} = FontConvertible(name: "{{font.name}}", family: "{{family.name}}", path: "{% call transformPath font.path %}") + static let {{font.style|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = FontConvertible(name: "{{font.name}}", family: "{{family.name}}", path: "{% call transformPath font.path %}") {% endfor %} } {% endfor %} diff --git a/templates/fonts/swift4.stencil b/templates/fonts/swift4.stencil index 53886e1..ec61014 100644 --- a/templates/fonts/swift4.stencil +++ b/templates/fonts/swift4.stencil @@ -58,9 +58,9 @@ extension Font { {% endfilter %}{% endmacro %} enum {{param.enumName|default:"FontFamily"}} { {% for family in families %} - enum {{family.name|swiftIdentifier|snakeToCamelCase:"true"|escapeReservedKeywords}} { + enum {{family.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% for font in family.fonts %} - static let {{font.style|swiftIdentifier|snakeToCamelCase:"true"|lowerFirstWord|escapeReservedKeywords}} = FontConvertible(name: "{{font.name}}", family: "{{family.name}}", path: "{% call transformPath font.path %}") + static let {{font.style|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = FontConvertible(name: "{{font.name}}", family: "{{family.name}}", path: "{% call transformPath font.path %}") {% endfor %} } {% endfor %} diff --git a/templates/storyboards/swift2.stencil b/templates/storyboards/swift2.stencil index 328ce8f..f3360d9 100644 --- a/templates/storyboards/swift2.stencil +++ b/templates/storyboards/swift2.stencil @@ -68,7 +68,7 @@ extension {% if isAppKit %}NSSeguePerforming{% else %}UIViewController{% endif % {% endfilter %}{% endmacro %} enum {{sceneEnumName}} { {% for storyboard in storyboards %} - {% set storyboardName %}{{storyboard.name|swiftIdentifier|escapeReservedKeywords}}{% endset %} + {% set storyboardName %}{{storyboard.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}{% endset %} enum {{storyboardName}}: StoryboardType { static let storyboardName = "{{storyboard.name}}" {% if storyboard.initialScene %} @@ -78,7 +78,7 @@ enum {{sceneEnumName}} { {% endif %} {% for scene in storyboard.scenes %} - {% set sceneID %}{{scene.identifier|swiftIdentifier|escapeReservedKeywords}}{% endset %} + {% set sceneID %}{{scene.identifier|swiftIdentifier:"pretty"|escapeReservedKeywords}}{% endset %} {% set sceneClass %}{% call className scene %}{% endset %} static let {{sceneID}} = SceneType<{{sceneClass}}>({{storyboardName}}.self, identifier: "{{scene.identifier}}") {% endfor %} @@ -88,9 +88,9 @@ enum {{sceneEnumName}} { enum {{param.segueEnumName|default:"StoryboardSegue"}} { {% for storyboard in storyboards where storyboard.segues %} - enum {{storyboard.name|swiftIdentifier|escapeReservedKeywords}}: String, SegueType { + enum {{storyboard.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}: String, SegueType { {% for segue in storyboard.segues %} - {% set segueID %}{{segue.identifier|swiftIdentifier}}{% endset %} + {% set segueID %}{{segue.identifier|swiftIdentifier:"pretty"}}{% endset %} case {{segueID|escapeReservedKeywords}}{% if segueID != segue.identifier %} = "{{segue.identifier}}"{% endif %} {% endfor %} } diff --git a/templates/storyboards/swift3.stencil b/templates/storyboards/swift3.stencil index 5bd5aa3..91b3d31 100644 --- a/templates/storyboards/swift3.stencil +++ b/templates/storyboards/swift3.stencil @@ -68,7 +68,7 @@ extension {% if isAppKit %}NSSeguePerforming{% else %}UIViewController{% endif % {% endfilter %}{% endmacro %} enum {{sceneEnumName}} { {% for storyboard in storyboards %} - {% set storyboardName %}{{storyboard.name|swiftIdentifier|escapeReservedKeywords}}{% endset %} + {% set storyboardName %}{{storyboard.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}{% endset %} enum {{storyboardName}}: StoryboardType { static let storyboardName = "{{storyboard.name}}" {% if storyboard.initialScene %} @@ -78,7 +78,7 @@ enum {{sceneEnumName}} { {% endif %} {% for scene in storyboard.scenes %} - {% set sceneID %}{{scene.identifier|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}}{% endset %} + {% set sceneID %}{{scene.identifier|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}{% endset %} {% set sceneClass %}{% call className scene %}{% endset %} static let {{sceneID}} = SceneType<{{sceneClass}}>(storyboard: {{storyboardName}}.self, identifier: "{{scene.identifier}}") {% endfor %} @@ -88,9 +88,9 @@ enum {{sceneEnumName}} { enum {{param.segueEnumName|default:"StoryboardSegue"}} { {% for storyboard in storyboards where storyboard.segues %} - enum {{storyboard.name|swiftIdentifier|escapeReservedKeywords}}: String, SegueType { + enum {{storyboard.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}: String, SegueType { {% for segue in storyboard.segues %} - {% set segueID %}{{segue.identifier|swiftIdentifier|snakeToCamelCase|lowerFirstWord}}{% endset %} + {% set segueID %}{{segue.identifier|swiftIdentifier:"pretty"|lowerFirstWord}}{% endset %} case {{segueID|escapeReservedKeywords}}{% if segueID != segue.identifier %} = "{{segue.identifier}}"{% endif %} {% endfor %} } diff --git a/templates/storyboards/swift4.stencil b/templates/storyboards/swift4.stencil index 04e4cdc..c0910a4 100644 --- a/templates/storyboards/swift4.stencil +++ b/templates/storyboards/swift4.stencil @@ -71,7 +71,7 @@ extension {% if isAppKit %}NSSeguePerforming{% else %}UIViewController{% endif % {% endfilter %}{% endmacro %} enum {{sceneEnumName}} { {% for storyboard in storyboards %} - {% set storyboardName %}{{storyboard.name|swiftIdentifier|escapeReservedKeywords}}{% endset %} + {% set storyboardName %}{{storyboard.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}{% endset %} enum {{storyboardName}}: StoryboardType { static let storyboardName = "{{storyboard.name}}" {% if storyboard.initialScene %} @@ -81,7 +81,7 @@ enum {{sceneEnumName}} { {% endif %} {% for scene in storyboard.scenes %} - {% set sceneID %}{{scene.identifier|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}}{% endset %} + {% set sceneID %}{{scene.identifier|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}{% endset %} {% set sceneClass %}{% call className scene %}{% endset %} static let {{sceneID}} = SceneType<{{sceneClass}}>(storyboard: {{storyboardName}}.self, identifier: "{{scene.identifier}}") {% endfor %} @@ -91,9 +91,9 @@ enum {{sceneEnumName}} { enum {{param.segueEnumName|default:"StoryboardSegue"}} { {% for storyboard in storyboards where storyboard.segues %} - enum {{storyboard.name|swiftIdentifier|escapeReservedKeywords}}: String, SegueType { + enum {{storyboard.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}: String, SegueType { {% for segue in storyboard.segues %} - {% set segueID %}{{segue.identifier|swiftIdentifier|snakeToCamelCase|lowerFirstWord}}{% endset %} + {% set segueID %}{{segue.identifier|swiftIdentifier:"pretty"|lowerFirstWord}}{% endset %} case {{segueID|escapeReservedKeywords}}{% if segueID != segue.identifier %} = "{{segue.identifier}}"{% endif %} {% endfor %} } diff --git a/templates/strings/flat-swift2.stencil b/templates/strings/flat-swift2.stencil index cfa66cf..f5d9988 100644 --- a/templates/strings/flat-swift2.stencil +++ b/templates/strings/flat-swift2.stencil @@ -20,11 +20,11 @@ import Foundation {{sp}} /// {{string.translation}} {{sp}} {% endif %} {{sp}} {% if string.types %} -{{sp}} static func {{string.key|swiftIdentifier|snakeToCamelCase|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String { +{{sp}} static func {{string.key|swiftIdentifier:"pretty"|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String { {{sp}} return {{enumName}}.tr("{{table}}", "{{string.key}}", {% call argumentsBlock string.types %}) {{sp}} } {{sp}} {% else %} -{{sp}} static let {{string.key|swiftIdentifier|snakeToCamelCase|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}") +{{sp}} static let {{string.key|swiftIdentifier:"pretty"|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}") {{sp}} {% endif %} {{sp}} {% endfor %} {{sp}} {% for child in item.children %} @@ -37,7 +37,7 @@ import Foundation enum {{enumName}} { {% if tables.count > 1 %} {% for table in tables %} - enum {{table.name|swiftIdentifier|snakeToCamelCase}} { + enum {{table.name|swiftIdentifier:"pretty"}} { {% call recursiveBlock table.name table.levels " " %} } {% endfor %} diff --git a/templates/strings/flat-swift3.stencil b/templates/strings/flat-swift3.stencil index 466e156..ef6a68a 100644 --- a/templates/strings/flat-swift3.stencil +++ b/templates/strings/flat-swift3.stencil @@ -20,11 +20,11 @@ import Foundation {{sp}} /// {{string.translation}} {{sp}} {% endif %} {{sp}} {% if string.types %} -{{sp}} static func {{string.key|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String { +{{sp}} static func {{string.key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String { {{sp}} return {{enumName}}.tr("{{table}}", "{{string.key}}", {% call argumentsBlock string.types %}) {{sp}} } {{sp}} {% else %} -{{sp}} static let {{string.key|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}") +{{sp}} static let {{string.key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}") {{sp}} {% endif %} {{sp}} {% endfor %} {{sp}} {% for child in item.children %} @@ -37,7 +37,7 @@ import Foundation enum {{enumName}} { {% if tables.count > 1 %} {% for table in tables %} - enum {{table.name|swiftIdentifier|snakeToCamelCase}} { + enum {{table.name|swiftIdentifier:"pretty"}} { {% call recursiveBlock table.name table.levels " " %} } {% endfor %} diff --git a/templates/strings/flat-swift4.stencil b/templates/strings/flat-swift4.stencil index 91a061a..7e74106 100644 --- a/templates/strings/flat-swift4.stencil +++ b/templates/strings/flat-swift4.stencil @@ -20,11 +20,11 @@ import Foundation {{sp}} /// {{string.translation}} {{sp}} {% endif %} {{sp}} {% if string.types %} -{{sp}} static func {{string.key|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String { +{{sp}} static func {{string.key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String { {{sp}} return {{enumName}}.tr("{{table}}", "{{string.key}}", {% call argumentsBlock string.types %}) {{sp}} } {{sp}} {% else %} -{{sp}} static let {{string.key|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}") +{{sp}} static let {{string.key|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}") {{sp}} {% endif %} {{sp}} {% endfor %} {{sp}} {% for child in item.children %} @@ -37,7 +37,7 @@ import Foundation enum {{enumName}} { {% if tables.count > 1 %} {% for table in tables %} - enum {{table.name|swiftIdentifier|snakeToCamelCase}} { + enum {{table.name|swiftIdentifier:"pretty"}} { {% call recursiveBlock table.name table.levels " " %} } {% endfor %} diff --git a/templates/strings/structured-swift2.stencil b/templates/strings/structured-swift2.stencil index 80f8aca..74e47e7 100644 --- a/templates/strings/structured-swift2.stencil +++ b/templates/strings/structured-swift2.stencil @@ -20,16 +20,16 @@ import Foundation {{sp}} /// {{string.translation}} {{sp}} {% endif %} {{sp}} {% if string.types %} -{{sp}} static func {{string.name|swiftIdentifier|snakeToCamelCase|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String { +{{sp}} static func {{string.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String { {{sp}} return {{enumName}}.tr("{{table}}", "{{string.key}}", {% call argumentsBlock string.types %}) {{sp}} } {{sp}} {% else %} -{{sp}} static let {{string.name|swiftIdentifier|snakeToCamelCase|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}") +{{sp}} static let {{string.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}") {{sp}} {% endif %} {{sp}} {% endfor %} {{sp}} {% for child in item.children %} -{{sp}} enum {{child.name|swiftIdentifier|snakeToCamelCase}} { +{{sp}} enum {{child.name|swiftIdentifier:"pretty"}} { {{sp}} {% set sp2 %}{{sp}} {% endset %} {{sp}} {% call recursiveBlock table child sp2 %} {{sp}} } @@ -41,7 +41,7 @@ import Foundation enum {{enumName}} { {% if tables.count > 1 %} {% for table in tables %} - enum {{table.name|swiftIdentifier|snakeToCamelCase}} { + enum {{table.name|swiftIdentifier:"pretty"}} { {% call recursiveBlock table.name table.levels " " %} } {% endfor %} diff --git a/templates/strings/structured-swift3.stencil b/templates/strings/structured-swift3.stencil index ba40993..a46d705 100644 --- a/templates/strings/structured-swift3.stencil +++ b/templates/strings/structured-swift3.stencil @@ -20,16 +20,16 @@ import Foundation {{sp}} /// {{string.translation}} {{sp}} {% endif %} {{sp}} {% if string.types %} -{{sp}} static func {{string.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String { +{{sp}} static func {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String { {{sp}} return {{enumName}}.tr("{{table}}", "{{string.key}}", {% call argumentsBlock string.types %}) {{sp}} } {{sp}} {% else %} -{{sp}} static let {{string.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}") +{{sp}} static let {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}") {{sp}} {% endif %} {{sp}} {% endfor %} {{sp}} {% for child in item.children %} -{{sp}} enum {{child.name|swiftIdentifier|snakeToCamelCase}} { +{{sp}} enum {{child.name|swiftIdentifier:"pretty"}} { {{sp}} {% set sp2 %}{{sp}} {% endset %} {{sp}} {% call recursiveBlock table child sp2 %} {{sp}} } @@ -41,7 +41,7 @@ import Foundation enum {{enumName}} { {% if tables.count > 1 %} {% for table in tables %} - enum {{table.name|swiftIdentifier|snakeToCamelCase}} { + enum {{table.name|swiftIdentifier:"pretty"}} { {% call recursiveBlock table.name table.levels " " %} } {% endfor %} diff --git a/templates/strings/structured-swift4.stencil b/templates/strings/structured-swift4.stencil index 92ef3fb..30beb04 100644 --- a/templates/strings/structured-swift4.stencil +++ b/templates/strings/structured-swift4.stencil @@ -20,16 +20,16 @@ import Foundation {{sp}} /// {{string.translation}} {{sp}} {% endif %} {{sp}} {% if string.types %} -{{sp}} static func {{string.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String { +{{sp}} static func {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}({% call parametersBlock string.types %}) -> String { {{sp}} return {{enumName}}.tr("{{table}}", "{{string.key}}", {% call argumentsBlock string.types %}) {{sp}} } {{sp}} {% else %} -{{sp}} static let {{string.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}") +{{sp}} static let {{string.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{enumName}}.tr("{{table}}", "{{string.key}}") {{sp}} {% endif %} {{sp}} {% endfor %} {{sp}} {% for child in item.children %} -{{sp}} enum {{child.name|swiftIdentifier|snakeToCamelCase}} { +{{sp}} enum {{child.name|swiftIdentifier:"pretty"}} { {{sp}} {% set sp2 %}{{sp}} {% endset %} {{sp}} {% call recursiveBlock table child sp2 %} {{sp}} } @@ -41,7 +41,7 @@ import Foundation enum {{enumName}} { {% if tables.count > 1 %} {% for table in tables %} - enum {{table.name|swiftIdentifier|snakeToCamelCase}} { + enum {{table.name|swiftIdentifier:"pretty"}} { {% call recursiveBlock table.name table.levels " " %} } {% endfor %} diff --git a/templates/xcassets/swift2.stencil b/templates/xcassets/swift2.stencil index 9b98b4e..202f93b 100644 --- a/templates/xcassets/swift2.stencil +++ b/templates/xcassets/swift2.stencil @@ -65,11 +65,11 @@ struct {{colorType}} { {% macro casesBlock assets sp %} {{sp}} {% for asset in assets %} {{sp}} {% if asset.type == "color" %} -{{sp}} static let {{asset.name|swiftIdentifier|snakeToCamelCase|escapeReservedKeywords}} = {{colorType}}(name: "{{asset.value}}") +{{sp}} static let {{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} = {{colorType}}(name: "{{asset.value}}") {{sp}} {% elif asset.type == "image" %} -{{sp}} static let {{asset.name|swiftIdentifier|snakeToCamelCase|escapeReservedKeywords}} = {{imageType}}(name: "{{asset.value}}") +{{sp}} static let {{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} = {{imageType}}(name: "{{asset.value}}") {{sp}} {% elif asset.items %} -{{sp}} enum {{asset.name|swiftIdentifier|snakeToCamelCase|escapeReservedKeywords}} { +{{sp}} enum {{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {{sp}} {% set sp2 %}{{sp}} {% endset %} {{sp}} {% call casesBlock asset.items sp2 %} {{sp}} } @@ -79,9 +79,9 @@ struct {{colorType}} { {% macro allValuesBlock assets filter prefix sp %} {{sp}} {% for asset in assets %} {{sp}} {% if asset.type == filter %} -{{sp}} {{prefix}}{{asset.name|swiftIdentifier|snakeToCamelCase|escapeReservedKeywords}}, +{{sp}} {{prefix}}{{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}, {{sp}} {% elif asset.items %} -{{sp}} {% set prefix2 %}{{prefix}}{{asset.name|swiftIdentifier|snakeToCamelCase|escapeReservedKeywords}}.{% endset %} +{{sp}} {% set prefix2 %}{{prefix}}{{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}.{% endset %} {{sp}} {% call allValuesBlock asset.items filter prefix2 sp %} {{sp}} {% endif %} {{sp}} {% endfor %} @@ -91,7 +91,7 @@ struct {{colorType}} { enum {{enumName}} { {% if catalogs.count > 1 %} {% for catalog in catalogs %} - enum {{catalog.name|swiftIdentifier|titlecase|snakeToCamelCase|escapeReservedKeywords}} { + enum {{catalog.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% call enumBlock catalog.assets " " %} } {% endfor %} diff --git a/templates/xcassets/swift3.stencil b/templates/xcassets/swift3.stencil index b6c9d6a..16e0657 100644 --- a/templates/xcassets/swift3.stencil +++ b/templates/xcassets/swift3.stencil @@ -65,11 +65,11 @@ struct {{colorType}} { {% macro casesBlock assets sp %} {{sp}} {% for asset in assets %} {{sp}} {% if asset.type == "color" %} -{{sp}} static let {{asset.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}} = {{colorType}}(name: "{{asset.value}}") +{{sp}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{colorType}}(name: "{{asset.value}}") {{sp}} {% elif asset.type == "image" %} -{{sp}} static let {{asset.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}} = {{imageType}}(name: "{{asset.value}}") +{{sp}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{imageType}}(name: "{{asset.value}}") {{sp}} {% elif asset.items %} -{{sp}} enum {{asset.name|swiftIdentifier|snakeToCamelCase|escapeReservedKeywords}} { +{{sp}} enum {{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {{sp}} {% set sp2 %}{{sp}} {% endset %} {{sp}} {% call casesBlock asset.items sp2 %} {{sp}} } @@ -79,9 +79,9 @@ struct {{colorType}} { {% macro allValuesBlock assets filter prefix sp %} {{sp}} {% for asset in assets %} {{sp}} {% if asset.type == filter %} -{{sp}} {{prefix}}{{asset.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}}, +{{sp}} {{prefix}}{{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}, {{sp}} {% elif asset.items %} -{{sp}} {% set prefix2 %}{{prefix}}{{asset.name|swiftIdentifier|snakeToCamelCase|escapeReservedKeywords}}.{% endset %} +{{sp}} {% set prefix2 %}{{prefix}}{{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}.{% endset %} {{sp}} {% call allValuesBlock asset.items filter prefix2 sp %} {{sp}} {% endif %} {{sp}} {% endfor %} @@ -91,7 +91,7 @@ struct {{colorType}} { enum {{enumName}} { {% if catalogs.count > 1 %} {% for catalog in catalogs %} - enum {{catalog.name|swiftIdentifier|snakeToCamelCase|escapeReservedKeywords}} { + enum {{catalog.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% call enumBlock catalog.assets " " %} } {% endfor %} diff --git a/templates/xcassets/swift4.stencil b/templates/xcassets/swift4.stencil index 75bc266..79b2af0 100644 --- a/templates/xcassets/swift4.stencil +++ b/templates/xcassets/swift4.stencil @@ -65,11 +65,11 @@ struct {{colorType}} { {% macro casesBlock assets sp %} {{sp}} {% for asset in assets %} {{sp}} {% if asset.type == "color" %} -{{sp}} static let {{asset.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}} = {{colorType}}(name: "{{asset.value}}") +{{sp}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{colorType}}(name: "{{asset.value}}") {{sp}} {% elif asset.type == "image" %} -{{sp}} static let {{asset.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}} = {{imageType}}(name: "{{asset.value}}") +{{sp}} static let {{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}} = {{imageType}}(name: "{{asset.value}}") {{sp}} {% elif asset.items %} -{{sp}} enum {{asset.name|swiftIdentifier|snakeToCamelCase|escapeReservedKeywords}} { +{{sp}} enum {{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {{sp}} {% set sp2 %}{{sp}} {% endset %} {{sp}} {% call casesBlock asset.items sp2 %} {{sp}} } @@ -79,9 +79,9 @@ struct {{colorType}} { {% macro allValuesBlock assets filter prefix sp %} {{sp}} {% for asset in assets %} {{sp}} {% if asset.type == filter %} -{{sp}} {{prefix}}{{asset.name|swiftIdentifier|snakeToCamelCase|lowerFirstWord|escapeReservedKeywords}}, +{{sp}} {{prefix}}{{asset.name|swiftIdentifier:"pretty"|lowerFirstWord|escapeReservedKeywords}}, {{sp}} {% elif asset.items %} -{{sp}} {% set prefix2 %}{{prefix}}{{asset.name|swiftIdentifier|snakeToCamelCase|escapeReservedKeywords}}.{% endset %} +{{sp}} {% set prefix2 %}{{prefix}}{{asset.name|swiftIdentifier:"pretty"|escapeReservedKeywords}}.{% endset %} {{sp}} {% call allValuesBlock asset.items filter prefix2 sp %} {{sp}} {% endif %} {{sp}} {% endfor %} @@ -91,7 +91,7 @@ struct {{colorType}} { enum {{enumName}} { {% if catalogs.count > 1 %} {% for catalog in catalogs %} - enum {{catalog.name|swiftIdentifier|snakeToCamelCase|escapeReservedKeywords}} { + enum {{catalog.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% call enumBlock catalog.assets " " %} } {% endfor %} From f660ec216ea146e63a71813785917e46ac5fa82c Mon Sep 17 00:00:00 2001 From: David Jennes Date: Sat, 19 Aug 2017 17:17:44 +0200 Subject: [PATCH 3/5] add some missing `escapeReservedKeywords` --- templates/strings/flat-swift2.stencil | 2 +- templates/strings/flat-swift3.stencil | 2 +- templates/strings/flat-swift4.stencil | 2 +- templates/strings/structured-swift2.stencil | 4 ++-- templates/strings/structured-swift3.stencil | 4 ++-- templates/strings/structured-swift4.stencil | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/templates/strings/flat-swift2.stencil b/templates/strings/flat-swift2.stencil index f5d9988..bff42ab 100644 --- a/templates/strings/flat-swift2.stencil +++ b/templates/strings/flat-swift2.stencil @@ -37,7 +37,7 @@ import Foundation enum {{enumName}} { {% if tables.count > 1 %} {% for table in tables %} - enum {{table.name|swiftIdentifier:"pretty"}} { + enum {{table.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% call recursiveBlock table.name table.levels " " %} } {% endfor %} diff --git a/templates/strings/flat-swift3.stencil b/templates/strings/flat-swift3.stencil index ef6a68a..1255743 100644 --- a/templates/strings/flat-swift3.stencil +++ b/templates/strings/flat-swift3.stencil @@ -37,7 +37,7 @@ import Foundation enum {{enumName}} { {% if tables.count > 1 %} {% for table in tables %} - enum {{table.name|swiftIdentifier:"pretty"}} { + enum {{table.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% call recursiveBlock table.name table.levels " " %} } {% endfor %} diff --git a/templates/strings/flat-swift4.stencil b/templates/strings/flat-swift4.stencil index 7e74106..3bfe5f5 100644 --- a/templates/strings/flat-swift4.stencil +++ b/templates/strings/flat-swift4.stencil @@ -37,7 +37,7 @@ import Foundation enum {{enumName}} { {% if tables.count > 1 %} {% for table in tables %} - enum {{table.name|swiftIdentifier:"pretty"}} { + enum {{table.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% call recursiveBlock table.name table.levels " " %} } {% endfor %} diff --git a/templates/strings/structured-swift2.stencil b/templates/strings/structured-swift2.stencil index 74e47e7..c0aea7a 100644 --- a/templates/strings/structured-swift2.stencil +++ b/templates/strings/structured-swift2.stencil @@ -29,7 +29,7 @@ import Foundation {{sp}} {% endfor %} {{sp}} {% for child in item.children %} -{{sp}} enum {{child.name|swiftIdentifier:"pretty"}} { +{{sp}} enum {{child.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {{sp}} {% set sp2 %}{{sp}} {% endset %} {{sp}} {% call recursiveBlock table child sp2 %} {{sp}} } @@ -41,7 +41,7 @@ import Foundation enum {{enumName}} { {% if tables.count > 1 %} {% for table in tables %} - enum {{table.name|swiftIdentifier:"pretty"}} { + enum {{table.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% call recursiveBlock table.name table.levels " " %} } {% endfor %} diff --git a/templates/strings/structured-swift3.stencil b/templates/strings/structured-swift3.stencil index a46d705..1d292e0 100644 --- a/templates/strings/structured-swift3.stencil +++ b/templates/strings/structured-swift3.stencil @@ -29,7 +29,7 @@ import Foundation {{sp}} {% endfor %} {{sp}} {% for child in item.children %} -{{sp}} enum {{child.name|swiftIdentifier:"pretty"}} { +{{sp}} enum {{child.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {{sp}} {% set sp2 %}{{sp}} {% endset %} {{sp}} {% call recursiveBlock table child sp2 %} {{sp}} } @@ -41,7 +41,7 @@ import Foundation enum {{enumName}} { {% if tables.count > 1 %} {% for table in tables %} - enum {{table.name|swiftIdentifier:"pretty"}} { + enum {{table.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% call recursiveBlock table.name table.levels " " %} } {% endfor %} diff --git a/templates/strings/structured-swift4.stencil b/templates/strings/structured-swift4.stencil index 30beb04..641dbdd 100644 --- a/templates/strings/structured-swift4.stencil +++ b/templates/strings/structured-swift4.stencil @@ -29,7 +29,7 @@ import Foundation {{sp}} {% endfor %} {{sp}} {% for child in item.children %} -{{sp}} enum {{child.name|swiftIdentifier:"pretty"}} { +{{sp}} enum {{child.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {{sp}} {% set sp2 %}{{sp}} {% endset %} {{sp}} {% call recursiveBlock table child sp2 %} {{sp}} } @@ -41,7 +41,7 @@ import Foundation enum {{enumName}} { {% if tables.count > 1 %} {% for table in tables %} - enum {{table.name|swiftIdentifier:"pretty"}} { + enum {{table.name|swiftIdentifier:"pretty"|escapeReservedKeywords}} { {% call recursiveBlock table.name table.levels " " %} } {% endfor %} From 35c42f549da1ae79f953ccc9d13a558cf6e98737 Mon Sep 17 00:00:00 2001 From: David Jennes Date: Sat, 19 Aug 2017 17:23:38 +0200 Subject: [PATCH 4/5] Changelog entry --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c63ea45..d57e9df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,9 @@ ### Bug Fixes -_None_ +* Templates now use the "pretty" mode of the `swiftIdentifier` filter, fixing some issues with identifiers starting with a number. + [David Jennes](https://github.com/djbe) + [#74](https://github.com/SwiftGen/templates/pull/74) ### Breaking Changes From 58cb617faa197f61ad5b825cae35d0a804112903 Mon Sep 17 00:00:00 2001 From: David Jennes Date: Sun, 20 Aug 2017 19:05:23 +0200 Subject: [PATCH 5/5] pod update SSK to 2.1.0 --- Podfile.lock | 6 +++--- Pods/Local Podspecs/StencilSwiftKit.podspec.json | 4 ++-- Pods/Manifest.lock | 6 +++--- Pods/Target Support Files/StencilSwiftKit/Info.plist | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index e2755b4..aab7219 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -2,7 +2,7 @@ PODS: - PathKit (0.8.0) - Stencil (0.9.0): - PathKit (~> 0.8.0) - - StencilSwiftKit (2.0.1): + - StencilSwiftKit (2.1.0): - Stencil (~> 0.9.0) DEPENDENCIES: @@ -15,13 +15,13 @@ EXTERNAL SOURCES: CHECKOUT OPTIONS: StencilSwiftKit: - :commit: fe07cd4c1f081565948d29963491748f2709d0e2 + :commit: fe1e940413b0aae34198f9465bbb34183c7aa0b2 :git: https://github.com/SwiftGen/StencilSwiftKit SPEC CHECKSUMS: PathKit: dcab05d701474011aae0e40cf892298a831f63d6 Stencil: 510f0b0518a366b67b6a9c5085a0399741b6d2f9 - StencilSwiftKit: b7f4de5ecd88c484713883d83968da8b6cc3ff97 + StencilSwiftKit: 76100a047f59c3358a3abe0cd5cc99db19a3dcc7 PODFILE CHECKSUM: 910aa7b4b6bcbe527b3b6800c8fe6bc374027140 diff --git a/Pods/Local Podspecs/StencilSwiftKit.podspec.json b/Pods/Local Podspecs/StencilSwiftKit.podspec.json index 0c350c4..7d87c62 100644 --- a/Pods/Local Podspecs/StencilSwiftKit.podspec.json +++ b/Pods/Local Podspecs/StencilSwiftKit.podspec.json @@ -1,6 +1,6 @@ { "name": "StencilSwiftKit", - "version": "2.0.1", + "version": "2.1.0", "summary": "Stencil additions dedicated for Swift code generation", "description": "This pod contains some additional nodes and filters for\n[Stencil](https://github.com/kylef/Stencil).\nThese additional nodes & filters are mainly dedicated\nfor writing Stencil templates generating *Swift* code.", "homepage": "https://github.com/SwiftGen/StencilSwiftKit", @@ -14,7 +14,7 @@ }, "source": { "git": "https://github.com/SwiftGen/StencilSwiftKit.git", - "tag": "2.0.1" + "tag": "2.1.0" }, "source_files": "Sources/**/*.swift", "dependencies": { diff --git a/Pods/Manifest.lock b/Pods/Manifest.lock index e2755b4..aab7219 100644 --- a/Pods/Manifest.lock +++ b/Pods/Manifest.lock @@ -2,7 +2,7 @@ PODS: - PathKit (0.8.0) - Stencil (0.9.0): - PathKit (~> 0.8.0) - - StencilSwiftKit (2.0.1): + - StencilSwiftKit (2.1.0): - Stencil (~> 0.9.0) DEPENDENCIES: @@ -15,13 +15,13 @@ EXTERNAL SOURCES: CHECKOUT OPTIONS: StencilSwiftKit: - :commit: fe07cd4c1f081565948d29963491748f2709d0e2 + :commit: fe1e940413b0aae34198f9465bbb34183c7aa0b2 :git: https://github.com/SwiftGen/StencilSwiftKit SPEC CHECKSUMS: PathKit: dcab05d701474011aae0e40cf892298a831f63d6 Stencil: 510f0b0518a366b67b6a9c5085a0399741b6d2f9 - StencilSwiftKit: b7f4de5ecd88c484713883d83968da8b6cc3ff97 + StencilSwiftKit: 76100a047f59c3358a3abe0cd5cc99db19a3dcc7 PODFILE CHECKSUM: 910aa7b4b6bcbe527b3b6800c8fe6bc374027140 diff --git a/Pods/Target Support Files/StencilSwiftKit/Info.plist b/Pods/Target Support Files/StencilSwiftKit/Info.plist index bdac57c..7f71fff 100644 --- a/Pods/Target Support Files/StencilSwiftKit/Info.plist +++ b/Pods/Target Support Files/StencilSwiftKit/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.0.1 + 2.1.0 CFBundleSignature ???? CFBundleVersion