Permalink
Browse files

Remove dependency on SwiftyJSON

  • Loading branch information...
dabbott committed Nov 22, 2017
1 parent 9111af5 commit d31eb1e903b01707815e98f99b5bd7bb90b73399
@@ -19,7 +19,6 @@
301433781F5B525100525DB1 /* ListEditor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 301433771F5B525100525DB1 /* ListEditor.swift */; };
301493A71EC0F415005BC573 /* CanvasView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 301493A61EC0F415005BC573 /* CanvasView.swift */; };
301D7EDC1F47A29D0098AB0D /* Modules in Resources */ = {isa = PBXBuildFile; fileRef = 301D7EDB1F47A29D0098AB0D /* Modules */; };
3030311B1F34E4E80078086F /* CSJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3030311A1F34E4E80078086F /* CSJSON.swift */; };
30335A071F5A2878006E507B /* URLExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30335A061F5A2878006E507B /* URLExtensions.swift */; };
30335A0C1F5B2F8B006E507B /* CaseList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30335A0B1F5B2F8B006E507B /* CaseList.swift */; };
30335A101F5B3023006E507B /* CSCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30335A0F1F5B3023006E507B /* CSCase.swift */; };
@@ -55,7 +54,6 @@
307718F21F365BCD003A597B /* CSValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 307718F11F365BCD003A597B /* CSValue.swift */; };
307718F41F366AEA003A597B /* CSValueField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 307718F31F366AEA003A597B /* CSValueField.swift */; };
307718F81F37AAFE003A597B /* CSScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 307718F71F37AAFE003A597B /* CSScope.swift */; };
307718FA1F3B6CEB003A597B /* JSONExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 307718F91F3B6CEB003A597B /* JSONExtensions.swift */; };
307718FE1F3CBDEA003A597B /* CSFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 307718FD1F3CBDEA003A597B /* CSFunction.swift */; };
307719001F3CD3F1003A597B /* MultilevelPopupField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 307718FF1F3CD3F1003A597B /* MultilevelPopupField.swift */; };
307B7B4F1F9A71C5001A62D9 /* MetadataEditorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 307B7B4E1F9A71C5001A62D9 /* MetadataEditorView.swift */; };
@@ -126,7 +124,6 @@
301433771F5B525100525DB1 /* ListEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListEditor.swift; sourceTree = "<group>"; };
301493A61EC0F415005BC573 /* CanvasView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CanvasView.swift; sourceTree = "<group>"; };
301D7EDB1F47A29D0098AB0D /* Modules */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Modules; sourceTree = "<group>"; };
3030311A1F34E4E80078086F /* CSJSON.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSJSON.swift; sourceTree = "<group>"; };
30335A061F5A2878006E507B /* URLExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLExtensions.swift; sourceTree = "<group>"; };
30335A0B1F5B2F8B006E507B /* CaseList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CaseList.swift; sourceTree = "<group>"; };
30335A0F1F5B3023006E507B /* CSCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSCase.swift; sourceTree = "<group>"; };
@@ -162,7 +159,6 @@
307718F11F365BCD003A597B /* CSValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSValue.swift; sourceTree = "<group>"; };
307718F31F366AEA003A597B /* CSValueField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSValueField.swift; sourceTree = "<group>"; };
307718F71F37AAFE003A597B /* CSScope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSScope.swift; sourceTree = "<group>"; };
307718F91F3B6CEB003A597B /* JSONExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONExtensions.swift; sourceTree = "<group>"; };
307718FD1F3CBDEA003A597B /* CSFunction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSFunction.swift; sourceTree = "<group>"; };
307718FF1F3CD3F1003A597B /* MultilevelPopupField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultilevelPopupField.swift; sourceTree = "<group>"; };
307B7B4E1F9A71C5001A62D9 /* MetadataEditorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetadataEditorView.swift; sourceTree = "<group>"; };
@@ -376,7 +372,6 @@
children = (
3094DFE21F68D19C00E5C7F0 /* CALayerExtensions.swift */,
30F4FD541F76B9DB0048691C /* DictionaryExtensions.swift */,
307718F91F3B6CEB003A597B /* JSONExtensions.swift */,
30A3F13D1F300294004C7631 /* NSColorExtensions.swift */,
306D2FEF1F847DCB00907B4E /* NSImageExtensions.swift */,
30D9B40D1F79BADC00C8A3D4 /* NSMenuExtensions.swift */,
@@ -405,7 +400,6 @@
3090D7D21F032305009277E7 /* CSComponentLayer.swift */,
309777711F2BA78E004C8975 /* CSData.swift */,
307718FD1F3CBDEA003A597B /* CSFunction.swift */,
3030311A1F34E4E80078086F /* CSJSON.swift */,
3090D7921F01B2EF009277E7 /* CSLayer.swift */,
3090D78C1F01B050009277E7 /* CSParameter.swift */,
307718F71F37AAFE003A597B /* CSScope.swift */,
@@ -631,7 +625,6 @@
30902A281F7B208A00B938BE /* CanvasCollectionView.swift in Sources */,
30D799821F2BE90E00EF12D7 /* SettingRow.swift in Sources */,
30C8BC321EDB758C00B99F1B /* Canvas.swift in Sources */,
3030311B1F34E4E80078086F /* CSJSON.swift in Sources */,
3003027C1EDCE0880085E140 /* CSComponent.swift in Sources */,
304004331ED8AB5A00AFCF2D /* CanvasListEditor.swift in Sources */,
3056275E1FBA0C0700026796 /* CSConstraint.swift in Sources */,
@@ -668,7 +661,6 @@
301433781F5B525100525DB1 /* ListEditor.swift in Sources */,
305A19581F463BD300EA033C /* NSTextFieldExtensions.swift in Sources */,
3069E09C1F324C550005E9A8 /* CSWorkspacePreferences.swift in Sources */,
307718FA1F3B6CEB003A597B /* JSONExtensions.swift in Sources */,
300302761EDCDA030085E140 /* LogicListView.swift in Sources */,
304478BC1F32923700FD06E0 /* NSPointExtensions.swift in Sources */,
3040EFC81F2FAC9C007C5368 /* Operators.swift in Sources */,
@@ -9,7 +9,6 @@
import Foundation
import Cocoa
import yoga
import SwiftyJSON
import Lottie
func measureText(string: NSAttributedString, width: CGFloat, maxNumberOfLines: Int = -1) -> NSSize {
@@ -322,7 +321,7 @@ typealias SketchFileReferenceMap = [String: SketchFileReference]
func renderBoxJSON(layer: CSLayer, node: YGNodeRef, references: inout SketchFileReferenceMap) -> CSData {
let layout = node.layout
var output = CSData.from(json: JSON(layer.toJSON()!))
var output = layer.toData()
let layoutJSON = CSData.Object([
"left": layout.left.toData(),
@@ -356,7 +355,7 @@ func renderBoxJSON(layer: CSLayer, node: YGNodeRef, references: inout SketchFile
styleJSON["borderBottomColor"] = color
styleJSON["borderLeftColor"] = color
for (_, key) in BORDERS {
if let width = layer.config?.get(attribute: key, for: layer.name).number ?? layer.parameters[key]?.double, width > 0 {
if let width = layer.config?.get(attribute: key, for: layer.name).number ?? layer.parameters[key]?.number, width > 0 {
styleJSON[key] = width.toData()
}
}
@@ -8,7 +8,6 @@
import Foundation
import Cocoa
import SwiftyJSON
import Lottie
typealias ExampleDictionary = [String: CSData]
View
@@ -7,7 +7,6 @@
//
import Cocoa
import SwiftyJSON
class Document: NSDocument {
@@ -90,8 +89,8 @@ class Document: NSDocument {
component = data
}
if let component = component {
return component.toJSONString().data(using: .utf8)!
if let component = component, let json = component.toData(), let data = json.toData() {
return data
}
throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
@@ -112,13 +111,21 @@ class Document: NSDocument {
}
override func read(from data: Data, ofType typeName: String) throws {
// Swift.print("READ")
guard let str = String(data: data, encoding: .utf8) else { return }
// Swift.print("PARSE", str)
let json = JSON(parseJSON: str)
// Swift.print("CSFILE", json)
file = CSComponent(json)
// Swift.print("FILE", file)
guard let json = try? JSONSerialization.jsonObject(with: data) else { return }
// let obj = NSDictionary(dictionary: [
// "paddingTop": 12,
// "paddingBottom": 0,
// "paddingLeft": 1,
// "visible": NSNumber.init(value: false),
// "ok": NSNumber.init(value: true),
// ])
// let test = CSData.from(json: obj)
// Swift.print(test)
file = CSComponent(CSData.from(json: json))
// Insert code here to read your document from the given data of the specified type. If outError != nil, ensure that you create and set an appropriate error when returning false.
// You can also choose to override readFromFileWrapper:ofType:error: or readFromURL:ofType:error: instead.

This file was deleted.

Oops, something went wrong.
@@ -19,7 +19,6 @@ import AppKit
import Foundation
import Cocoa
import SwiftyJSON
class ListView<Element: DataNode>: NSOutlineView, NSOutlineViewDataSource, NSOutlineViewDelegate, NSTextFieldDelegate {
@@ -7,7 +7,6 @@
//
import Foundation
import SwiftyJSON
final class CSCaseEntry: CSDataSerializable, CSDataDeserializable {
var name: String
@@ -7,7 +7,6 @@
//
import Foundation
import SwiftyJSON
class CSComponent: DataNode, NSCopying {
var name: String? = nil
@@ -172,42 +171,32 @@ class CSComponent: DataNode, NSCopying {
return "\(prefix) \(next)"
}
func toJSON() -> Any? {
let data: [String: Any?] = [
"parameters": parameters.toJSON(),
"rootLayer": rootLayer.toJSON(),
"logic": logic.toData().toAny(),
"canvases": canvas.toData().toAny(),
"config": config.toAny(),
"metadata": metadata.toAny(),
"cases": cases.toData().toAny(),
]
return data
func toData() -> CSData? {
return CSData.Object([
"parameters": CSData.Array(parameters.map({ $0.toData() })),
"rootLayer": rootLayer.toData(),
"logic": logic.toData(),
"canvases": canvas.toData(),
"config": config,
"metadata": metadata,
"cases": cases.toData(),
])
}
func toJSONString() -> String {
return JSON(toJSON() as Any).rawString(.utf8, options: .prettyPrinted) ?? ""
}
init(_ json: JSON) {
parameters = json["parameters"].arrayValue.map({ CSParameter($0) })
rootLayer = CSLayer.deserialize(json["rootLayer"])!
logic = json["logic"].arrayValue.map({ LogicNode(CSData.from(json: $0)) })
canvas = json["canvases"].arrayValue.map({ Canvas(CSData.from(json: $0)) })
config = json["config"].dictionary != nil
? CSData.from(json: json["config"])
: CSData.Object([:])
metadata = json["metadata"].dictionary != nil
? CSData.from(json: json["metadata"])
: CSData.Object([:])
cases = json["cases"].arrayValue.map({ CSCase(CSData.from(json: $0)) })
init(_ json: CSData) {
parameters = json.get(key: "parameters").arrayValue.map({ CSParameter($0) })
rootLayer = CSLayer.deserialize(json.get(key: "rootLayer"))!
logic = json.get(key: "logic").arrayValue.map({ LogicNode($0) })
canvas = json.get(key: "canvases").arrayValue.map({ Canvas($0) })
config = json.get(key: "config")
metadata = json.get(key: "metadata")
cases = json.get(key: "cases").arrayValue.map({ CSCase($0) })
}
convenience init?(url: URL) {
guard let data = try? Data(contentsOf: url, options: NSData.ReadingOptions()) else { return nil }
guard let str = String(data: data, encoding: .utf8) else { return nil }
let json = JSON(parseJSON: str)
self.init(json)
guard let json = try? JSONSerialization.jsonObject(with: data) else { return nil }
self.init(CSData.from(json: json))
}
}
@@ -7,7 +7,6 @@
//
import Foundation
import SwiftyJSON
class CSComponentLayer: CSLayer {
var url: String?
@@ -32,8 +31,7 @@ class CSComponentLayer: CSLayer {
let parametersMap: [String: CSData] = component.parameters.key {
(parameter) -> (key: String, value: CSData) in
let value = CSData.from(json: parameters[parameter.name] ?? JSON.null)
return (key: parameter.name, value: value)
return (key: parameter.name, value: parameters[parameter.name] ?? CSData.Null)
}
return CSValue(type: CSType.dictionary(parametersSchema), data: CSData.Object(parametersMap))
@@ -52,10 +50,10 @@ class CSComponentLayer: CSLayer {
return component
}
required init(_ json: JSON) {
required init(_ json: CSData) {
super.init(json)
let url = json["url"].stringValue
let url = json.get(key: "url").stringValue
if url.hasPrefix("./") {
self.url = URL(fileURLWithPath: url, relativeTo: CSWorkspacePreferences.workspaceURL).absoluteString
@@ -66,15 +64,15 @@ class CSComponentLayer: CSLayer {
reload()
}
init(name: String, url: String, parameters: [String: JSON] = [:], children: [CSLayer] = []) {
init(name: String, url: String, parameters: [String: CSData] = [:], children: [CSLayer] = []) {
self.url = url
super.init(name: name, type: "Component", parameters: parameters, children: children)
reload()
}
override func toJSON() -> Any? {
var data = super.toJSON() as! [String : Any?]
override func toData() -> CSData {
var data = super.toData()
guard let absolutePathWithProtocol = url else { return data }
guard let absolutePath = URL(string: absolutePathWithProtocol)?.path else { return data }
@@ -86,7 +84,7 @@ class CSComponentLayer: CSLayer {
// Swift.print("base path", basePath)
// Swift.print("relative path", relativePath)
data["url"] = relativePath
data["url"] = relativePath?.toData()
return data
}
Oops, something went wrong.

0 comments on commit d31eb1e

Please sign in to comment.