From d5108e06505b92051248cb04c832d6125b9ea6e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Garci=CC=81a?= Date: Sat, 11 Mar 2017 16:08:28 +0100 Subject: [PATCH 1/3] resourcesChecked --- Tests/Resources | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Resources b/Tests/Resources index 35a8748..6a243cb 160000 --- a/Tests/Resources +++ b/Tests/Resources @@ -1 +1 @@ -Subproject commit 35a8748f00c11859505ae83e943abb7318919487 +Subproject commit 6a243cb9b1309ad3b6618318d805e9719670ed7b From b7e4fac4ee2fa57c969a2501831a4a1f7ab04e44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Garci=CC=81a?= Date: Sat, 11 Mar 2017 22:09:35 +0100 Subject: [PATCH 2/3] recopile cells with reuseIdentifier --- Sources/Parsers/StoryboardParser.swift | 37 ++++++++++++++++++++++-- Sources/Stencil/StoryboardsContext.swift | 30 ++++++++++++++----- 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/Sources/Parsers/StoryboardParser.swift b/Sources/Parsers/StoryboardParser.swift index 5ece2ed..12aa29c 100644 --- a/Sources/Parsers/StoryboardParser.swift +++ b/Sources/Parsers/StoryboardParser.swift @@ -28,9 +28,16 @@ public final class StoryboardParser { let customModule: String? } + struct Cell { + let identifier: String + let customClass: String? + let customModule: String? + } + var initialScenes = [String: InitialScene]() var storyboardsScenes = [String: Set]() var storyboardsSegues = [String: Set]() + var storyboardsCells = [String: Set]() var modules = Set() public init() {} @@ -40,10 +47,12 @@ public final class StoryboardParser { var initialScene: InitialScene? var scenes = Set() var segues = Set() + var cells = Set() var inScene = false var readyForFirstObject = false var readyForConnections = false - + var readyForTableView = false + @objc func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String: String]) { @@ -71,6 +80,14 @@ public final class StoryboardParser { customModule: customModule)) } readyForFirstObject = false + case "tableView": + readyForTableView = true + case "tableViewCell" where readyForTableView: + if let reuseIdentifier = attributeDict["reuseIdentifier"] { + let customClass = attributeDict["customClass"] + let customModule = attributeDict["customModule"] + cells.insert(Cell(identifier: reuseIdentifier, customClass: customClass, customModule: customModule)) + } case "connections": readyForConnections = true case "segue" where readyForConnections: @@ -91,6 +108,8 @@ public final class StoryboardParser { inScene = false case "objects" where inScene: readyForFirstObject = false + case "tableView": + readyForTableView = false case "connections": readyForConnections = false default: @@ -110,7 +129,8 @@ public final class StoryboardParser { initialScenes[storyboardName] = delegate.initialScene storyboardsScenes[storyboardName] = delegate.scenes storyboardsSegues[storyboardName] = delegate.segues - + storyboardsCells[storyboardName] = delegate.cells + modules.formUnion(collectModules(initial: delegate.initialScene, scenes: delegate.scenes, segues: delegate.segues)) } @@ -163,3 +183,16 @@ extension StoryboardParser.Segue: Hashable { return identifier.hashValue ^ (customModule?.hashValue ?? 0) ^ (customClass?.hashValue ?? 0) } } + +extension StoryboardParser.Cell: Equatable { } +func == (lhs: StoryboardParser.Cell, rhs: StoryboardParser.Cell) -> Bool { + return lhs.identifier == rhs.identifier && + lhs.customClass == rhs.customClass && + lhs.customModule == rhs.customModule +} + +extension StoryboardParser.Cell: Hashable { + var hashValue: Int { + return identifier.hashValue ^ (customModule?.hashValue ?? 0) ^ (customClass?.hashValue ?? 0) ^ (customClass?.hashValue ?? 0) + } +} diff --git a/Sources/Stencil/StoryboardsContext.swift b/Sources/Stencil/StoryboardsContext.swift index 711ef24..33628b2 100644 --- a/Sources/Stencil/StoryboardsContext.swift +++ b/Sources/Stencil/StoryboardsContext.swift @@ -37,7 +37,8 @@ private func uppercaseFirst(_ string: String) -> String { */ extension StoryboardParser { public func stencilContext(sceneEnumName: String = "StoryboardScene", - segueEnumName: String = "StoryboardSegue") -> [String: Any] { + segueEnumName: String = "StoryboardSegue", + cellEnumName: String = "StoryboardCells") -> [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] @@ -60,14 +61,15 @@ extension StoryboardParser { if let scenes = storyboardsScenes[storyboardName] { sbMap["scenes"] = scenes .sorted(by: {$0.storyboardID < $1.storyboardID}) - .map { (scene: Scene) -> [String:Any] in + .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" { + } + else if scene.tag == "viewController" { return [ "identifier": scene.storyboardID, "baseType": uppercaseFirst(scene.tag), @@ -81,17 +83,29 @@ extension StoryboardParser { } // 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 { (segue: Segue) -> [String: String] in + ["identifier": segue.identifier, "customClass": segue.customClass ?? ""] + } + } + + // All Segues + if let cells = storyboardsCells[storyboardName] { + sbMap["cells"] = cells + .sorted(by: {$0.identifier < $1.identifier}) + .map { (cell: Cell) -> [String: String] in + ["identifier": cell.identifier, "customClass": cell.customClass ?? ""] + } } + return sbMap } + return [ "sceneEnumName": sceneEnumName, "segueEnumName": segueEnumName, + "cellEnumName": cellEnumName, "storyboards": storyboardsMap, "modules": modules.sorted(), From d5bc42d2cefef71f19ee315f432d604bbeff70e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Garci=CC=81a?= Date: Sun, 12 Mar 2017 01:14:24 +0100 Subject: [PATCH 3/3] fix lint errors --- Sources/Parsers/StoryboardParser.swift | 10 +++++++--- Sources/Stencil/StoryboardsContext.swift | 11 ++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Sources/Parsers/StoryboardParser.swift b/Sources/Parsers/StoryboardParser.swift index 12aa29c..f849060 100644 --- a/Sources/Parsers/StoryboardParser.swift +++ b/Sources/Parsers/StoryboardParser.swift @@ -33,7 +33,7 @@ public final class StoryboardParser { let customClass: String? let customModule: String? } - + var initialScenes = [String: InitialScene]() var storyboardsScenes = [String: Set]() var storyboardsSegues = [String: Set]() @@ -52,7 +52,8 @@ public final class StoryboardParser { var readyForFirstObject = false var readyForConnections = false var readyForTableView = false - + + // swiftlint:disable cyclomatic_complexity @objc func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String: String]) { @@ -100,6 +101,7 @@ public final class StoryboardParser { break } } + // swiftlint:enable cyclomatic_complexity @objc func parser(_ parser: XMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) { @@ -130,7 +132,7 @@ public final class StoryboardParser { storyboardsScenes[storyboardName] = delegate.scenes storyboardsSegues[storyboardName] = delegate.segues storyboardsCells[storyboardName] = delegate.cells - + modules.formUnion(collectModules(initial: delegate.initialScene, scenes: delegate.scenes, segues: delegate.segues)) } @@ -193,6 +195,8 @@ func == (lhs: StoryboardParser.Cell, rhs: StoryboardParser.Cell) -> Bool { extension StoryboardParser.Cell: Hashable { var hashValue: Int { + // swiftlint:disable line_length return identifier.hashValue ^ (customModule?.hashValue ?? 0) ^ (customClass?.hashValue ?? 0) ^ (customClass?.hashValue ?? 0) + // swiftlint:enable line_length } } diff --git a/Sources/Stencil/StoryboardsContext.swift b/Sources/Stencil/StoryboardsContext.swift index 33628b2..b256406 100644 --- a/Sources/Stencil/StoryboardsContext.swift +++ b/Sources/Stencil/StoryboardsContext.swift @@ -36,6 +36,7 @@ private func uppercaseFirst(_ string: String) -> String { - `class`: `String` (absent if generic UIStoryboardSegue) */ extension StoryboardParser { + // swiftlint:disable function_body_length public func stencilContext(sceneEnumName: String = "StoryboardScene", segueEnumName: String = "StoryboardSegue", cellEnumName: String = "StoryboardCells") -> [String: Any] { @@ -68,8 +69,7 @@ extension StoryboardParser { "customClass": customClass, "customModule": scene.customModule ?? "" ] - } - else if scene.tag == "viewController" { + } else if scene.tag == "viewController" { return [ "identifier": scene.storyboardID, "baseType": uppercaseFirst(scene.tag), @@ -89,7 +89,7 @@ extension StoryboardParser { ["identifier": segue.identifier, "customClass": segue.customClass ?? ""] } } - + // All Segues if let cells = storyboardsCells[storyboardName] { sbMap["cells"] = cells @@ -98,10 +98,10 @@ extension StoryboardParser { ["identifier": cell.identifier, "customClass": cell.customClass ?? ""] } } - + return sbMap } - + return [ "sceneEnumName": sceneEnumName, "segueEnumName": segueEnumName, @@ -113,4 +113,5 @@ extension StoryboardParser { "extraImports": modules.sorted() ] } + // swiftlint:enable function_body_length }