Fix code style issues

This commit is contained in:
Tyler Long
2017-04-13 20:50:22 +08:00
parent a2ce9e6a54
commit ab398c64a8
7 changed files with 269 additions and 268 deletions

View File

@@ -6,13 +6,13 @@
* https://github.com/filamentgroup/grunticon
*/
phantom.onError = function (msg, trace) {
window.phantom.onError = function (msg, trace) {
var msgStack = ['PHANTOM ERROR: ' + msg]
if (trace && trace.length) {
msgStack.push('TRACE:')
trace.forEach(function (t) {
msgStack.push(
' -> ' +
' -> ' +
(t.file || t.sourceURL) +
': ' +
t.line +
@@ -21,32 +21,32 @@ phantom.onError = function (msg, trace) {
})
}
system.stderr.write(msgStack.join('\n'))
phantom.exit(1)
window.phantom.exit(1)
}
var system = require('system'),
fs = require('fs'),
webpage = require('webpage')
var system = require('system')
var fs = require('fs')
var webpage = require('webpage')
var page = webpage.create(),
files = system.args.slice(10, system.args.length),
width = system.args[8]
var page = webpage.create()
var files = system.args.slice(10, system.args.length)
var width = system.args[8]
if (typeof width === 'undefined' || width === 'undefined') {
width = 1200
}
var options = {
outputDir: system.args[1],
png: system.args[2] === 'true',
svg: system.args[3] === 'true',
css: fs.read(system.args[4]),
sequenceConfig: system.args[5] !== 'null' ? JSON.parse(fs.read(system.args[5])) : {},
ganttConfig: system.args[6] !== 'null' ? JSON.parse(fs.read(system.args[6])) : {},
verbose: system.args[7] === 'true',
width: width,
outputSuffix: system.args[9]
},
log = logger(options.verbose)
outputDir: system.args[1],
png: system.args[2] === 'true',
svg: system.args[3] === 'true',
css: fs.read(system.args[4]),
sequenceConfig: system.args[5] !== 'null' ? JSON.parse(fs.read(system.args[5])) : {},
ganttConfig: system.args[6] !== 'null' ? JSON.parse(fs.read(system.args[6])) : {},
verbose: system.args[7] === 'true',
width: width,
outputSuffix: system.args[9]
}
var log = logger(options.verbose)
options.sequenceConfig.useMaxWidth = false
page.content = [
@@ -69,12 +69,12 @@ page.onConsoleMessage = function (msg, lineNum, sourceId) {
console.log('Num files to execute : ' + files.length)
files.forEach(function (file) {
var contents = fs.read(file),
filename = file.split(fs.separator).slice(-1),
oParser = new DOMParser(),
oDOM,
svgContent,
allElements
var contents = fs.read(file)
var filename = file.split(fs.separator).slice(-1)
var oParser = new window.DOMParser()
var oDOM
var svgContent
var allElements
console.log('ready to execute png: ' + filename + '.png ')
@@ -112,7 +112,7 @@ files.forEach(function (file) {
}
if (options.svg) {
var serialize = new XMLSerializer()
var serialize = new window.XMLSerializer()
fs.write(outputPath + '.svg'
, serialize.serializeToString(oDOM) + '\n'
, 'w'
@@ -121,15 +121,15 @@ files.forEach(function (file) {
}
})
phantom.exit()
window.phantom.exit()
function logger (_verbose) {
var verbose = _verbose
return function (_message, _level) {
var level = level,
message = _message,
log
var level = _level
var message = _message
var log
log = level === 'error' ? system.stderr : system.stdout
@@ -149,7 +149,7 @@ function traverse (obj) {
if (node && node.hasChildNodes()) {
var child = node.firstChild
while (child) {
if (child.nodeType === 1 && child.nodeName != 'SCRIPT') {
if (child.nodeType === 1 && child.nodeName !== 'SCRIPT') {
tree.push(child)
visit(child)
}
@@ -163,13 +163,13 @@ function traverse (obj) {
function resolveSVGElement (element) {
var prefix = {
xmlns: 'http://www.w3.org/2000/xmlns/',
xlink: 'http://www.w3.org/1999/xlink',
svg: 'http://www.w3.org/2000/svg'
},
doctype = '<!DOCTYPE svg:svg PUBLIC' +
' "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"' +
' "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">'
xmlns: 'http://www.w3.org/2000/xmlns/',
xlink: 'http://www.w3.org/1999/xlink',
svg: 'http://www.w3.org/2000/svg'
}
// var doctype = '<!DOCTYPE svg:svg PUBLIC' +
// ' "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"' +
// ' "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">'
element.setAttribute('version', '1.1')
// removing attributes so they aren't doubled up
@@ -187,48 +187,48 @@ function resolveSVGElement (element) {
function setSVGStyle (svg, css) {
if (!css || !svg) { return }
var styles = svg.getElementsByTagName('style')
if (!styles || styles.length == 0) { return }
if (!styles || styles.length === 0) { return }
styles[0].textContent = css
}
function resolveForeignObjects (element) {
return
var children,
textElement,
textSpan
// return
// var children
// var textElement
// var textSpan
if (element.tagName === 'foreignObject') {
textElement = document.createElement('text')
textSpan = document.createElement('tspan')
textSpan.setAttribute(
'style'
, 'font-size: 11.5pt; font-family: "sans-serif";'
)
textSpan.setAttribute('x', 0)
textSpan.setAttribute('y', 14.5)
textSpan.textContent = element.textContent
// if (element.tagName === 'foreignObject') {
// textElement = document.createElement('text')
// textSpan = document.createElement('tspan')
// textSpan.setAttribute(
// 'style'
// , 'font-size: 11.5pt; font-family: "sans-serif";'
// )
// textSpan.setAttribute('x', 0)
// textSpan.setAttribute('y', 14.5)
// textSpan.textContent = element.textContent
textElement.appendChild(textSpan)
element.parentElement.appendChild(textElement)
element.parentElement.removeChild(element)
}
// textElement.appendChild(textSpan)
// element.parentElement.appendChild(textElement)
// element.parentElement.removeChild(element)
// }
}
// The sandboxed function that's executed in-page by phantom
function executeInPage (data) {
var xmlSerializer = new XMLSerializer(),
contents = data.contents,
sequenceConfig = JSON.stringify(data.sequenceConfig),
ganttConfig = JSON.stringify(data.ganttConfig).replace(/"(function.*})"/, '$1'),
toRemove,
el,
elContent,
svg,
svgValue,
boundingBox,
width,
height,
confWidth = data.confWidth
var xmlSerializer = new window.XMLSerializer()
var contents = data.contents
var sequenceConfig = JSON.stringify(data.sequenceConfig)
var ganttConfig = JSON.stringify(data.ganttConfig).replace(/"(function.*})"/, '$1')
// var toRemove
// var el
// var elContent
var svg
var svgValue
var boundingBox
var width
var height
var confWidth = data.confWidth
var toRemove = document.getElementsByClassName('mermaid')
if (toRemove && toRemove.length) {
@@ -244,17 +244,17 @@ function executeInPage (data) {
var config = {
sequenceDiagram: JSON.parse(sequenceConfig),
flowchart: {useMaxWidth: false},
flowchart: { useMaxWidth: false },
logLevel: 1
}
mermaid.initialize(config)
window.mermaid.initialize(config)
var sc = document.createElement('script')
sc.appendChild(document.createTextNode('mermaid.ganttConfig = ' + ganttConfig + ';'))
document.body.appendChild(sc)
mermaid.init()
window.mermaid.init()
svg = document.querySelector('svg')