Skip to content

Commit

Permalink
Merge pull request #34 from griffin-stewie/feat/add_sketch_measure_js…
Browse files Browse the repository at this point in the history
…on_support

Add Sketch Measure JSON import JSON support.
  • Loading branch information
Adrxx authored Aug 1, 2018
2 parents abf6cd1 + 209b990 commit 4a75f36
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 2 deletions.
1 change: 1 addition & 0 deletions Prism.sketchplugin/Contents/Sketch/build/ColorFormatter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 57 additions & 1 deletion Prism.sketchplugin/Contents/Sketch/build/Formats.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Prism.sketchplugin/Contents/Sketch/build/FormatterBase.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class ColorFormatter
@FORMATS.push new UIColorObjCFormatter()
@FORMATS.push new AndroidJavaFormatter()
@FORMATS.push new AndroidXMLFormatter()
@FORMATS.push new SketchMeasureFormatter()

for format in @FORMATS
@FORMATS_BY_ID[format.id()] = format
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

class SketchMeasureFormatter extends FormatterBase
# Sketch Measure - Make it a fun to create spec for developers and teammates http://utom.design/measure/
id: ->
"SKETCHMESURE_JSON"
name: ->
"Sketch Measure (JSON)"
format: ->
"colors.json"

supportClipboard: ->
true

exportAsString: (colorDictionaries) ->
root = []
for colorDictionary in colorDictionaries
log colorDictionary
obj =
"name": "#{colorDictionary.name.trim()}"
"color": @colorToDictionaryToJSON(colorDictionary)
root.push obj

JSON.stringify(root, undefined, 4)

colorToDictionaryToJSON: (colorDictionary) ->
json =
r: Math.round(colorDictionary.red * 255)
g: Math.round(colorDictionary.green * 255)
b: Math.round(colorDictionary.blue * 255)
a: (Math.round(colorDictionary.alpha * 100) / 100)
"color-hex": "\##{colorDictionary.hex} " + "#{Math.round(colorDictionary.alpha * 100)}%",
"argb-hex": "\##{helperHex(colorDictionary.alpha * 255) + colorDictionary.hex}",
"css-rgba": "rgba(#{Math.round(colorDictionary.red * 255)},#{Math.round(colorDictionary.green * 255)},#{Math.round(colorDictionary.blue * 255)},#{Math.round(colorDictionary.alpha * 100) / 100})"
"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)})"

0 comments on commit 4a75f36

Please sign in to comment.