Merge branch 'sequence_config_file' of https://github.com/jjmr/mermaid into jjmr-sequence_config_file
Conflicts: dist/mermaid.full.js dist/mermaid.full.min.js dist/mermaid.slim.js dist/mermaid.slim.min.js src/main.js
This commit is contained in:
commit
73f567f3e2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
32
lib/cli.js
32
lib/cli.js
|
@ -23,6 +23,7 @@ function cli(options) {
|
||||||
, svg: 's'
|
, svg: 's'
|
||||||
, verbose: 'v'
|
, verbose: 'v'
|
||||||
, phantomPath: 'e'
|
, phantomPath: 'e'
|
||||||
|
, sequenceConfig: 'c'
|
||||||
}
|
}
|
||||||
, 'boolean': ['help', 'png', 'svg']
|
, 'boolean': ['help', 'png', 'svg']
|
||||||
, 'string': ['outputDir']
|
, 'string': ['outputDir']
|
||||||
|
@ -37,13 +38,14 @@ function cli(options) {
|
||||||
, "file The mermaid description file to be rendered"
|
, "file The mermaid description file to be rendered"
|
||||||
, ""
|
, ""
|
||||||
, "Options:"
|
, "Options:"
|
||||||
, " -s --svg Output SVG instead of PNG (experimental)"
|
, " -s --svg Output SVG instead of PNG (experimental)"
|
||||||
, " -p --png If SVG was selected, and you also want PNG, set this flag"
|
, " -p --png If SVG was selected, and you also want PNG, set this flag"
|
||||||
, " -o --outputDir Directory to save files, will be created automatically, defaults to `cwd`"
|
, " -o --outputDir Directory to save files, will be created automatically, defaults to `cwd`"
|
||||||
, " -e --phantomPath Specify the path to the phantomjs executable"
|
, " -e --phantomPath Specify the path to the phantomjs executable"
|
||||||
, " -h --help Show this message"
|
, " -c --sequenceConfig Specify the path to the file with the configuration to be applied in the sequence diagram"
|
||||||
, " -v --verbose Show logging"
|
, " -h --help Show this message"
|
||||||
, " --version Print version and quit"
|
, " -v --verbose Show logging"
|
||||||
|
, " --version Print version and quit"
|
||||||
]
|
]
|
||||||
|
|
||||||
return this
|
return this
|
||||||
|
@ -70,7 +72,7 @@ cli.prototype.parse = function(argv, next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure that parameter-expecting options have parameters
|
// ensure that parameter-expecting options have parameters
|
||||||
;['outputDir', 'phantomPath'].forEach(function(i) {
|
;['outputDir', 'phantomPath', 'sequenceConfig'].forEach(function(i) {
|
||||||
if(typeof options[i] !== 'undefined') {
|
if(typeof options[i] !== 'undefined') {
|
||||||
if (typeof options[i] !== 'string' || options[i].length < 1) {
|
if (typeof options[i] !== 'string' || options[i].length < 1) {
|
||||||
this.errors.push(new Error(i + " expects a value."))
|
this.errors.push(new Error(i + " expects a value."))
|
||||||
|
@ -86,6 +88,10 @@ cli.prototype.parse = function(argv, next) {
|
||||||
options.png = true
|
options.png = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.sequenceConfig) {
|
||||||
|
options.sequenceConfig = checkConfig(options.sequenceConfig)
|
||||||
|
}
|
||||||
|
|
||||||
this.checkPhantom = createCheckPhantom(options.phantomPath)
|
this.checkPhantom = createCheckPhantom(options.phantomPath)
|
||||||
|
|
||||||
this.checkPhantom(function(err, path) {
|
this.checkPhantom(function(err, path) {
|
||||||
|
@ -102,6 +108,16 @@ cli.prototype.parse = function(argv, next) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkConfig(configPath) {
|
||||||
|
try {
|
||||||
|
var text = fs.readFileSync(configPath, 'utf8')
|
||||||
|
JSON.parse(text)
|
||||||
|
return text
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createCheckPhantom(_phantomPath) {
|
function createCheckPhantom(_phantomPath) {
|
||||||
var phantomPath = _phantomPath
|
var phantomPath = _phantomPath
|
||||||
, phantomVersion
|
, phantomVersion
|
||||||
|
|
|
@ -18,6 +18,7 @@ function processMermaid(files, _options, _next) {
|
||||||
, outputDir
|
, outputDir
|
||||||
, options.png
|
, options.png
|
||||||
, options.svg
|
, options.svg
|
||||||
|
, options.sequenceConfig
|
||||||
, options.verbose
|
, options.verbose
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -29,12 +29,13 @@ var system = require('system')
|
||||||
, webpage = require('webpage')
|
, webpage = require('webpage')
|
||||||
|
|
||||||
var page = webpage.create()
|
var page = webpage.create()
|
||||||
, files = phantom.args.slice(4, phantom.args.length)
|
, files = phantom.args.slice(5, phantom.args.length)
|
||||||
, options = {
|
, options = {
|
||||||
outputDir: phantom.args[0]
|
outputDir: phantom.args[0]
|
||||||
, png: phantom.args[1] === 'true' ? true : false
|
, png: phantom.args[1] === 'true' ? true : false
|
||||||
, svg: phantom.args[2] === '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)
|
, log = logger(options.verbose)
|
||||||
|
|
||||||
|
@ -51,7 +52,9 @@ page.content = [
|
||||||
].join('\n')
|
].join('\n')
|
||||||
|
|
||||||
page.injectJs('../dist/mermaid.full.js')
|
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) {
|
files.forEach(function(file) {
|
||||||
var contents = fs.read(file)
|
var contents = fs.read(file)
|
||||||
, filename = file.split(fs.separator).slice(-1)
|
, 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
|
// 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
|
// look like it. we need to serialize then unserialize the svgContent that's
|
||||||
// taken from the DOM
|
// taken from the DOM
|
||||||
svgContent = page.evaluate(executeInPage, contents)
|
svgContent = page.evaluate(executeInPage, {
|
||||||
|
contents: contents,
|
||||||
|
sequenceConfig: options.sequenceConfig
|
||||||
|
})
|
||||||
oDOM = oParser.parseFromString(svgContent, "text/xml")
|
oDOM = oParser.parseFromString(svgContent, "text/xml")
|
||||||
|
|
||||||
resolveSVGElement(oDOM.firstChild)
|
resolveSVGElement(oDOM.firstChild)
|
||||||
|
@ -182,8 +188,10 @@ function resolveForeignObjects(element) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// The sandboxed function that's executed in-page by phantom
|
// The sandboxed function that's executed in-page by phantom
|
||||||
function executeInPage(contents) {
|
function executeInPage(data) {
|
||||||
var xmlSerializer = new XMLSerializer()
|
var xmlSerializer = new XMLSerializer()
|
||||||
|
, contents = data.contents
|
||||||
|
, sequenceConfig = data.sequenceConfig
|
||||||
, toRemove
|
, toRemove
|
||||||
, el
|
, el
|
||||||
, elContent
|
, elContent
|
||||||
|
@ -204,7 +212,7 @@ function executeInPage(contents) {
|
||||||
|
|
||||||
document.body.appendChild(el)
|
document.body.appendChild(el)
|
||||||
|
|
||||||
mermaid.init()
|
mermaid.init(sequenceConfig)
|
||||||
|
|
||||||
svg = document.querySelector('svg')
|
svg = document.querySelector('svg')
|
||||||
svgValue = xmlSerializer.serializeToString(svg)
|
svgValue = xmlSerializer.serializeToString(svg)
|
||||||
|
|
10
src/main.js
10
src/main.js
|
@ -18,10 +18,14 @@ var he = require('he');
|
||||||
* c-->|No |d(Transform);
|
* c-->|No |d(Transform);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
var init = function () {
|
var init = function (sequenceConfig) {
|
||||||
var arr = document.querySelectorAll('.mermaid');
|
var arr = document.querySelectorAll('.mermaid');
|
||||||
var i;
|
var i;
|
||||||
|
|
||||||
|
if (sequenceConfig) {
|
||||||
|
seq.setConf(JSON.parse(sequenceConfig));
|
||||||
|
}
|
||||||
|
|
||||||
var cnt = 0;
|
var cnt = 0;
|
||||||
for (i = 0; i < arr.length; i++) {
|
for (i = 0; i < arr.length; i++) {
|
||||||
var element = arr[i];
|
var element = arr[i];
|
||||||
|
@ -95,8 +99,8 @@ var equals = function (val, variable){
|
||||||
global.mermaid = {
|
global.mermaid = {
|
||||||
startOnLoad:true,
|
startOnLoad:true,
|
||||||
htmlLabels:true,
|
htmlLabels:true,
|
||||||
init:function(){
|
init:function(sequenceConfig){
|
||||||
init();
|
init(sequenceConfig);
|
||||||
},
|
},
|
||||||
version:function(){
|
version:function(){
|
||||||
return exports.version();
|
return exports.version();
|
||||||
|
|
Loading…
Reference in New Issue