Skip to content

Commit

Permalink
Fix code style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerlong committed Apr 13, 2017
1 parent a2ce9e6 commit ab398c6
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 272 deletions.
42 changes: 21 additions & 21 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
var fs = require('fs'),
exec = require('child_process').exec,
chalk = require('chalk'),
which = require('which'),
parseArgs = require('minimist'),
semver = require('semver'),
path = require('path')
var fs = require('fs')
var exec = require('child_process').exec
var chalk = require('chalk')
var which = require('which')
var parseArgs = require('minimist')
var semver = require('semver')
var path = require('path')

var PHANTOM_VERSION = '^2.1.0'

var info = chalk.blue.bold,
note = chalk.green.bold
var info = chalk.blue.bold
// var note = chalk.green.bold

module.exports = (function () {
return new cli()
return new Cli()
}())

function cli (options) {
function Cli (options) {
this.options = {
alias: {
help: 'h',
Expand All @@ -37,7 +37,7 @@ function cli (options) {
this.errors = []
this.message = null

this.helpMessage = [,
this.helpMessage = [
info('Usage: mermaid [options] <file>...'),
'',
'file The mermaid description file to be rendered',
Expand All @@ -60,10 +60,10 @@ function cli (options) {
return this
}

cli.prototype.parse = function (argv, next) {
Cli.prototype.parse = function (argv, next) {
this.errors = [] // clear errors
var options = parseArgs(argv, this.options),
phantom
var options = parseArgs(argv, this.options)
// var phantom

if (options.version) {
var pkg = require('../package.json')
Expand Down Expand Up @@ -138,7 +138,7 @@ cli.prototype.parse = function (argv, next) {
}
options.phantomPath = path
next(
this.errors.length > 0 ? this.errors : null
this.errors.length > 0 ? this.errors : null
, this.message
, options
)
Expand All @@ -147,12 +147,12 @@ cli.prototype.parse = function (argv, next) {
}

function createCheckPhantom (_phantomPath) {
var phantomPath = _phantomPath,
phantomVersion
var phantomPath = _phantomPath
// var phantomVersion

return function checkPhantom (_next) {
var next = _next || function () {},
err
var next = _next || function () { }
var err

if (typeof phantomPath === 'undefined') {
try {
Expand Down Expand Up @@ -186,7 +186,7 @@ function createCheckPhantom (_phantomPath) {
next(new Error('Could not find phantomjs at the specified path.'))
} else if (!semver.satisfies(stdout, PHANTOM_VERSION)) {
next(new Error(
'mermaid requires phantomjs ' +
'mermaid requires phantomjs ' +
PHANTOM_VERSION +
' to be installed, found version ' +
stdout
Expand Down
42 changes: 21 additions & 21 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var os = require('os'),
fs = require('fs'),
path = require('path'),
spawn = require('child_process').spawn
// var os = require('os')
// var fs = require('fs')
var path = require('path')
var spawn = require('child_process').spawn

var mkdirp = require('mkdirp')

Expand All @@ -10,22 +10,22 @@ var phantomscript = path.join(__dirname, 'phantomscript.js')
module.exports = { process: processMermaid }

function processMermaid (files, _options, _next) {
var options = _options || {},
outputDir = options.outputDir || process.cwd(),
outputSuffix = options.outputSuffix || '',
next = _next || function () {},
phantomArgs = [
phantomscript,
outputDir,
options.png,
options.svg,
options.css,
options.sequenceConfig,
options.ganttConfig,
options.verbose,
options.width,
outputSuffix
]
var options = _options || {}
var outputDir = options.outputDir || process.cwd()
var outputSuffix = options.outputSuffix || ''
var next = _next || function () { }
var phantomArgs = [
phantomscript,
outputDir,
options.png,
options.svg,
options.css,
options.sequenceConfig,
options.ganttConfig,
options.verbose,
options.width,
outputSuffix
]

files.forEach(function (file) {
phantomArgs.push(file)
Expand All @@ -35,7 +35,7 @@ function processMermaid (files, _options, _next) {
if (err) {
throw err
}
phantom = spawn(options.phantomPath, phantomArgs)
var phantom = spawn(options.phantomPath, phantomArgs)

phantom.on('exit', next)

Expand Down
152 changes: 76 additions & 76 deletions lib/phantomscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand All @@ -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 = [
Expand All @@ -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 ')

Expand Down Expand Up @@ -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'
Expand All @@ -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

Expand All @@ -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)
}
Expand All @@ -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
Expand All @@ -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

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)
}
// 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

// 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) {
Expand All @@ -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')

Expand Down
Loading

0 comments on commit ab398c6

Please sign in to comment.