Skip to content

Commit 4a75f36

Browse files
authored
Merge pull request #34 from griffin-stewie/feat/add_sketch_measure_json_support
Add Sketch Measure JSON import JSON support.
2 parents abf6cd1 + 209b990 commit 4a75f36

File tree

5 files changed

+99
-2
lines changed

5 files changed

+99
-2
lines changed

Prism.sketchplugin/Contents/Sketch/build/ColorFormatter.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Prism.sketchplugin/Contents/Sketch/build/Formats.js

Lines changed: 57 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Prism.sketchplugin/Contents/Sketch/build/FormatterBase.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Prism.sketchplugin/Contents/Sketch/src/ColorFormatter.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ColorFormatter
2727
@FORMATS.push new UIColorObjCFormatter()
2828
@FORMATS.push new AndroidJavaFormatter()
2929
@FORMATS.push new AndroidXMLFormatter()
30+
@FORMATS.push new SketchMeasureFormatter()
3031

3132
for format in @FORMATS
3233
@FORMATS_BY_ID[format.id()] = format
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
class SketchMeasureFormatter extends FormatterBase
3+
# Sketch Measure - Make it a fun to create spec for developers and teammates http://utom.design/measure/
4+
id: ->
5+
"SKETCHMESURE_JSON"
6+
name: ->
7+
"Sketch Measure (JSON)"
8+
format: ->
9+
"colors.json"
10+
11+
supportClipboard: ->
12+
true
13+
14+
exportAsString: (colorDictionaries) ->
15+
root = []
16+
for colorDictionary in colorDictionaries
17+
log colorDictionary
18+
obj =
19+
"name": "#{colorDictionary.name.trim()}"
20+
"color": @colorToDictionaryToJSON(colorDictionary)
21+
root.push obj
22+
23+
JSON.stringify(root, undefined, 4)
24+
25+
colorToDictionaryToJSON: (colorDictionary) ->
26+
json =
27+
r: Math.round(colorDictionary.red * 255)
28+
g: Math.round(colorDictionary.green * 255)
29+
b: Math.round(colorDictionary.blue * 255)
30+
a: (Math.round(colorDictionary.alpha * 100) / 100)
31+
"color-hex": "\##{colorDictionary.hex} " + "#{Math.round(colorDictionary.alpha * 100)}%",
32+
"argb-hex": "\##{helperHex(colorDictionary.alpha * 255) + colorDictionary.hex}",
33+
"css-rgba": "rgba(#{Math.round(colorDictionary.red * 255)},#{Math.round(colorDictionary.green * 255)},#{Math.round(colorDictionary.blue * 255)},#{Math.round(colorDictionary.alpha * 100) / 100})"
34+
"ui-color": "(r:#{parseFloat(colorDictionary.red).toFixed(3)} g:#{parseFloat(colorDictionary.green).toFixed(3)} b:#{parseFloat(colorDictionary.blue).toFixed(3)} a:#{parseFloat(colorDictionary.alpha).toFixed(3)})"
35+

0 commit comments

Comments
 (0)