Skip to content
This repository was archived by the owner on Sep 6, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

## Master

Due to the removal of legacy code, there are a few breaking changes in this new version that affect both template writers as well as developers. We've provided a migration guide to help you through these changes, which you can find here:
[Migration Guide for 2.0](https://github.com/SwiftGen/SwiftGenKit/blob/master/Documentation/MigrationGuide.md#swiftgenkit-20-swiftgen-50)

### Bug Fixes

* Fixed color's hex value rounding error.
Expand All @@ -18,6 +21,7 @@
* Removed deprecated variables. See [SwiftGenKit#5](https://github.com/SwiftGen/SwiftGenKit/issues/5) for more information.
[David Jennes](https://github.com/djbe)
[#35](https://github.com/SwiftGen/templates/issues/35)
[#42](https://github.com/SwiftGen/templates/issues/42)

### New Features

Expand Down
45 changes: 45 additions & 0 deletions Documentation/MigrationGuide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## SwiftGenKit 2.0 (SwiftGen 5.0)

### For template writers:

#### Colors

- `enumName`: has been replaced by `param.enumName`, should provide default value.
- For each `color`:
- `rgb` and `rgba`: can be composed from the other components.

#### Fonts

- `enumName`: has been replaced by `param.enumName`, should provide default value.
- For each `font`:
- `fontName`: has been replaced by the `name` property.

#### Images

- `enumName`: has been replaced by `param.enumName`, should provide default value.
- `images`: just old, `catalogs` contains the structured information.

#### Storyboards

- `extraImports`: replaced by `modules` (https://github.com/AliSoftware/SwiftGen/pull/243)
- `sceneEnumName`: has been replaced by `param.sceneEnumName`, should provide default value.
- `segueEnumName`: has been replaced by `param.segueEnumName`, should provide default value.
- For each `scene`:
- `isBaseViewController`: removed. You can replace it with a test for `baseType == "ViewController"`.

#### Strings

- `enumName`: has been replaced by `param.enumName`, should provide default value.
- `strings` and `structuredStrings`: replaced by `tables` array, where each table has a structured `levels` property.
- `tableName`: replaced by `tables` array, where each table has a `name` property.
- for each `level`:
- `subenums`: renamed to `children`.
- for each `string`:
- `keytail`: renamed to `name`.
- `params` structure with the `names`, `typednames`, `types`, `count` and `declarations` arrays: removed.
- These have been replaced by `types` which is an array of types. The previous variables
can now be reconstructed using template tags now that Stencil has become more powerful.

### For developers using SwiftGenKit as a dependency:

Previously the parser context generation method (`stencilContext()`) accepted parameters such as `enumName`, this has been removed in favor of the `--param` system. Templates will automatically receive a `param` object with parameters from the CLI invocation, and should provide default values in case no value was present in the invocation.
2 changes: 1 addition & 1 deletion Sources/Stencil/AssetsCatalogContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
- `value`: `String` — the actual full name for loading the image
*/
extension AssetsCatalogParser {
public func stencilContext(enumName: String = "Asset") -> [String: Any] {
public func stencilContext() -> [String: Any] {
let catalogs = self.catalogs.keys.sorted(by: <).map { name -> [String: Any] in
return [
"name": name,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Stencil/ColorsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Foundation
- `alpha`: `String` — hex value of the alpha component
*/
extension ColorsFileParser {
public func stencilContext(enumName: String = "ColorName") -> [String: Any] {
public func stencilContext() -> [String: Any] {
let colorMap = colors.map({ (color: (name: String, value: UInt32)) -> [String:String] in
let name = color.name.trimmingCharacters(in: CharacterSet.whitespaces)
let hex = "00000000" + String(color.value, radix: 16)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Stencil/FontsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Foundation
*/

extension FontsFileParser {
public func stencilContext(enumName: String = "FontFamily") -> [String: Any] {
public func stencilContext() -> [String: Any] {
// turn into array of dictionaries
let families = entries.map { (name: String, family: Set<Font>) -> [String: Any] in
let fonts = family.map { (font: Font) -> [String: String] in
Expand Down
3 changes: 1 addition & 2 deletions Sources/Stencil/StoryboardsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ private func uppercaseFirst(_ string: String) -> String {
- `customModule`: `String` — The custom module of the segue (absent if no custom segue class)
*/
extension StoryboardParser {
public func stencilContext(sceneEnumName: String = "StoryboardScene",
segueEnumName: String = "StoryboardSegue") -> [String: Any] {
public func stencilContext() -> [String: Any] {
let storyboards = Set(storyboardsScenes.keys).union(storyboardsSegues.keys).sorted(by: <)
let storyboardsMap = storyboards.map { (storyboardName: String) -> [String:Any] in
var sbMap: [String:Any] = ["name": storyboardName]
Expand Down
4 changes: 2 additions & 2 deletions Sources/Stencil/StringsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private extension String {
Contains a list of types like `"String"`, `"Int"`, etc
*/
extension StringsFileParser {
public func stencilContext(enumName: String = "L10n", tableName: String = "Localizable") -> [String: Any] {
public func stencilContext() -> [String: Any] {

let entryToStringMapper = { (entry: Entry, keyPath: [String]) -> [String: Any] in
let levelName = entry.keyStructure.last ?? ""
Expand All @@ -52,7 +52,7 @@ extension StringsFileParser {
usingMapper: entryToStringMapper
)
let tables: [[String: Any]] = [[
"name": tableName,
"name": "Localizable",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That present #42 will have to be merged before #41 I guess, to avoid this hard-coded value here to override the self.tables.map { … } in #41 right?

"levels": structuredStrings
]]

Expand Down
2 changes: 1 addition & 1 deletion Tests/Resources
Submodule Resources updated 27 files
+4 −0 CHANGELOG.md
+0 −57 Contexts/Colors/customname.plist
+0 −93 Contexts/Colors/text-customname.plist
+0 −212 Contexts/Fonts/customname.plist
+0 −92 Contexts/Images/customname.plist
+6 −0 Contexts/Images/defaults.plist
+0 −215 Contexts/Storyboards-iOS/customname.plist
+0 −171 Contexts/Storyboards-macOS/customname.plist
+0 −245 Contexts/Strings/defaults.plist
+0 −40 Contexts/Strings/entries.plist
+0 −0 Contexts/Strings/localizable.plist
+6 −0 Fixtures/Images/Images.xcassets/Empty/Contents.json
+0 −0 Tests/Expected/Strings/flat-swift2-context-localizable-customname.swift
+0 −0 Tests/Expected/Strings/flat-swift2-context-localizable-no-comments.swift
+0 −0 Tests/Expected/Strings/flat-swift2-context-localizable.swift
+0 −0 Tests/Expected/Strings/flat-swift3-context-localizable-customname.swift
+0 −0 Tests/Expected/Strings/flat-swift3-context-localizable-no-comments.swift
+0 −0 Tests/Expected/Strings/flat-swift3-context-localizable.swift
+0 −0 Tests/Expected/Strings/structured-swift2-context-localizable-customname.swift
+0 −0 Tests/Expected/Strings/structured-swift2-context-localizable-no-comments.swift
+0 −0 Tests/Expected/Strings/structured-swift2-context-localizable.swift
+0 −0 Tests/Expected/Strings/structured-swift3-context-localizable-customname.swift
+0 −0 Tests/Expected/Strings/structured-swift3-context-localizable-no-comments.swift
+0 −0 Tests/Expected/Strings/structured-swift3-context-localizable.swift
+2 −2 Tests/TemplatesTests/StringsTests.swift
+4 −4 templates/images/swift2.stencil
+4 −4 templates/images/swift3.stencil
9 changes: 0 additions & 9 deletions Tests/SwiftGenKitTests/ColorsCLRFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ class ColorsCLRFileTests: XCTestCase {
let result = parser.stencilContext()
XCTDiffContexts(result, expected: "defaults.plist", sub: .colors)
}

func testFileWithCustomName() throws {
let parser = ColorsCLRFileParser()
try parser.parseFile(at: Fixtures.path(for: "colors.clr", sub: .colors))

let result = parser.stencilContext(enumName: "XCTColors")
XCTDiffContexts(result, expected: "customname.plist", sub: .colors)
}

func testFileWithBadFile() {
let parser = ColorsCLRFileParser()
do {
Expand Down
8 changes: 0 additions & 8 deletions Tests/SwiftGenKitTests/ColorsJSONFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ class ColorsJSONFileTests: XCTestCase {
XCTDiffContexts(result, expected: "defaults.plist", sub: .colors)
}

func testFileWithCustomName() throws {
let parser = ColorsJSONFileParser()
try parser.parseFile(at: Fixtures.path(for: "colors.json", sub: .colors))

let result = parser.stencilContext(enumName: "XCTColors")
XCTDiffContexts(result, expected: "customname.plist", sub: .colors)
}

func testFileWithBadSyntax() {
let parser = ColorsJSONFileParser()
do {
Expand Down
8 changes: 0 additions & 8 deletions Tests/SwiftGenKitTests/ColorsTextFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ class ColorsTextFileTests: XCTestCase {
XCTDiffContexts(result, expected: "text-defaults.plist", sub: .colors)
}

func testFileWithCustomName() throws {
let parser = ColorsTextFileParser()
try parser.parseFile(at: Fixtures.path(for: "colors.txt", sub: .colors))

let result = parser.stencilContext(enumName: "XCTColors")
XCTDiffContexts(result, expected: "text-customname.plist", sub: .colors)
}

func testFileWithBadSyntax() {
let parser = ColorsTextFileParser()
do {
Expand Down
8 changes: 0 additions & 8 deletions Tests/SwiftGenKitTests/ColorsXMLFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ class ColorsXMLFileTests: XCTestCase {
XCTDiffContexts(result, expected: "defaults.plist", sub: .colors)
}

func testFileWithCustomName() throws {
let parser = ColorsXMLFileParser()
try parser.parseFile(at: Fixtures.path(for: "colors.xml", sub: .colors))

let result = parser.stencilContext(enumName: "XCTColors")
XCTDiffContexts(result, expected: "customname.plist", sub: .colors)
}

func testFileWithBadSyntax() {
let parser = ColorsXMLFileParser()
do {
Expand Down
8 changes: 0 additions & 8 deletions Tests/SwiftGenKitTests/FontsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,4 @@ class FontsTests: XCTestCase {
let result = parser.stencilContext()
XCTDiffContexts(result, expected: "defaults.plist", sub: .fonts)
}

func testCustomName() {
let parser = FontsFileParser()
parser.parseFile(at: Fixtures.directory(sub: .fonts))

let result = parser.stencilContext(enumName: "CustomFamily")
XCTDiffContexts(result, expected: "customname.plist", sub: .fonts)
}
}
10 changes: 1 addition & 9 deletions Tests/SwiftGenKitTests/ImagesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,11 @@ class ImagesTests: XCTestCase {
XCTDiffContexts(result, expected: "empty.plist", sub: .images)
}

func testFileWithDefaults() {
func testDefaults() {
let parser = AssetsCatalogParser()
parser.parseCatalog(at: Fixtures.path(for: "Images.xcassets", sub: .images))

let result = parser.stencilContext()
XCTDiffContexts(result, expected: "defaults.plist", sub: .images)
}

func testFileWithCustomName() {
let parser = AssetsCatalogParser()
parser.parseCatalog(at: Fixtures.path(for: "Images.xcassets", sub: .images))

let result = parser.stencilContext(enumName: "XCTImages")
XCTDiffContexts(result, expected: "customname.plist", sub: .images)
}
}
18 changes: 3 additions & 15 deletions Tests/SwiftGenKitTests/StoryboardsMacOSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class StoryboardsMacOSTests: XCTestCase {
XCTDiffContexts(result, expected: "empty.plist", sub: .storyboardsMacOS)
}

func testMessageStoryboardWithDefaults() {
func testMessageStoryboard() {
let parser = StoryboardParser()
do {
try parser.addStoryboard(at: Fixtures.path(for: "Message.storyboard", sub: .storyboardsMacOS))
Expand All @@ -33,7 +33,7 @@ class StoryboardsMacOSTests: XCTestCase {
XCTDiffContexts(result, expected: "messages.plist", sub: .storyboardsMacOS)
}

func testAnonymousStoryboardWithDefaults() {
func testAnonymousStoryboard() {
let parser = StoryboardParser()
do {
try parser.addStoryboard(at: Fixtures.path(for: "Anonymous.storyboard", sub: .storyboardsMacOS))
Expand All @@ -45,7 +45,7 @@ class StoryboardsMacOSTests: XCTestCase {
XCTDiffContexts(result, expected: "anonymous.plist", sub: .storyboardsMacOS)
}

func testAllStoryboardsWithDefaults() {
func testAllStoryboards() {
let parser = StoryboardParser()
do {
try parser.parseDirectory(at: Fixtures.directory(sub: .storyboardsMacOS))
Expand All @@ -56,16 +56,4 @@ class StoryboardsMacOSTests: XCTestCase {
let result = parser.stencilContext()
XCTDiffContexts(result, expected: "all.plist", sub: .storyboardsMacOS)
}

func testAllStoryboardsWithCustomName() {
let parser = StoryboardParser()
do {
try parser.parseDirectory(at: Fixtures.directory(sub: .storyboardsMacOS))
} catch {
print("Error: \(error.localizedDescription)")
}

let result = parser.stencilContext(sceneEnumName: "XCTStoryboardsScene", segueEnumName: "XCTStoryboardsSegue")
XCTDiffContexts(result, expected: "customname.plist", sub: .storyboardsMacOS)
}
}
18 changes: 3 additions & 15 deletions Tests/SwiftGenKitTests/StoryboardsiOSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class StoryboardsiOSTests: XCTestCase {
XCTDiffContexts(result, expected: "empty.plist", sub: .storyboardsiOS)
}

func testMessageStoryboardWithDefaults() {
func testMessageStoryboard() {
let parser = StoryboardParser()
do {
try parser.addStoryboard(at: Fixtures.path(for: "Message.storyboard", sub: .storyboardsiOS))
Expand All @@ -34,7 +34,7 @@ class StoryboardsiOSTests: XCTestCase {
XCTDiffContexts(result, expected: "messages.plist", sub: .storyboardsiOS)
}

func testAnonymousStoryboardWithDefaults() {
func testAnonymousStoryboard() {
let parser = StoryboardParser()
do {
try parser.addStoryboard(at: Fixtures.path(for: "Anonymous.storyboard", sub: .storyboardsiOS))
Expand All @@ -46,7 +46,7 @@ class StoryboardsiOSTests: XCTestCase {
XCTDiffContexts(result, expected: "anonymous.plist", sub: .storyboardsiOS)
}

func testAllStoryboardsWithDefaults() {
func testAllStoryboards() {
let parser = StoryboardParser()
do {
try parser.parseDirectory(at: Fixtures.directory(sub: .storyboardsiOS))
Expand All @@ -57,16 +57,4 @@ class StoryboardsiOSTests: XCTestCase {
let result = parser.stencilContext()
XCTDiffContexts(result, expected: "all.plist", sub: .storyboardsiOS)
}

func testAllStoryboardsWithCustomName() {
let parser = StoryboardParser()
do {
try parser.parseDirectory(at: Fixtures.directory(sub: .storyboardsiOS))
} catch {
print("Error: \(error.localizedDescription)")
}

let result = parser.stencilContext(sceneEnumName: "XCTStoryboardsScene", segueEnumName: "XCTStoryboardsSegue")
XCTDiffContexts(result, expected: "customname.plist", sub: .storyboardsiOS)
}
}
28 changes: 4 additions & 24 deletions Tests/SwiftGenKitTests/StringsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,12 @@ class StringsTests: XCTestCase {
XCTDiffContexts(result, expected: "empty.plist", sub: .strings)
}

func testEntriesWithDefaults() {
let parser = StringsFileParser()
parser.addEntry(StringsFileParser.Entry(key: "Title",
translation: "My awesome title"))
parser.addEntry(StringsFileParser.Entry(key: "Greetings",
translation: "Hello, my name is %@ and I'm %d",
types: .object, .int))

let result = parser.stencilContext()
XCTDiffContexts(result, expected: "entries.plist", sub: .strings)
}

func testFileWithDefaults() throws {
func testLocalizable() throws {
let parser = StringsFileParser()
try parser.parseFile(at: Fixtures.path(for: "Localizable.strings", sub: .strings))

let result = parser.stencilContext()
XCTDiffContexts(result, expected: "defaults.plist", sub: .strings)
XCTDiffContexts(result, expected: "localizable.plist", sub: .strings)
}

func testMultiline() throws {
Expand All @@ -49,23 +37,15 @@ class StringsTests: XCTestCase {
XCTDiffContexts(result, expected: "multiline.plist", sub: .strings)
}

func testUTF8FileWithDefaults() throws {
func testUTF8File() throws {
let parser = StringsFileParser()
try parser.parseFile(at: Fixtures.path(for: "LocUTF8.strings", sub: .strings))

let result = parser.stencilContext()
XCTDiffContexts(result, expected: "utf8.plist", sub: .strings)
}

func testFileWithCustomName() throws {
let parser = StringsFileParser()
try parser.parseFile(at: Fixtures.path(for: "Localizable.strings", sub: .strings))

let result = parser.stencilContext(enumName: "XCTLoc")
XCTDiffContexts(result, expected: "customname.plist", sub: .strings)
}

func testFileWithStructuredOnly() throws {
func testStructuredOnly() throws {
let parser = StringsFileParser()
try parser.parseFile(at: Fixtures.path(for: "LocStructuredOnly.strings", sub: .strings))

Expand Down