From 6717de13c368ac428572c6555aa47852678847a9 Mon Sep 17 00:00:00 2001 From: David Jennes Date: Tue, 30 May 2017 15:43:07 +0200 Subject: [PATCH 1/2] adapt templates to use the new removenewlines filter --- Podfile.lock | 2 +- Pods/Manifest.lock | 2 +- Pods/StencilSwiftKit/README.md | 2 +- .../StencilSwiftKit/Sources/Environment.swift | 10 ++- .../Sources/Filters+Numbers.swift | 4 - .../Sources/Filters+Strings.swift | 85 +++++++++++++----- Pods/StencilSwiftKit/Sources/Filters.swift | 23 ++++- Pods/StencilSwiftKit/Sources/MapNode.swift | 34 +++---- .../Sources/SwiftIdentifier.swift | 89 ++++++------------- templates/storyboards/macOS-swift2.stencil | 9 +- templates/storyboards/macOS-swift3.stencil | 9 +- templates/storyboards/swift2.stencil | 9 +- templates/storyboards/swift3.stencil | 9 +- templates/strings/flat-swift2.stencil | 12 ++- templates/strings/flat-swift3.stencil | 12 ++- templates/strings/structured-swift2.stencil | 12 ++- templates/strings/structured-swift3.stencil | 12 ++- 17 files changed, 211 insertions(+), 124 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 7e8e51c..7cd6592 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -15,7 +15,7 @@ EXTERNAL SOURCES: CHECKOUT OPTIONS: StencilSwiftKit: - :commit: 21da18cdefe2deda281c134173f7558b37536250 + :commit: 4a73848c371c1c356f56462523c6f073d2389e4d :git: https://github.com/SwiftGen/StencilSwiftKit SPEC CHECKSUMS: diff --git a/Pods/Manifest.lock b/Pods/Manifest.lock index 7e8e51c..7cd6592 100644 --- a/Pods/Manifest.lock +++ b/Pods/Manifest.lock @@ -15,7 +15,7 @@ EXTERNAL SOURCES: CHECKOUT OPTIONS: StencilSwiftKit: - :commit: 21da18cdefe2deda281c134173f7558b37536250 + :commit: 4a73848c371c1c356f56462523c6f073d2389e4d :git: https://github.com/SwiftGen/StencilSwiftKit SPEC CHECKSUMS: diff --git a/Pods/StencilSwiftKit/README.md b/Pods/StencilSwiftKit/README.md index c7a27a6..0b784c6 100644 --- a/Pods/StencilSwiftKit/README.md +++ b/Pods/StencilSwiftKit/README.md @@ -27,7 +27,7 @@ * [String filters](Documentation/filters-strings.md): * `escapeReservedKeywords`: Escape keywods reserved in the Swift language, by wrapping them inside backticks so that the can be used as regular escape keywords in Swift code. * `lowerFirstWord` - * `snakeToCamelCase` / `snakeToCamelCaseNoPrefix` + * `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". * `camelToSnakeCase`: Transforms text from camelCase to snake_case. By default it converts to lower case, unless a single optional argument is set to "false", "no" or "0". * `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) * `titlecase` diff --git a/Pods/StencilSwiftKit/Sources/Environment.swift b/Pods/StencilSwiftKit/Sources/Environment.swift index 6727f2c..5348e00 100644 --- a/Pods/StencilSwiftKit/Sources/Environment.swift +++ b/Pods/StencilSwiftKit/Sources/Environment.swift @@ -12,16 +12,18 @@ public extension Extension { registerTag("macro", parser: MacroNode.parse) registerTag("call", parser: CallNode.parse) registerTag("map", parser: MapNode.parse) - registerFilter("swiftIdentifier", filter: Filters.Strings.stringToSwiftIdentifier) + + registerFilter("camelToSnakeCase", filter: Filters.Strings.camelToSnakeCase) + registerFilter("escapeReservedKeywords", filter: Filters.Strings.escapeReservedKeywords) registerFilter("lowerFirstWord", filter: Filters.Strings.lowerFirstWord) + registerFilter("removeNewlines", filter: Filters.Strings.removeNewlines) registerFilter("snakeToCamelCase", filter: Filters.Strings.snakeToCamelCase) - registerFilter("snakeToCamelCaseNoPrefix", filter: Filters.Strings.snakeToCamelCaseNoPrefix) - registerFilter("camelToSnakeCase", filter: Filters.Strings.camelToSnakeCase) + registerFilter("swiftIdentifier", filter: Filters.Strings.swiftIdentifier) registerFilter("titlecase", filter: Filters.Strings.titlecase) + registerFilter("hexToInt", filter: Filters.Numbers.hexToInt) registerFilter("int255toFloat", filter: Filters.Numbers.int255toFloat) registerFilter("percent", filter: Filters.Numbers.percent) - registerFilter("escapeReservedKeywords", filter: Filters.Strings.escapeReservedKeywords) } } diff --git a/Pods/StencilSwiftKit/Sources/Filters+Numbers.swift b/Pods/StencilSwiftKit/Sources/Filters+Numbers.swift index 23f365a..e866ee9 100644 --- a/Pods/StencilSwiftKit/Sources/Filters+Numbers.swift +++ b/Pods/StencilSwiftKit/Sources/Filters+Numbers.swift @@ -7,10 +7,6 @@ import Foundation import Stencil -// For retro-compatibility. Remove in next major. -@available(*, deprecated, renamed: "Filters.Numbers", message: "Use the Filters.Numbers nested type instead") -typealias NumFilters = Filters.Numbers - extension Filters { enum Numbers { static func hexToInt(_ value: Any?) throws -> Any? { diff --git a/Pods/StencilSwiftKit/Sources/Filters+Strings.swift b/Pods/StencilSwiftKit/Sources/Filters+Strings.swift index dafed84..4bbbb86 100644 --- a/Pods/StencilSwiftKit/Sources/Filters+Strings.swift +++ b/Pods/StencilSwiftKit/Sources/Filters+Strings.swift @@ -7,9 +7,9 @@ import Foundation import Stencil -// For retro-compatibility. Remove in next major. -@available(*, deprecated, renamed: "Filters.Strings", message: "Use the Filters.Strings nested type instead") -typealias StringFilters = Filters.Strings +enum RemoveNewlinesModes: String { + case all, leading +} extension Filters { enum Strings { @@ -32,9 +32,9 @@ extension Filters { "right", "set", "Type", "unowned", "weak", "willSet" ] - static func stringToSwiftIdentifier(value: Any?) throws -> Any? { + static func swiftIdentifier(_ value: Any?) throws -> Any? { guard let value = value as? String else { throw Filters.Error.invalidInputType } - return swiftIdentifier(from: value, replaceWithUnderscores: true) + return StencilSwiftKit.swiftIdentifier(from: value, replaceWithUnderscores: true) } /* - If the string starts with only one uppercase letter, lowercase that first letter @@ -66,30 +66,37 @@ extension Filters { return titlecase(string) } - static func snakeToCamelCase(_ value: Any?) throws -> Any? { - guard let string = value as? String else { throw Filters.Error.invalidInputType } - guard let noPrefix = try snakeToCamelCaseNoPrefix(value) else { - return nil - } - var prefixUnderscores = "" - for scalar in string.unicodeScalars { - guard scalar == "_" else { break } - prefixUnderscores += "_" - } - - return prefixUnderscores + ("\(noPrefix)") - } - - static func snakeToCamelCaseNoPrefix(_ value: Any?) throws -> Any? { + /// Converts snake_case to camelCase. Takes an optional Bool argument for removing any resulting + /// leading '_' characters, which defaults to false + /// + /// - Parameters: + /// - value: the value to be processed + /// - arguments: the arguments to the function; expecting zero or one boolean argument + /// - Returns: the camel case string + /// - Throws: FilterError.invalidInputType if the value parameter isn't a string + static func snakeToCamelCase(_ value: Any?, arguments: [Any?]) throws -> Any? { + 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: "_") - return comps.map { titlecase($0) }.joined(separator: "") + unprefixed = comps.map { titlecase($0) }.joined(separator: "") } else { let comps = try snakecase(string).components(separatedBy: "_") - return comps.map { $0.capitalized }.joined(separator: "") + 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 } /// Converts camelCase to snake_case. Takes an optional Bool argument for making the string lower case, @@ -101,7 +108,7 @@ extension Filters { /// - Returns: the snake case string /// - Throws: FilterError.invalidInputType if the value parameter isn't a string static func camelToSnakeCase(_ value: Any?, arguments: [Any?]) throws -> Any? { - let toLower = try Filters.parseBool(from: arguments, index: 0, required: false) ?? true + let toLower = try Filters.parseBool(from: arguments, required: false) ?? true guard let string = value as? String else { throw Filters.Error.invalidInputType } let snakeCase = try snakecase(string) @@ -116,8 +123,40 @@ extension Filters { return escapeReservedKeywords(in: string) } + /// Removes newlines and other whitespace from a string. Takes an optional Mode argument: + /// - all (default): remove all newlines and whitespaces + /// - leading: remove newlines and only leading whitespaces + /// + /// - Parameters: + /// - value: the value to be processed + /// - arguments: the arguments to the function; expecting zero or one mode argument + /// - Returns: the trimmed string + /// - Throws: FilterError.invalidInputType if the value parameter isn't a string + static func removeNewlines(_ value: Any?, arguments: [Any?]) throws -> Any? { + guard let string = value as? String else { throw Filters.Error.invalidInputType } + let mode = try Filters.parseEnum(from: arguments, default: RemoveNewlinesModes.all) + + switch mode { + case .all: + return string + .components(separatedBy: .whitespacesAndNewlines) + .joined() + case .leading: + return string + .components(separatedBy: .newlines) + .map(removeLeadingWhitespaces(from:)) + .joined() + .trimmingCharacters(in: .whitespaces) + } + } + // MARK: - Private methods + private static func removeLeadingWhitespaces(from string: String) -> String { + let chars = string.unicodeScalars.drop { CharacterSet.whitespaces.contains($0) } + return String(chars) + } + /// 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/Filters.swift b/Pods/StencilSwiftKit/Sources/Filters.swift index 70f2924..1c74616 100644 --- a/Pods/StencilSwiftKit/Sources/Filters.swift +++ b/Pods/StencilSwiftKit/Sources/Filters.swift @@ -10,6 +10,7 @@ import Stencil enum Filters { enum Error: Swift.Error { case invalidInputType + case invalidOption(option: String) } /// Parses filter arguments for a boolean value, where true can by any one of: "true", "yes", "1", and @@ -22,7 +23,7 @@ enum Filters { /// - required: If true, the argument is required and function throws if missing. /// If false, returns nil on missing args. /// - Throws: Filters.Error.invalidInputType - static func parseBool(from arguments: [Any?], index: Int, required: Bool = true) throws -> Bool? { + static func parseBool(from arguments: [Any?], at index: Int = 0, required: Bool = true) throws -> Bool? { guard index < arguments.count, let boolArg = arguments[index] as? String else { if required { throw Error.invalidInputType @@ -40,4 +41,24 @@ enum Filters { throw Error.invalidInputType } } + + /// Parses filter arguments for an enum value (with a String rawvalue). + /// + /// - Parameters: + /// - arguments: an array of argument values, may be empty + /// - index: the index in the arguments array + /// - default: The default value should no argument be provided + /// - Throws: Filters.Error.invalidInputType + static func parseEnum(from arguments: [Any?], at index: Int = 0, default: T) throws -> T + where T: RawRepresentable, T.RawValue == String { + + guard index < arguments.count else { return `default` } + let arg = arguments[index].map(String.init(describing:)) ?? `default`.rawValue + + guard let result = T(rawValue: arg) else { + throw Filters.Error.invalidOption(option: arg) + } + + return result + } } diff --git a/Pods/StencilSwiftKit/Sources/MapNode.swift b/Pods/StencilSwiftKit/Sources/MapNode.swift index 88c9658..41bcba0 100644 --- a/Pods/StencilSwiftKit/Sources/MapNode.swift +++ b/Pods/StencilSwiftKit/Sources/MapNode.swift @@ -55,7 +55,7 @@ class MapNode: NodeType { if let values = values as? [Any], values.count > 0 { let mappedValues: [String] = try values.enumerated().map { (index, item) in - let mapContext = self.context(values: values, index: index, item: item) + let mapContext = self.context(values: values, index: index, item: item) return try context.push(dictionary: mapContext) { try renderNodes(nodes, context) @@ -68,20 +68,20 @@ class MapNode: NodeType { return "" } - func context(values: [Any], index: Int, item: Any) -> [String: Any] { - var result: [String: Any] = [ - "maploop": [ - "counter": index, - "first": index == 0, - "last": index == (values.count - 1), - "item": item - ] - ] - - if let mapVariable = mapVariable { - result[mapVariable] = item - } - - return result - } + func context(values: [Any], index: Int, item: Any) -> [String: Any] { + var result: [String: Any] = [ + "maploop": [ + "counter": index, + "first": index == 0, + "last": index == (values.count - 1), + "item": item + ] + ] + + if let mapVariable = mapVariable { + result[mapVariable] = item + } + + return result + } } diff --git a/Pods/StencilSwiftKit/Sources/SwiftIdentifier.swift b/Pods/StencilSwiftKit/Sources/SwiftIdentifier.swift index 945e84d..654b98f 100644 --- a/Pods/StencilSwiftKit/Sources/SwiftIdentifier.swift +++ b/Pods/StencilSwiftKit/Sources/SwiftIdentifier.swift @@ -6,82 +6,51 @@ import Foundation +private func mr(_ char: Int) -> CountableClosedRange { + return char...char +} + // Official list of valid identifier characters // swiftlint:disable:next line_length // from: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html#//apple_ref/doc/uid/TP40014097-CH30-ID410 -// swiftlint:disable function_body_length +private let headRanges: [CountableClosedRange] = [ + 0x61...0x7a, 0x41...0x5a, mr(0x5f), mr(0xa8), mr(0xaa), mr(0xad), mr(0xaf), + 0xb2...0xb5, 0xb7...0xba, 0xbc...0xbe, 0xc0...0xd6, 0xd8...0xf6, 0xf8...0xff, + 0x100...0x2ff, 0x370...0x167f, 0x1681...0x180d, 0x180f...0x1dbf, + 0x1e00...0x1fff, 0x200b...0x200d, 0x202a...0x202e, mr(0x203F), mr(0x2040), + mr(0x2054), 0x2060...0x206f, 0x2070...0x20cf, 0x2100...0x218f, 0x2460...0x24ff, + 0x2776...0x2793, 0x2c00...0x2dff, 0x2e80...0x2fff, 0x3004...0x3007, + 0x3021...0x302f, 0x3031...0x303f, 0x3040...0xd7ff, 0xf900...0xfd3d, + 0xfd40...0xfdcf, 0xfdf0...0xfe1f, 0xfe30...0xfe44, 0xfe47...0xfffd, + 0x10000...0x1fffd, 0x20000...0x2fffd, 0x30000...0x3fffd, 0x40000...0x4fffd, + 0x50000...0x5fffd, 0x60000...0x6fffd, 0x70000...0x7fffd, 0x80000...0x8fffd, + 0x90000...0x9fffd, 0xa0000...0xafffd, 0xb0000...0xbfffd, 0xc0000...0xcfffd, + 0xd0000...0xdfffd, 0xe0000...0xefffd +] + +private let tailRanges: [CountableClosedRange] = [ + 0x30...0x39, 0x300...0x36F, 0x1dc0...0x1dff, 0x20d0...0x20ff, 0xfe20...0xfe2f +] + private func identifierCharacterSets() -> (head: NSMutableCharacterSet, tail: NSMutableCharacterSet) { let addRange: (NSMutableCharacterSet, CountableClosedRange) -> Void = { (mcs, range) in mcs.addCharacters(in: NSRange(location: range.lowerBound, length: range.count)) } - let addChars: (NSMutableCharacterSet, String) -> Void = { (mcs, string) in - mcs.addCharacters(in: string) - } let head = NSMutableCharacterSet() - - addRange(head, 0x41...0x5A) // A-Z - addRange(head, 0x61...0x7A) // a-z - addChars(head, "_") - addChars(head, "\u{00A8}\u{00AA}\u{00AD}\u{00AF}") - addRange(head, 0x00B2...0x00B5) - addRange(head, 0x00B7...0x00BA) - addRange(head, 0x00BC...0x00BE) - addRange(head, 0x00C0...0x00D6) - addRange(head, 0x00D8...0x00F6) - addRange(head, 0x00F8...0x00FF) - addRange(head, 0x0100...0x02FF) - addRange(head, 0x0370...0x167F) - addRange(head, 0x1681...0x180D) - addRange(head, 0x180F...0x1DBF) - addRange(head, 0x1E00...0x1FFF) - addRange(head, 0x200B...0x200D) - addRange(head, 0x202A...0x202E) - addRange(head, 0x203F...0x2040) - addChars(head, "\u{2054}") - addRange(head, 0x2060...0x206F) - addRange(head, 0x2070...0x20CF) - addRange(head, 0x2100...0x218F) - addRange(head, 0x2460...0x24FF) - addRange(head, 0x2776...0x2793) - addRange(head, 0x2C00...0x2DFF) - addRange(head, 0x2E80...0x2FFF) - addRange(head, 0x3004...0x3007) - addRange(head, 0x3021...0x302F) - addRange(head, 0x3031...0x303F) - addRange(head, 0x3040...0xD7FF) - addRange(head, 0xF900...0xFD3D) - addRange(head, 0xFD40...0xFDCF) - addRange(head, 0xFDF0...0xFE1F) - addRange(head, 0xFE30...0xFE44) - addRange(head, 0xFE47...0xFFFD) - addRange(head, 0x10000...0x1FFFD) - addRange(head, 0x20000...0x2FFFD) - addRange(head, 0x30000...0x3FFFD) - addRange(head, 0x40000...0x4FFFD) - addRange(head, 0x50000...0x5FFFD) - addRange(head, 0x60000...0x6FFFD) - addRange(head, 0x70000...0x7FFFD) - addRange(head, 0x80000...0x8FFFD) - addRange(head, 0x90000...0x9FFFD) - addRange(head, 0xA0000...0xAFFFD) - addRange(head, 0xB0000...0xBFFFD) - addRange(head, 0xC0000...0xCFFFD) - addRange(head, 0xD0000...0xDFFFD) - addRange(head, 0xE0000...0xEFFFD) + for range in headRanges { + addRange(head, range) + } guard let tail = head.mutableCopy() as? NSMutableCharacterSet else { fatalError("Internal error: mutableCopy() should have returned a valid NSMutableCharacterSet") } - addChars(tail, "0123456789") - addRange(tail, 0x0300...0x036F) - addRange(tail, 0x1DC0...0x1DFF) - addRange(tail, 0x20D0...0x20FF) - addRange(tail, 0xFE20...0xFE2F) + for range in tailRanges { + addRange(tail, range) + } return (head, tail) } -// swiftlint:enable function_body_length func swiftIdentifier(from string: String, forbiddenChars exceptions: String = "", diff --git a/templates/storyboards/macOS-swift2.stencil b/templates/storyboards/macOS-swift2.stencil index f957945..19745bb 100644 --- a/templates/storyboards/macOS-swift2.stencil +++ b/templates/storyboards/macOS-swift2.stencil @@ -2,7 +2,14 @@ {% if storyboards %} // swiftlint:disable sorted_imports -{% macro className scene %}{% if scene.customClass %}{% if scene.customModule %}{{scene.customModule}}.{% endif %}{{scene.customClass}}{% else %}NS{{scene.baseType}}{% endif %}{% endmacro %} +{% macro className scene %}{% filter removeNewlines %} + {% if scene.customClass %} + {% if scene.customModule %}{{scene.customModule}}.{% endif %} + {{scene.customClass}} + {% else %} + NS{{scene.baseType}} + {% endif %} +{% endfilter %}{% endmacro %} import Cocoa import Foundation {% for module in modules where module != env.PRODUCT_MODULE_NAME and module != param.module %} diff --git a/templates/storyboards/macOS-swift3.stencil b/templates/storyboards/macOS-swift3.stencil index 19d4fe3..9f1ccd6 100644 --- a/templates/storyboards/macOS-swift3.stencil +++ b/templates/storyboards/macOS-swift3.stencil @@ -2,7 +2,14 @@ {% if storyboards %} // swiftlint:disable sorted_imports -{% macro className scene %}{% if scene.customClass %}{% if scene.customModule %}{{scene.customModule}}.{% endif %}{{scene.customClass}}{% else %}NS{{scene.baseType}}{% endif %}{% endmacro %} +{% macro className scene %}{% filter removeNewlines %} + {% if scene.customClass %} + {% if scene.customModule %}{{scene.customModule}}.{% endif %} + {{scene.customClass}} + {% else %} + NS{{scene.baseType}} + {% endif %} +{% endfilter %}{% endmacro %} import Cocoa import Foundation {% for module in modules where module != env.PRODUCT_MODULE_NAME and module != param.module %} diff --git a/templates/storyboards/swift2.stencil b/templates/storyboards/swift2.stencil index 9dfa8b2..8c877e5 100644 --- a/templates/storyboards/swift2.stencil +++ b/templates/storyboards/swift2.stencil @@ -2,7 +2,14 @@ {% if storyboards %} // swiftlint:disable sorted_imports -{% macro className scene %}{% if scene.customClass %}{% if scene.customModule %}{{scene.customModule}}.{% endif %}{{scene.customClass}}{% else %}UI{{scene.baseType}}{% endif %}{% endmacro %} +{% macro className scene %}{% filter removeNewlines %} + {% if scene.customClass %} + {% if scene.customModule %}{{scene.customModule}}.{% endif %} + {{scene.customClass}} + {% else %} + UI{{scene.baseType}} + {% endif %} +{% endfilter %}{% endmacro %} import Foundation import UIKit {% for module in modules where module != env.PRODUCT_MODULE_NAME and module != param.module %} diff --git a/templates/storyboards/swift3.stencil b/templates/storyboards/swift3.stencil index 2e83dcc..9abb104 100644 --- a/templates/storyboards/swift3.stencil +++ b/templates/storyboards/swift3.stencil @@ -2,7 +2,14 @@ {% if storyboards %} // swiftlint:disable sorted_imports -{% macro className scene %}{% if scene.customClass %}{% if scene.customModule %}{{scene.customModule}}.{% endif %}{{scene.customClass}}{% else %}UI{{scene.baseType}}{% endif %}{% endmacro %} +{% macro className scene %}{% filter removeNewlines %} + {% if scene.customClass %} + {% if scene.customModule %}{{scene.customModule}}.{% endif %} + {{scene.customClass}} + {% else %} + UI{{scene.baseType}} + {% endif %} +{% endfilter %}{% endmacro %} import Foundation import UIKit {% for module in modules where module != env.PRODUCT_MODULE_NAME and module != param.module %} diff --git a/templates/strings/flat-swift2.stencil b/templates/strings/flat-swift2.stencil index 310571c..cfa66cf 100644 --- a/templates/strings/flat-swift2.stencil +++ b/templates/strings/flat-swift2.stencil @@ -4,8 +4,16 @@ import Foundation // swiftlint:disable file_length -{% macro parametersBlock types %}{% for type in types %}p{{forloop.counter}}: {{type}}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %} -{% macro argumentsBlock types %}{% for type in types %}p{{forloop.counter}}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %} +{% macro parametersBlock types %}{% filter removeNewlines:"leading" %} + {% for type in types %} + p{{forloop.counter}}: {{type}}{% if not forloop.last %}, {% endif %} + {% endfor %} +{% endfilter %}{% endmacro %} +{% macro argumentsBlock types %}{% filter removeNewlines:"leading" %} + {% for type in types %} + p{{forloop.counter}}{% if not forloop.last %}, {% endif %} + {% endfor %} +{% endfilter %}{% endmacro %} {% macro recursiveBlock table item sp %} {{sp}} {% for string in item.strings %} {{sp}} {% if not param.noComments %} diff --git a/templates/strings/flat-swift3.stencil b/templates/strings/flat-swift3.stencil index a9cb406..466e156 100644 --- a/templates/strings/flat-swift3.stencil +++ b/templates/strings/flat-swift3.stencil @@ -4,8 +4,16 @@ import Foundation // swiftlint:disable file_length -{% macro parametersBlock types %}{% for type in types %}_ p{{forloop.counter}}: {{type}}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %} -{% macro argumentsBlock types %}{% for type in types %}p{{forloop.counter}}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %} +{% macro parametersBlock types %}{% filter removeNewlines:"leading" %} + {% for type in types %} + _ p{{forloop.counter}}: {{type}}{% if not forloop.last %}, {% endif %} + {% endfor %} +{% endfilter %}{% endmacro %} +{% macro argumentsBlock types %}{% filter removeNewlines:"leading" %} + {% for type in types %} + p{{forloop.counter}}{% if not forloop.last %}, {% endif %} + {% endfor %} +{% endfilter %}{% endmacro %} {% macro recursiveBlock table item sp %} {{sp}} {% for string in item.strings %} {{sp}} {% if not param.noComments %} diff --git a/templates/strings/structured-swift2.stencil b/templates/strings/structured-swift2.stencil index 0fc37d9..80f8aca 100644 --- a/templates/strings/structured-swift2.stencil +++ b/templates/strings/structured-swift2.stencil @@ -4,8 +4,16 @@ import Foundation // swiftlint:disable file_length -{% macro parametersBlock types %}{% for type in types %}p{{forloop.counter}}: {{type}}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %} -{% macro argumentsBlock types %}{% for type in types %}p{{forloop.counter}}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %} +{% macro parametersBlock types %}{% filter removeNewlines:"leading" %} + {% for type in types %} + p{{forloop.counter}}: {{type}}{% if not forloop.last %}, {% endif %} + {% endfor %} +{% endfilter %}{% endmacro %} +{% macro argumentsBlock types %}{% filter removeNewlines:"leading" %} + {% for type in types %} + p{{forloop.counter}}{% if not forloop.last %}, {% endif %} + {% endfor %} +{% endfilter %}{% endmacro %} {% macro recursiveBlock table item sp %} {{sp}} {% for string in item.strings %} {{sp}} {% if not param.noComments %} diff --git a/templates/strings/structured-swift3.stencil b/templates/strings/structured-swift3.stencil index def9f25..ba40993 100644 --- a/templates/strings/structured-swift3.stencil +++ b/templates/strings/structured-swift3.stencil @@ -4,8 +4,16 @@ import Foundation // swiftlint:disable file_length -{% macro parametersBlock types %}{% for type in types %}_ p{{forloop.counter}}: {{type}}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %} -{% macro argumentsBlock types %}{% for type in types %}p{{forloop.counter}}{% if not forloop.last %}, {% endif %}{% endfor %}{% endmacro %} +{% macro parametersBlock types %}{% filter removeNewlines:"leading" %} + {% for type in types %} + _ p{{forloop.counter}}: {{type}}{% if not forloop.last %}, {% endif %} + {% endfor %} +{% endfilter %}{% endmacro %} +{% macro argumentsBlock types %}{% filter removeNewlines:"leading" %} + {% for type in types %} + p{{forloop.counter}}{% if not forloop.last %}, {% endif %} + {% endfor %} +{% endfilter %}{% endmacro %} {% macro recursiveBlock table item sp %} {{sp}} {% for string in item.strings %} {{sp}} {% if not param.noComments %} From e9bb42235f9de95b51654bdc2ba54c3fd4903f87 Mon Sep 17 00:00:00 2001 From: David Jennes Date: Tue, 30 May 2017 20:11:26 +0200 Subject: [PATCH 2/2] update font templates to use `snakeToCamelCase` with parameter instead of the old version --- templates/fonts/swift2.stencil | 4 ++-- templates/fonts/swift3.stencil | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/fonts/swift2.stencil b/templates/fonts/swift2.stencil index b25446c..a2d4fbc 100644 --- a/templates/fonts/swift2.stencil +++ b/templates/fonts/swift2.stencil @@ -54,9 +54,9 @@ extension Font { // swiftlint:disable identifier_name line_length type_body_length enum {{param.enumName|default:"FontFamily"}} { {% for family in families %} - enum {{family.name|swiftIdentifier|snakeToCamelCaseNoPrefix|escapeReservedKeywords}}: String, FontConvertible { + enum {{family.name|swiftIdentifier|snakeToCamelCase:"true"|escapeReservedKeywords}}: String, FontConvertible { {% for font in family.fonts %} - case {{font.style|swiftIdentifier|snakeToCamelCaseNoPrefix|escapeReservedKeywords}} = "{{font.name}}" + case {{font.style|swiftIdentifier|snakeToCamelCase:"true"|escapeReservedKeywords}} = "{{font.name}}" {% endfor %} } {% endfor %} diff --git a/templates/fonts/swift3.stencil b/templates/fonts/swift3.stencil index 552999e..6c96ae5 100644 --- a/templates/fonts/swift3.stencil +++ b/templates/fonts/swift3.stencil @@ -54,9 +54,9 @@ extension Font { // swiftlint:disable identifier_name line_length type_body_length enum {{param.enumName|default:"FontFamily"}} { {% for family in families %} - enum {{family.name|swiftIdentifier|snakeToCamelCaseNoPrefix|escapeReservedKeywords}}: String, FontConvertible { + enum {{family.name|swiftIdentifier|snakeToCamelCase:"true"|escapeReservedKeywords}}: String, FontConvertible { {% for font in family.fonts %} - case {{font.style|swiftIdentifier|snakeToCamelCaseNoPrefix|lowerFirstWord|escapeReservedKeywords}} = "{{font.name}}" + case {{font.style|swiftIdentifier|snakeToCamelCase:"true"|lowerFirstWord|escapeReservedKeywords}} = "{{font.name}}" {% endfor %} } {% endfor %}