forked from Charimon/iosViews
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_as_dict.sketchplugin
37 lines (31 loc) · 1.23 KB
/
export_as_dict.sketchplugin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// (ctrl alt cmd d)
//doc, selection, scriptPath
#import 'lib/common.js'
main()
function main() {
var loop = selection.objectEnumerator()
var str = ""
while(item = loop.nextObject()) {
str += processSelection(item, item.frame(), 0, 0)
}
paste(str)
}
function processSelection(layer, boundingFrame, offsetX, offsetY) {
if(!layer.isVisible()) return ""
var str = "let {{0}}Map = [".format(safeName(layer))
var kvPairs = []
var views = []
forEach(layer.layers(), function(item, i){if(item.isVisible()) {
if(isShape(item)) {
var frame = item.frame()
//kvPairs.push("\"{{0}}\":NSValue(CGRect: CGRect(x:{{1}}, y:{{2}}, width:{{3}}, height:{{4}}))".format(safeName(item), frame.x(), frame.y(), frame.width(), frame.height()))
kvPairs.push("\"{{0}}\":({{1}},{{2}},{{3}},{{4}})".format( safeName(item), frame.x(), frame.y(), frame.width(), frame.height() ))
views.push("\"{{0}}\"".format(safeName(item)))
}
}})
str += kvPairs.join(",\n") + "]\n"
str += "let {{0}}Keys = [{{1}}]\n".format(safeName(item), views.join(", "))
str += "let {{0}}Width = {{1}}\n".format(safeName(item), layer.frame().width())
str += "let {{0}}Height = {{1}}\n".format(safeName(item), layer.frame().height())
return str
}