Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Deprecated variables #13

Merged
merged 13 commits into from
Apr 12, 2017
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ _None_

### New Features

_None_
* More variables have been deprecated, while new variables have been added.
[David Jennes](https://github.com/djbe)
[#13](https://github.com/SwiftGen/SwiftGenKit/issues/13)
* The `strings`, `structuredStrings` and `tableName` have been replaced by `tables`, which is an array of string tables, each with a `name` and a `strings` property.
* For each string, the `params` variable and it's subvariables (such as `names`, `count`, ...) have been replaced by `types`, which is an array of types.
* `enumName`, `sceneEnumName` and `segueEnumName` have been replaced by `param.enumName`, `param.sceneEnumName` and `param.segueEnumName` respectively. Templates should provide a default value for these in case the variables are empty.

### Internal Changes

Expand All @@ -34,7 +39,7 @@ _None_

* Asset catalog parser: ignore unsupported types (such as appiconset).
[David Jennes](https://github.com/djbe)
[#7](https://github.com/SwiftGen/StencilSwiftKit/issues/7)
[#7](https://github.com/SwiftGen/SwiftGenKit/issues/7)

### New Features

Expand Down
16 changes: 12 additions & 4 deletions Sources/Stencil/AssetsCatalogContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@
import Foundation

/*
- `enumName`: `String` — name of the enum to generate
- `images`: `Array<String>` — list of image names
- `catalogs`: `Array` — list of asset catalogs
- `name` : `String` — the name of the catalog
- `assets`: `Array` — tree structure of items, each item is either a:
- group: this represents a folder
- `name` : `String` — name of the folder
- `items`: `Array` — list of items, can be either groups or images
- image: this represents an image asset
- `name` : `String` — name of the image
- `value`: `String` — the actual name for loading the image
*/
extension AssetsCatalogParser {
public func stencilContext(enumName: String = "Asset") -> [String: Any] {
Expand All @@ -21,11 +28,12 @@ extension AssetsCatalogParser {
}

return [
"enumName": enumName,
"catalogs": structured,

// NOTE: This is a deprecated variable
"images": images
"enumName": enumName,
"images": images,
"param": ["enumName": enumName]
]
}

Expand Down
20 changes: 13 additions & 7 deletions Sources/Stencil/ColorsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
import Foundation

/*
- `enumName`: `String` — name of the enum to generate
- `colors`: `Array` of:
- `name` : `String` — name of each color
- `rgb` : `String` — hex value of the form RRGGBB (like "ff6600")
- `rgba` : `String` — hex value of the form RRGGBBAA (like "ff6600cc")
- `red` : `String` — hex value of the red component
- `green`: `String` — hex value of the green component
- `blue` : `String` — hex value of the blue component
Expand All @@ -27,14 +24,23 @@ extension ColorsFileParser {

return [
"name": name,
"rgba": String(hexChars[0..<8]),
"rgb": String(hexChars[0..<6]),
"red": comps[0],
"green": comps[1],
"blue": comps[2],
"alpha": comps[3]
"alpha": comps[3],

// NOTE: This is a deprecated variable
"rgba": String(hexChars[0..<8]),
"rgb": String(hexChars[0..<6])
]
}).sorted { $0["name"] ?? "" < $1["name"] ?? "" }
return ["enumName": enumName, "colors": colorMap]

return [
"colors": colorMap,

// NOTE: This is a deprecated variable
"enumName": enumName,
"param": ["enumName": enumName]
]
}
}
19 changes: 12 additions & 7 deletions Sources/Stencil/FontsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
import Foundation

/*
- `enumName`: `String`
- `families`: `Array`
- `name`: `String`
- `fonts`: `Array`
- `style`: `String`
- `name`: `String`
- `families`: `Array` — list of font families
- `name` : `String` — name of family
- `fonts`: `Array` — list of fonts in family
- `style`: `String` — font style
- `name` : `String` — font postscript name
*/

extension FontsFileParser {
Expand All @@ -33,6 +32,12 @@ extension FontsFileParser {
]
}.sorted { $0["name"] as? String ?? "" < $1["name"] as? String ?? "" }

return ["enumName": enumName, "families": families]
return [
"families": families,

// NOTE: This is a deprecated variable
"enumName": enumName,
"param": ["enumName": enumName]
]
}
}
120 changes: 70 additions & 50 deletions Sources/Stencil/StoryboardsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,25 @@ private func uppercaseFirst(_ string: String) -> String {
}

/*
- `sceneEnumName`: `String`
- `segueEnumName`: `String`
- `modules`: `Array` of `String`
- `storyboards`: `Array` of:
- `name`: `String`
- `modules` : `Array<String>` — List of modules used by scenes and segues
- `storyboards`: `Array` — List of storyboards
- `name`: `String` — Name of the storyboard
- `initialScene`: `Dictionary` (absent if not specified)
- `customClass`: `String` (absent if generic UIViewController/NSViewController)
- `isBaseViewController`: `Bool`, indicate if the baseType is 'viewController' or anything else
- `customClass` : `String` (absent if generic UIViewController/NSViewController)
- `customModule`: `String` (absent if no custom class)
- `baseType`: `String` (absent if class is a custom class).
The base class type on which the initial scene is base.
Possible values include 'ViewController', 'NavigationController', 'TableViewController'…
- `scenes`: `Array` (absent if empty)
- `identifier`: `String`
- `identifier` : `String`
- `customClass`: `String` (absent if generic UIViewController/NSViewController)
- `isBaseViewController`: `Bool`, indicate if the baseType is 'ViewController' or anything else
- `baseType`: `String` (absent if class is a custom class). The base class type on which a scene is base.
- `customModule`: `String` (absent if no custom class)
- `baseType`: `String` (absent if class is a custom class).
The base class type on which a scene is base.
Possible values include 'ViewController', 'NavigationController', 'TableViewController'…
- `segues`: `Array` (absent if empty)
- `identifier`: `String`
- `class`: `String` (absent if generic UIStoryboardSegue)
- `customClass`: `String` (absent if generic UIStoryboardSegue)
*/
extension StoryboardParser {
public func stencilContext(sceneEnumName: String = "StoryboardScene",
Expand All @@ -43,60 +42,81 @@ extension StoryboardParser {
var sbMap: [String:Any] = ["name": storyboardName]
// Initial Scene
if let initialScene = initialScenes[storyboardName] {
let initial: [String:Any]
if let customClass = initialScene.customClass {
initial = ["customClass": customClass, "customModule": initialScene.customModule ?? ""]
} else {
initial = [
"baseType": uppercaseFirst(initialScene.tag),

// NOTE: This is a deprecated variable
"isBaseViewController": initialScene.tag == "viewController"
]
}
sbMap["initialScene"] = initial
sbMap["initialScene"] = map(initialScene: initialScene)
}
// All Scenes
if let scenes = storyboardsScenes[storyboardName] {
sbMap["scenes"] = scenes
.sorted(by: {$0.storyboardID < $1.storyboardID})
.map { (scene: Scene) -> [String:Any] in
if let customClass = scene.customClass {
return [
"identifier": scene.storyboardID,
"customClass": customClass,
"customModule": scene.customModule ?? ""
]
} else if scene.tag == "viewController" {
return [
"identifier": scene.storyboardID,
"baseType": uppercaseFirst(scene.tag),

// NOTE: This is a deprecated variable
"isBaseViewController": scene.tag == "viewController"
]
}
return ["identifier": scene.storyboardID, "baseType": uppercaseFirst(scene.tag)]
}
.map(map(scene:))
}
// All Segues
if let segues = storyboardsSegues[storyboardName] {
sbMap["segues"] = segues
.sorted(by: {$0.identifier < $1.identifier})
.map { (segue: Segue) -> [String:String] in
["identifier": segue.identifier, "customClass": segue.customClass ?? ""]
}
sbMap["segues"] = segues
.sorted(by: {$0.identifier < $1.identifier})
.map(map(segue:))
}
return sbMap
}
return [
"sceneEnumName": sceneEnumName,
"segueEnumName": segueEnumName,
"storyboards": storyboardsMap,
"modules": modules.sorted(),
"storyboards": storyboardsMap,

// NOTE: This is a deprecated variable
"extraImports": modules.sorted()
"extraImports": modules.sorted(),
"param": [
"sceneEnumName": sceneEnumName,
"segueEnumName": segueEnumName
],
"sceneEnumName": sceneEnumName,
"segueEnumName": segueEnumName
]
}

private func map(initialScene scene: InitialScene) -> [String: Any] {
if let customClass = scene.customClass {
return [
"customClass": customClass,
"customModule": scene.customModule ?? ""
]
} else {
return [
"baseType": uppercaseFirst(scene.tag),

// NOTE: This is a deprecated variable
"isBaseViewController": scene.tag == "viewController"
]
}
}

private func map(scene: Scene) -> [String: Any] {
if let customClass = scene.customClass {
return [
"identifier": scene.storyboardID,
"customClass": customClass,
"customModule": scene.customModule ?? ""
]
} else if scene.tag == "viewController" {
return [
"identifier": scene.storyboardID,
"baseType": uppercaseFirst(scene.tag),

// NOTE: This is a deprecated variable
"isBaseViewController": scene.tag == "viewController"
]
} else {
return [
"identifier": scene.storyboardID,
"baseType": uppercaseFirst(scene.tag)
]
}
}

private func map(segue: Segue) -> [String: Any] {
return [
"identifier": segue.identifier,
"customClass": segue.customClass ?? "",
"customModule": segue.customModule ?? ""
]
}
}
71 changes: 38 additions & 33 deletions Sources/Stencil/StringsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@ private extension String {
}

/*
- `enumName`: `String`
- `tableName`: `String` - name of the `.strings` file (usually `"Localizable"`)
- `strings`: `Array`
- `key`: `String`
- `translation`: `String`
- `params`: `Dictionary` — defined only if localized string has parameters; contains the following entries:
- `count`: `Int` — number of parameters
- `types`: `Array<String>` containing types like `"String"`, `"Int"`, etc
- `declarations`: `Array<String>` containing declarations like `"let p0"`, `"let p1"`, etc
- `names`: `Array<String>` containing parameter names like `"p0"`, `"p1"`, etc
- `typednames`: Array<String>` containing typed declarations like `"let p0: String`", `"let p1: Int"`, etc
- `keytail`: `String` containing the rest of the key after the next first `.`
(useful to do recursion when splitting keys against `.` for structured templates)
- `structuredStrings`: `Dictionary` - contains strings structured by keys separated by '.' syntax
- `tables`: `Array` — List of string tables
- `name` : `String` — name of the `.strings` file (usually `"Localizable"`)
- `strings`: `Array` — Tree structure of strings (based on dot syntax), each level has:
- `name` : `String` — name of the level
- `strings`: `Array` — list of strings at this level:
- `key`: `String` — the full translation key
- `translation`: `String` — the translated text
- `types`: `Array<String>` — defined only if localized string has parameters.
Containing types like `"String"`, `"Int"`, etc
- `keytail`: `String` containing the rest of the key after the next first `.`
(useful to do recursion when splitting keys against `.` for structured templates)
- `subenums`: `Array` — list of sub-levels, repeating the structure mentioned above
*/
extension StringsFileParser {
public func stencilContext(enumName: String = "L10n", tableName: String = "Localizable") -> [String: Any] {
Expand All @@ -38,42 +36,49 @@ extension StringsFileParser {
Array(0..<keyPath.count).forEach { _ in keyStructure.removeFirst() }
let keytail = keyStructure.joined(separator: ".")

var result: [String: Any] = [
"key": entry.key.newlineEscaped,
"translation": entry.translation.newlineEscaped,
"keytail": keytail
]

if entry.types.count > 0 {
let params: [String: Any] = [
"types": entry.types.map { $0.rawValue },
result["types"] = entry.types.map { $0.rawValue }

// NOTE: These are deprecated variables
// NOTE: params is deprecated
result["params"] = [
"types": entry.types.map { $0.rawValue },
"count": entry.types.count,
"declarations": entry.types.indices.map { "let p\($0)" },
"names": entry.types.indices.map { "p\($0)" },
"typednames": entry.types.enumerated().map { "p\($0): \($1.rawValue)" }
]
return ["key": entry.key.newlineEscaped,
"translation": entry.translation.newlineEscaped,
"params": params,
"keytail": keytail
]
} else {
return ["key": entry.key.newlineEscaped,
"translation": entry.translation.newlineEscaped,
"keytail": keytail
]
}

return result
}

let strings = entries
.sorted { $0.key.caseInsensitiveCompare($1.key) == .orderedAscending }
.map { entryToStringMapper($0, []) }
.sorted { $0.key.caseInsensitiveCompare($1.key) == .orderedAscending }
.map { entryToStringMapper($0, []) }
let structuredStrings = structure(
entries: entries,
usingMapper: entryToStringMapper
entries: entries,
usingMapper: entryToStringMapper
)
let tables: [[String: Any]] = [[
"name": tableName,
"strings": structuredStrings
]]

return [
"tables": tables,

// NOTE: These are deprecated variables
"enumName": enumName,
"tableName": tableName,
"param": ["enumName": enumName],
"strings": strings,
"structuredStrings": structuredStrings
"structuredStrings": structuredStrings,
"tableName": tableName
]
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Resources
Submodule Resources updated 198 files
Loading