Skip to content

Commit 824d002

Browse files
author
Max Bazarov
committed
3.4.0
1 parent a07f5b3 commit 824d002

14 files changed

Lines changed: 2472 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
@import("constants.js")
2+
@import("lib/utils.js")
3+
4+
5+
class ChildFinder {
6+
constructor() {
7+
}
8+
9+
// find overrided layer by customPropery path
10+
findChildInPath(prefix, l, path, index) {
11+
let foundLayer = undefined
12+
let seekId = path[index]
13+
const lastIndex = path.length - 1
14+
15+
// if start from current layer itself?
16+
if (seekId == l.objectID) {
17+
seekId = path[++index]
18+
}
19+
20+
for (var layer of l.childs) {
21+
exporter.log(prefix + "scan layer.id=" + layer.objectID + " seekID=" + seekId)
22+
if (layer.objectID == seekId || layer.originalID == seekId) {
23+
exporter.log(prefix + "found!")
24+
if (index == lastIndex) {
25+
foundLayer = layer
26+
exporter.log(prefix + "found last")
27+
return foundLayer
28+
}
29+
foundLayer = this.findChildInPath(prefix + " ", layer, path, index + 1)
30+
return foundLayer
31+
}
32+
}
33+
34+
// failed to found. time to use deep nested search
35+
for (var layer of l.childs) {
36+
foundLayer = this.findChildInPath(prefix + " ", layer, path, index)
37+
if (foundLayer) return foundLayer
38+
}
39+
40+
return undefined
41+
}
42+
43+
// find child layer by ID
44+
findChildByID(l, id, recursive=true) {
45+
for (var layer of l.childs) {
46+
if (layer.objectID == id) {
47+
return layer
48+
}
49+
if (recursive && layer.childs.length > 0) {
50+
const foundLayer = this.findChildByID(layer, id, true)
51+
if (foundLayer != undefined) return foundLayer
52+
}
53+
}
54+
55+
return undefined
56+
}
57+
58+
}

Exporter.sketchplugin/Contents/Sketch/exporter/exporter-build-html.js

Lines changed: 144 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@import "constants.js"
2+
@import "exporter/exporter.js"
3+
@import "lib/utils.js"
4+
5+
6+
function runExporter(context,exportOptions=null) {
7+
8+
const Dom = require('sketch/dom')
9+
const doc = context.document
10+
const Doc = Dom.fromNative(doc)
11+
const Settings = require('sketch/settings')
12+
let UI = require('sketch/ui')
13+
14+
// check is something to export
15+
/*if (exportOptions==null && doc.currentPage().artboards().count() === 0) {
16+
UI.alert("There are no artboards to export.");
17+
return;
18+
}*/
19+
20+
// ask for output path
21+
let currentPath = Settings.documentSettingForKey(doc,SettingKeys.DOC_EXPORTING_URL)
22+
if(currentPath==null){
23+
currentPath = ""
24+
}
25+
const newPath = Utils.askSavePath(currentPath)
26+
if (newPath == null) {
27+
return
28+
}
29+
Settings.setDocumentSettingForKey(doc,SettingKeys.DOC_EXPORTING_URL,newPath)
30+
31+
// export HTML
32+
new Exporter(newPath, doc, doc.currentPage(), exportOptions, context);
33+
exporter.exportArtboards();
34+
35+
36+
// open HTML in browser
37+
const dontOpenBrowser = Settings.settingForKey(SettingKeys.PLUGIN_DONT_OPEN_BROWSER)==1
38+
if(!dontOpenBrowser){
39+
const openPath = newPath+"/"+exporter.docName+"/"
40+
const openResult = Utils.runCommand('/usr/bin/open', [openPath,openPath+'/index.html'])
41+
42+
if(openResult.result){
43+
}else{
44+
UI.alert('Can not open HTML in browser', openResult.output)
45+
}
46+
}
47+
48+
};

0 commit comments

Comments
 (0)