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

Commit

Permalink
fix some lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
djbe committed Mar 5, 2017
1 parent 54f72df commit 00865b3
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Sources/Stencil/AssetsCatalogContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension AssetsCatalogParser {
return [
"catalogs": structured,
"param": ["enumName": enumName],

// NOTE: This is a deprecated variable
"enumName": enumName,
"images": images
Expand Down
6 changes: 3 additions & 3 deletions Sources/Stencil/ColorsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ extension ColorsFileParser {
"green": comps[1],
"blue": comps[2],
"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 [
"colors": colorMap,
"param": ["enumName": enumName],

// NOTE: This is a deprecated variable
"enumName": enumName
]
Expand Down
2 changes: 1 addition & 1 deletion Sources/Stencil/FontsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension FontsFileParser {
return [
"families": families,
"param": ["enumName": enumName],

// NOTE: This is a deprecated variable
"enumName": enumName
]
Expand Down
86 changes: 51 additions & 35 deletions Sources/Stencil/StoryboardsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,49 +43,19 @@ 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
}
Expand All @@ -103,4 +73,50 @@ extension StoryboardParser {
"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 ?? ""
]
}
}
8 changes: 4 additions & 4 deletions Sources/Stencil/StringsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ extension StringsFileParser {
"translation": entry.translation.newlineEscaped,
"keytail": keytail
]

if entry.types.count > 0 {
result["parameters"] = entry.types.map { $0.rawValue }

// NOTE: params is deprecated
result["params"] = [
"types": entry.types.map { $0.rawValue },
Expand All @@ -56,7 +56,7 @@ extension StringsFileParser {
"typednames": entry.types.enumerated().map { "p\($0): \($1.rawValue)" }
]
}

return result
}

Expand All @@ -75,7 +75,7 @@ extension StringsFileParser {
return [
"tables": tables,
"param": ["enumName": enumName],

// NOTE: These are deprecated variables
"enumName": enumName,
"strings": strings,
Expand Down
6 changes: 3 additions & 3 deletions Tests/SwiftGenKitTests/StoryboardsMacOSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ class StoryboardsMacOSTests: XCTestCase {

XCTDiffContexts(result, expected)
}

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")
let expected = Fixtures.context(for: "customname.plist", sub: .storyboardsMacOS)

XCTDiffContexts(result, expected)
}
}

0 comments on commit 00865b3

Please sign in to comment.