Skip to content

Commit 201edf2

Browse files
committed
Merge branch 'dev'
2 parents be41e9d + da1e19e commit 201edf2

File tree

103 files changed

+622
-468
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+622
-468
lines changed

JSONConverter.xcodeproj/project.pbxproj

Lines changed: 412 additions & 408 deletions
Large diffs are not rendered by default.

JSONConverter/Classes/Manager/FileConfigManager.swift renamed to JSONConverter/Classes/Builder/FileConfigBuilder.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import Foundation
1010

1111
private let FILE_CACHE_CONFIG_KEY = "FILE_CACHE_CONFIG_KEY"
1212

13-
class FileConfigManager {
13+
class FileConfigBuilder {
1414

1515
private lazy var fileConfigDic: [String: String]? = {
1616
let dic = UserDefaults.standard.object(forKey: FILE_CACHE_CONFIG_KEY) as? [String: String]
1717
return dic
1818
}()
1919

20-
static let shared: FileConfigManager = {
21-
let manager = FileConfigManager()
20+
static let shared: FileConfigBuilder = {
21+
let manager = FileConfigBuilder()
2222
return manager
2323
}()
2424

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//
2+
// JSONParseManager.swift
3+
// Test
4+
//
5+
// Created by Yao on 2018/2/3.
6+
// Copyright © 2018年 Yao. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
class JSONBuilder {
12+
13+
static let shared: JSONBuilder = {
14+
let manager = JSONBuilder()
15+
return manager
16+
}()
17+
18+
private var file: File!
19+
20+
func buildWithJSONObject(_ obj: Any, file: File) -> (String, String?) {
21+
file.contents.removeAll()
22+
self.file = file
23+
var content : Content?
24+
let propertyKey = file.rootName.propertyName()
25+
26+
switch obj {
27+
case let dic as [String: Any]:
28+
content = addDictionaryWithKeyName(propertyKey, dic: dic)
29+
case let arr as [Any]:
30+
_ = addArraryWithKeyName(propertyKey, valueArrary: arr)
31+
default:
32+
assertionFailure("parse object type error")
33+
}
34+
35+
if let content = content {
36+
file.contents.insert(content, at: 0)
37+
}
38+
39+
return file.toString()
40+
}
41+
42+
43+
private func addDictionaryWithKeyName(_ keyName: String, dic: [String: Any]) -> Content {
44+
let content = file.contentWithKeyName(keyName)
45+
46+
dic.forEach { (item) in
47+
let keyName = item.key
48+
var property: Property?
49+
50+
switch item.value {
51+
case _ as String:
52+
property = file.propertyWithKeyName(keyName, type: .String)
53+
case let num as NSNumber:
54+
property = file.propertyWithKeyName(keyName, type: num.valueType())
55+
case let dic as [String: Any]:
56+
property = file.propertyWithKeyName(keyName, type: .Dictionary)
57+
let content = addDictionaryWithKeyName(keyName, dic: dic)
58+
file.contents.insert(content, at: 0)
59+
case let arr as [Any]:
60+
property = addArraryWithKeyName(keyName, valueArrary: arr)
61+
case _ as NSNull:
62+
property = file.propertyWithKeyName(keyName, type: .nil)
63+
default:
64+
assertionFailure("build JSON object type error")
65+
}
66+
67+
if let propertyModel = property {
68+
content.properties.append(propertyModel)
69+
}
70+
}
71+
72+
return content
73+
}
74+
75+
private func addArraryWithKeyName(_ keyName: String, valueArrary: [Any]) -> Property? {
76+
var item = valueArrary.first
77+
if valueArrary.first is Dictionary<String, Any> {
78+
var temp = [String: Any]()
79+
valueArrary.forEach { temp.merge($0 as! [String: Any]) { $1 } }
80+
item = temp
81+
}
82+
83+
if let item = item {
84+
var propertyModel: Property?
85+
switch item {
86+
case _ as String:
87+
propertyModel = file.propertyWithKeyName(keyName, type: .ArrayString)
88+
case let num as NSNumber:
89+
let type = PropertyType(rawValue: num.valueType().rawValue + 6)!
90+
propertyModel = file.propertyWithKeyName(keyName, type: type)
91+
case let dic as [String: Any]:
92+
propertyModel = file.propertyWithKeyName(keyName, type: .ArrayDictionary)
93+
let content = addDictionaryWithKeyName(keyName, dic: dic)
94+
file.contents.insert(content, at: 0)
95+
default:
96+
assertionFailure("build JSON object type error")
97+
break
98+
}
99+
100+
return propertyModel
101+
}else {
102+
return nil
103+
}
104+
}
105+
}
106+
107+
108+
109+
110+
111+
112+

JSONConverter/Classes/Manager/JSONParseManager.swift renamed to JSONConverter/Classes/Builder/JSONParseManager.swift

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
import Foundation
1010

11-
class JSONParseManager {
11+
class JSONBuilder {
1212

13-
static let shared: JSONParseManager = {
14-
let manager = JSONParseManager()
13+
static let shared: JSONBuilder = {
14+
let manager = JSONBuilder()
1515
return manager
1616
}()
1717

@@ -25,9 +25,9 @@ class JSONParseManager {
2525

2626
switch obj {
2727
case let dic as [String: Any]:
28-
content = handleDictionary(propertyKey: propertyKey, dic: dic)
28+
content = addDictionaryWithKeyName(propertyKey, dic: dic)
2929
case let arr as [Any]:
30-
_ = handleArrary(itemKey: propertyKey, arr: arr)
30+
_ = addArraryWithKeyName(propertyKey, valueArrary: arr)
3131
default:
3232
assertionFailure("parse object type error")
3333
}
@@ -40,26 +40,26 @@ class JSONParseManager {
4040
}
4141

4242

43-
private func handleDictionary(propertyKey: String, dic: [String: Any]) -> Content {
44-
let content = file.content(withPropertyKey: propertyKey)
43+
private func addDictionaryWithKeyName(_ keyName: String, dic: [String: Any]) -> Content {
44+
let content = file.contentWithKeyName(keyName)
4545

4646
dic.forEach { (item) in
4747
let itemKey = item.key
4848
var propertyModel: Property?
4949

5050
switch item.value {
5151
case _ as String:
52-
propertyModel = file.property(withPropertykey: itemKey, type: .String)
52+
propertyModel = file.propertyWithKeyName(itemKey, type: .String)
5353
case let num as NSNumber:
54-
propertyModel = file.property(withPropertykey: itemKey, type: num.valueType())
54+
propertyModel = file.propertyWithKeyName(itemKey, type: num.valueType())
5555
case let dic as [String: Any]:
56-
propertyModel = file.property(withPropertykey: itemKey, type: .Dictionary)
57-
let content = handleDictionary(propertyKey: itemKey, dic: dic)
56+
propertyModel = file.propertyWithKeyName(itemKey, type: .Dictionary)
57+
let content = addDictionaryWithKeyName(itemKey, dic: dic)
5858
file.contents.insert(content, at: 0)
5959
case let arr as [Any]:
60-
propertyModel = handleArrary(itemKey: itemKey, arr: arr)
60+
propertyModel = addArraryWithKeyName(itemKey, valueArrary: arr)
6161
case _ as NSNull:
62-
propertyModel = file.property(withPropertykey: itemKey, type: .nil)
62+
propertyModel = file.propertyWithKeyName(itemKey, type: .nil)
6363
default:
6464
assertionFailure("parse object type error")
6565
}
@@ -72,18 +72,22 @@ class JSONParseManager {
7272
return content
7373
}
7474

75-
private func handleArrary(itemKey: String, arr: [Any]) -> Property? {
76-
if let first = arr.first {
75+
private func addArraryWithKeyName(_ keyName: String, valueArrary: [Any]) -> Property? {
76+
if valueArrary.count == 0 {
77+
return nil
78+
}
79+
80+
if let first = valueArrary.first {
7781
var propertyModel: Property?
7882
switch first {
7983
case _ as String:
80-
propertyModel = file.property(withPropertykey: itemKey, type: .ArrayString)
84+
propertyModel = file.propertyWithKeyName(keyName, type: .ArrayString)
8185
case let num as NSNumber:
8286
let type = PropertyType(rawValue: num.valueType().rawValue + 6)!
83-
propertyModel = file.property(withPropertykey: itemKey, type: type)
87+
propertyModel = file.propertyWithKeyName(keyName, type: type)
8488
case let dic as [String: Any]:
85-
propertyModel = file.property(withPropertykey: itemKey, type: .ArrayDictionary)
86-
let content = handleDictionary(propertyKey: itemKey, dic: dic)
89+
propertyModel = file.propertyWithKeyName(keyName, type: .ArrayDictionary)
90+
let content = addDictionaryWithKeyName(keyName, dic: dic)
8791
file.contents.insert(content, at: 0)
8892
default:
8993
assertionFailure("parse object type error")

JSONConverter/Classes/Controller/Main/Controller/MainViewController.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class MainViewController: NSViewController {
135135
}
136136

137137
private func setupCacheConfig() {
138-
let configFile = FileConfigManager.shared.currentConfigFile()
138+
let configFile = FileConfigBuilder.shared.currentConfigFile()
139139
languageBox.selectItem(at: configFile.langStruct.langType.rawValue)
140140
structureBox.selectItem(at: configFile.langStruct.structType.rawValue)
141141
if let themeIndex = highlightr.availableThemes().firstIndex(where: {configFile.theme == $0}) {
@@ -169,7 +169,7 @@ class MainViewController: NSViewController {
169169
}
170170

171171
func exportClassesFileWithPath(_ path : String) {
172-
let configFile = FileConfigManager.shared.currentConfigFile()
172+
let configFile = FileConfigBuilder.shared.currentConfigFile()
173173
let classfilePath = "\(path)/\(configFile.rootName.className(withPrefix: configFile.prefix))"
174174
let suffix = configFile.classSuffixString()
175175

@@ -216,8 +216,8 @@ class MainViewController: NSViewController {
216216
let JSONData = try? JSONSerialization.data(withJSONObject: JSONObject, options: [.sortedKeys, .prettyPrinted]),
217217
let JSONString = String(data: JSONData, encoding: .utf8) {
218218

219-
let configFile = FileConfigManager.shared.currentConfigFile()
220-
let fileString = JSONParseManager.shared.parseJSONObject(JSONObject, file:configFile)
219+
let configFile = FileConfigBuilder.shared.currentConfigFile()
220+
let fileString = JSONBuilder.shared.buildWithJSONObject(JSONObject, file:configFile)
221221
let endTime1 = CFAbsoluteTimeGetCurrent()
222222
let offsetTime1 = Int((endTime1 - startTime) * 1000)
223223

@@ -265,7 +265,7 @@ class MainViewController: NSViewController {
265265
}
266266

267267
private func updateCacheConfigAndUI() {
268-
let configFile = FileConfigManager.shared.currentConfigFile()
268+
let configFile = FileConfigBuilder.shared.currentConfigFile()
269269
guard let langType = LangType(rawValue: languageBox.indexOfSelectedItem),
270270
let structType = StructType(rawValue: structureBox.indexOfSelectedItem)
271271
else {
@@ -293,7 +293,7 @@ class MainViewController: NSViewController {
293293

294294
let theme = highlightr.availableThemes()[structureBox.indexOfSelectedItem]
295295
configFile.theme = theme
296-
FileConfigManager.shared.updateConfigWithFile(configFile)
296+
FileConfigBuilder.shared.updateConfigWithFile(configFile)
297297
generateClasses()
298298
}
299299

@@ -312,8 +312,8 @@ class MainViewController: NSViewController {
312312

313313
extension MainViewController {
314314
@objc func applicationWillTerminateNotiAction() {
315-
let currentConfigFile = FileConfigManager.shared.currentConfigFile()
316-
FileConfigManager.shared.updateConfigWithFile(currentConfigFile)
315+
let currentConfigFile = FileConfigBuilder.shared.currentConfigFile()
316+
FileConfigBuilder.shared.updateConfigWithFile(currentConfigFile)
317317
}
318318
}
319319

JSONConverter/Classes/Controller/Setting/SettingViewController.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class SettingViewController: NSViewController {
5454
}
5555

5656
private func updateCacheConfigUI() {
57-
let configFile = FileConfigManager.shared.currentConfigFile()
57+
let configFile = FileConfigBuilder.shared.currentConfigFile()
5858
prefixField.stringValue = configFile.prefix ?? ""
5959
rootClassField.stringValue = configFile.rootName
6060
parentClassField.stringValue = configFile.parentName ?? ""
@@ -65,23 +65,23 @@ class SettingViewController: NSViewController {
6565
}
6666

6767
@IBAction func saveConfigAction(_ sender: NSButton) {
68-
let configFile = FileConfigManager.shared.currentConfigFile()
68+
let configFile = FileConfigBuilder.shared.currentConfigFile()
6969
configFile.prefix = prefixField.stringValue
7070
configFile.rootName = rootClassField.stringValue
7171
configFile.parentName = parentClassField.stringValue
7272
configFile.header = headerField.stringValue
7373
configFile.isCustomHeader = customHeaderSwitch.state.rawValue == 1
7474
configFile.autoCaseUnderline = autoHumpSwitch.state.rawValue == 1
75-
FileConfigManager.shared.updateConfigWithFile(configFile)
75+
FileConfigBuilder.shared.updateConfigWithFile(configFile)
7676
fileConfigChangedClosure?()
7777
dismiss(nil)
7878
}
7979

8080
@IBAction func customFileHeaderSwitch(_ sender: NSSwitch) {
81-
let configFile = FileConfigManager.shared.currentConfigFile()
81+
let configFile = FileConfigBuilder.shared.currentConfigFile()
8282
configFile.isCustomHeader = customHeaderSwitch.state.rawValue == 1
8383
configFile.autoCaseUnderline = autoHumpSwitch.state.rawValue == 1
84-
FileConfigManager.shared.updateConfigWithFile(configFile)
84+
FileConfigBuilder.shared.updateConfigWithFile(configFile)
8585
updateCacheConfigUI()
8686
}
8787
}

JSONConverter/Classes/Model/File.swift

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ class File {
5151
}
5252
}
5353

54-
func content(withPropertyKey key: String) -> Content {
55-
let content = Content(propertyKey: key, langStruct: langStruct, parentClsName: parentName, prefixStr: prefix, autoCaseUnderline: autoCaseUnderline)
54+
func contentWithKeyName(_ keyName: String) -> Content {
55+
let content = Content(propertyKey: keyName, langStruct: langStruct, parentClsName: parentName, prefixStr: prefix, autoCaseUnderline: autoCaseUnderline)
5656
return content
5757
}
5858

59-
func property(withPropertykey key: String, type: PropertyType) -> Property {
60-
let property = Property(propertyKey: key, type: type, langStruct: langStruct, prefixStr: prefix, autoCaseUnderline: autoCaseUnderline)
59+
func propertyWithKeyName(_ keyName: String, type: PropertyType) -> Property {
60+
let property = Property(propertyKey: keyName, type: type, langStruct: langStruct, prefixStr: prefix, autoCaseUnderline: autoCaseUnderline)
6161
return property
6262
}
6363

@@ -72,6 +72,20 @@ class File {
7272
"structType": "\(langStruct.structType.rawValue)", "theme": theme]
7373
}
7474

75+
func classSuffixString() -> (String, String?) {
76+
switch langStruct.langType {
77+
case .Swift, .HandyJSON, .SwiftyJSON, .ObjectMapper, .Codable:
78+
return ( "swift", nil)
79+
case .ObjC:
80+
return ("h", "m")
81+
case .Flutter:
82+
return ("dart", nil)
83+
}
84+
}
85+
}
86+
87+
extension File {
88+
7589
private func defaultHeaderString(suffix: String) -> String {
7690
let headerString = """
7791
//
@@ -154,16 +168,4 @@ class File {
154168
return nil
155169
}
156170
}
157-
158-
159-
func classSuffixString() -> (String, String?) {
160-
switch langStruct.langType {
161-
case .Swift, .HandyJSON, .SwiftyJSON, .ObjectMapper, .Codable:
162-
return ( "swift", nil)
163-
case .ObjC:
164-
return ("h", "m")
165-
case .Flutter:
166-
return ("dart", nil)
167-
}
168-
}
169171
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright (c) 2006, Ivan Sagalaev
2+
All rights reserved.
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are met:
5+
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above copyright
9+
notice, this list of conditions and the following disclaimer in the
10+
documentation and/or other materials provided with the distribution.
11+
* Neither the name of highlight.js nor the names of its contributors
12+
may be used to endorse or promote products derived from this software
13+
without specific prior written permission.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
16+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
19+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

JSONConverter/Vendor/Highlightr_2.1.0/Assets/Highlighter/highlight.min.js renamed to JSONConverter/Vendor/Highlightr/Assets/Highlighter/highlight.min.js

File renamed without changes.

JSONConverter/Vendor/Highlightr_2.1.0/Assets/styles/a11y-dark.min.css renamed to JSONConverter/Vendor/Highlightr/Assets/styles/a11y-dark.min.css

File renamed without changes.

0 commit comments

Comments
 (0)