-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Max Bazarov
committed
Nov 13, 2018
1 parent
a07f5b3
commit 824d002
Showing
14 changed files
with
2,472 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
Exporter.sketchplugin/Contents/Sketch/exporter/child-finder.js
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,58 @@ | ||
@import("constants.js") | ||
@import("lib/utils.js") | ||
|
||
|
||
class ChildFinder { | ||
constructor() { | ||
} | ||
|
||
// find overrided layer by customPropery path | ||
findChildInPath(prefix, l, path, index) { | ||
let foundLayer = undefined | ||
let seekId = path[index] | ||
const lastIndex = path.length - 1 | ||
|
||
// if start from current layer itself? | ||
if (seekId == l.objectID) { | ||
seekId = path[++index] | ||
} | ||
|
||
for (var layer of l.childs) { | ||
exporter.log(prefix + "scan layer.id=" + layer.objectID + " seekID=" + seekId) | ||
if (layer.objectID == seekId || layer.originalID == seekId) { | ||
exporter.log(prefix + "found!") | ||
if (index == lastIndex) { | ||
foundLayer = layer | ||
exporter.log(prefix + "found last") | ||
return foundLayer | ||
} | ||
foundLayer = this.findChildInPath(prefix + " ", layer, path, index + 1) | ||
return foundLayer | ||
} | ||
} | ||
|
||
// failed to found. time to use deep nested search | ||
for (var layer of l.childs) { | ||
foundLayer = this.findChildInPath(prefix + " ", layer, path, index) | ||
if (foundLayer) return foundLayer | ||
} | ||
|
||
return undefined | ||
} | ||
|
||
// find child layer by ID | ||
findChildByID(l, id, recursive=true) { | ||
for (var layer of l.childs) { | ||
if (layer.objectID == id) { | ||
return layer | ||
} | ||
if (recursive && layer.childs.length > 0) { | ||
const foundLayer = this.findChildByID(layer, id, true) | ||
if (foundLayer != undefined) return foundLayer | ||
} | ||
} | ||
|
||
return undefined | ||
} | ||
|
||
} |
144 changes: 144 additions & 0 deletions
144
Exporter.sketchplugin/Contents/Sketch/exporter/exporter-build-html.js
Large diffs are not rendered by default.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
Exporter.sketchplugin/Contents/Sketch/exporter/exporter-run.js
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,48 @@ | ||
@import "constants.js" | ||
@import "exporter/exporter.js" | ||
@import "lib/utils.js" | ||
|
||
|
||
function runExporter(context,exportOptions=null) { | ||
|
||
const Dom = require('sketch/dom') | ||
const doc = context.document | ||
const Doc = Dom.fromNative(doc) | ||
const Settings = require('sketch/settings') | ||
let UI = require('sketch/ui') | ||
|
||
// check is something to export | ||
/*if (exportOptions==null && doc.currentPage().artboards().count() === 0) { | ||
UI.alert("There are no artboards to export."); | ||
return; | ||
}*/ | ||
|
||
// ask for output path | ||
let currentPath = Settings.documentSettingForKey(doc,SettingKeys.DOC_EXPORTING_URL) | ||
if(currentPath==null){ | ||
currentPath = "" | ||
} | ||
const newPath = Utils.askSavePath(currentPath) | ||
if (newPath == null) { | ||
return | ||
} | ||
Settings.setDocumentSettingForKey(doc,SettingKeys.DOC_EXPORTING_URL,newPath) | ||
|
||
// export HTML | ||
new Exporter(newPath, doc, doc.currentPage(), exportOptions, context); | ||
exporter.exportArtboards(); | ||
|
||
|
||
// open HTML in browser | ||
const dontOpenBrowser = Settings.settingForKey(SettingKeys.PLUGIN_DONT_OPEN_BROWSER)==1 | ||
if(!dontOpenBrowser){ | ||
const openPath = newPath+"/"+exporter.docName+"/" | ||
const openResult = Utils.runCommand('/usr/bin/open', [openPath,openPath+'/index.html']) | ||
|
||
if(openResult.result){ | ||
}else{ | ||
UI.alert('Can not open HTML in browser', openResult.output) | ||
} | ||
} | ||
|
||
}; |
Oops, something went wrong.