Add new parameter to the console client to override the svg configuration in sequence diagrams

This commit is contained in:
jjmr
2015-01-13 16:17:30 +01:00
parent 0b2afb8e71
commit 9b892ef128
8 changed files with 136 additions and 1101 deletions

View File

@@ -29,12 +29,13 @@ var system = require('system')
, webpage = require('webpage')
var page = webpage.create()
, files = phantom.args.slice(4, phantom.args.length)
, files = phantom.args.slice(5, phantom.args.length)
, options = {
outputDir: phantom.args[0]
, png: phantom.args[1] === 'true' ? true : false
, svg: phantom.args[2] === 'true' ? true : false
, verbose: phantom.args[3] === 'true' ? true : false
, sequenceConfig: phantom.args[3]
, verbose: phantom.args[4] === 'true' ? true : false
}
, log = logger(options.verbose)
@@ -51,7 +52,9 @@ page.content = [
].join('\n')
page.injectJs('../dist/mermaid.full.js')
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
files.forEach(function(file) {
var contents = fs.read(file)
, filename = file.split(fs.separator).slice(-1)
@@ -63,7 +66,10 @@ files.forEach(function(file) {
// this JS is executed in this statement is sandboxed, even though it doesn't
// look like it. we need to serialize then unserialize the svgContent that's
// taken from the DOM
svgContent = page.evaluate(executeInPage, contents)
svgContent = page.evaluate(executeInPage, {
contents: contents,
sequenceConfig: options.sequenceConfig
})
oDOM = oParser.parseFromString(svgContent, "text/xml")
resolveSVGElement(oDOM.firstChild)
@@ -182,8 +188,10 @@ function resolveForeignObjects(element) {
}
// The sandboxed function that's executed in-page by phantom
function executeInPage(contents) {
function executeInPage(data) {
var xmlSerializer = new XMLSerializer()
, contents = data.contents
, sequenceConfig = data.sequenceConfig
, toRemove
, el
, elContent
@@ -204,7 +212,7 @@ function executeInPage(contents) {
document.body.appendChild(el)
mermaid.init()
mermaid.init(sequenceConfig)
svg = document.querySelector('svg')
svgValue = xmlSerializer.serializeToString(svg)