-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for exporting colors from variables (#236)
* Add VariablesEndpoint Add Variables models * Add new VariablesColors params * Add raw ColorsVariablesLoader Update ExportColors Update params name Update params name Small refactoring Small refactoring Add doc Refactoring Refactoring * Update doc * Filter support * Simplified handleColorMode method * Small refactoring * Update after review
- Loading branch information
1 parent
90ef6b7
commit d667c99
Showing
10 changed files
with
426 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Foundation | ||
#if os(Linux) | ||
import FoundationNetworking | ||
#endif | ||
|
||
public struct VariablesEndpoint: BaseEndpoint { | ||
public typealias Content = VariablesMeta | ||
|
||
private let fileId: String | ||
|
||
public init(fileId: String) { | ||
self.fileId = fileId | ||
} | ||
|
||
func content(from root: VariablesResponse) -> Content { | ||
return root.meta | ||
} | ||
|
||
public func makeRequest(baseURL: URL) -> URLRequest { | ||
let url = baseURL | ||
.appendingPathComponent("files") | ||
.appendingPathComponent(fileId) | ||
.appendingPathComponent("variables") | ||
.appendingPathComponent("local") | ||
return URLRequest(url: url) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
public struct Mode: Decodable { | ||
public var modeId: String | ||
public var name: String | ||
} | ||
|
||
public struct VariableCollectionValue: Decodable { | ||
public var defaultModeId: String | ||
public var id: String | ||
public var name: String | ||
public var modes: [Mode] | ||
public var variableIds: [String] | ||
} | ||
|
||
public struct VariableAlias: Codable { | ||
public var id: String | ||
public var type: String | ||
} | ||
|
||
public enum ValuesByMode: Decodable { | ||
case variableAlias(VariableAlias) | ||
case color(PaintColor) | ||
case string(String) | ||
case number(Double) | ||
case boolean(Bool) | ||
|
||
public enum CodingKeys: CodingKey { | ||
case variableAlias | ||
case color | ||
case string | ||
case number | ||
case boolean | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
if let variableAlias = try? VariableAlias(from: decoder) { | ||
self = .variableAlias(variableAlias) | ||
} else if let color = try? PaintColor(from: decoder) { | ||
self = .color(color) | ||
} else if let string = try? String(from: decoder) { | ||
self = .string(string) | ||
} else if let number = try? Double(from: decoder) { | ||
self = .number(number) | ||
} else if let boolean = try? Bool(from: decoder) { | ||
self = .boolean(boolean) | ||
} else { | ||
throw DecodingError.dataCorrupted(DecodingError.Context(codingPath: decoder.codingPath, debugDescription: "Data didn't match any expected type.")) | ||
} | ||
} | ||
} | ||
|
||
public struct VariableValue: Decodable { | ||
public var id: String | ||
public var name: String | ||
public var variableCollectionId: String | ||
public var valuesByMode: [String: ValuesByMode] | ||
public var description: String | ||
} | ||
|
||
public typealias VariableId = String | ||
public typealias VariableCollectionId = String | ||
|
||
public struct VariablesMeta: Decodable { | ||
public var variableCollections: [VariableCollectionId: VariableCollectionValue] | ||
public var variables: [VariableId: VariableValue] | ||
} | ||
|
||
public struct VariablesResponse: Decodable { | ||
public let meta: VariablesMeta | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.