Skip to content

Commit

Permalink
3.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Bazarov committed Nov 13, 2018
1 parent a07f5b3 commit 824d002
Show file tree
Hide file tree
Showing 14 changed files with 2,472 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Exporter.sketchplugin/Contents/Sketch/exporter/child-finder.js
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 Exporter.sketchplugin/Contents/Sketch/exporter/exporter-build-html.js

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions Exporter.sketchplugin/Contents/Sketch/exporter/exporter-run.js
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)
}
}

};
Loading

0 comments on commit 824d002

Please sign in to comment.