Skip to content

Commit

Permalink
Adding experimental new grammars
Browse files Browse the repository at this point in the history
  • Loading branch information
knsv committed Dec 4, 2014
1 parent 2a0a2a2 commit 4c564eb
Show file tree
Hide file tree
Showing 10 changed files with 1,673 additions and 145 deletions.
8 changes: 5 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ var tag_version = require('gulp-tag-version');
gulp.task('jison2', function() {
return gulp.src('./src/*.jison')
.pipe(jison({ moduleType: 'amd' }))
.pipe(gulp.dest('./src/'));
.pipe(gulp.dest('./src/parser'));
});

gulp.task('jison', shell.task([
'jison src/parser/flow.jison -o src/parser/flow.js'
'jison src/parser/flow.jison -o src/parser/flow.js',
'jison src/parser/dot.jison -o src/parser/dot.js',
'jison src/parser/js-sequence-diagram.jison -o src/parser/sequenceDiagram.js'
//'source scripts/compileJison.sh'
// 'jison src/parser/flow.jison -o src/parser/flow.js',
]))
]));

gulp.task('jisonSd', shell.task([
//'jison src/parser/flow.jison -o src/parser/flow.js',
Expand Down
11 changes: 10 additions & 1 deletion src/graphDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ var funs = [];
* @param style
*/
exports.addVertex = function (id, text, type, style) {
//console.log('Got node ' + id + ' ' + type + ' ' + text + ' styles: ' + JSON.stringify(style));

if(typeof id === 'undefined'){
return;
}
if(id.trim().length === 0){
return;
}

if (typeof vertices[id] === 'undefined') {
vertices[id] = {id: id, styles: [], classes:[]};
}
Expand All @@ -37,6 +44,7 @@ exports.addVertex = function (id, text, type, style) {
}
}
};

/**
* Function called by parser when a link/edge definition has been found
* @param start
Expand All @@ -45,6 +53,7 @@ exports.addVertex = function (id, text, type, style) {
* @param linktext
*/
exports.addLink = function (start, end, type, linktext) {
//console.log('Got edge', start, end);
var edge = {start: start, end: end, type: undefined, text: ''};
var linktext = type.text;
if (typeof linktext !== 'undefined') {
Expand Down
34 changes: 25 additions & 9 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var graph = require('./graphDb');
var flow = require('./parser/flow');
var dot = require('./parser/dot');
var utils = require('./utils');
var seq = require('./sequenceRenderer');
var he = require('he');
Expand Down Expand Up @@ -141,12 +142,19 @@ exports.addEdges = function (edges, g) {
* @param text
* @param id
*/
var draw = function (text, id) {
var draw = function (text, id,isDot) {
var parser;
graph.clear();
flow.parser.yy = graph;
if(isDot){
parser = dot.parser;

}else{
parser = flow.parser;
}
parser.yy = graph;

// Parse the graph definition
flow.parser.parse(text);
parser.parse(text);

// Fetch the default direction, use TD if none was found
var dir;
Expand Down Expand Up @@ -291,12 +299,19 @@ var init = function () {
'<g />' +
'</svg>';

if(utils.detectType(txt) === 'graph'){
draw(txt, id);
graph.bindFunctions();
}
else{
seq.draw(txt,id);
var graphType = utils.detectType(txt);

switch(graphType){
case 'graph':
draw(txt, id,false);
graph.bindFunctions();
break;
case 'dotGraph':
draw(txt, id,true);
break;
case 'sequenceDiagram':
seq.draw(txt,id);
break;
}

}
Expand Down Expand Up @@ -341,6 +356,7 @@ if(typeof document !== 'undefined'){

}


global.mermaid = {
init:function(){
init();
Expand Down
4 changes: 2 additions & 2 deletions src/main.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe('when using main and ',function() {
it('should start something with a mermaid document', function () {
mermaid_config ={startOnLoad : false};
main = rewire('./main');

document.body.innerHTML = '<div class="mermaid"></div>';
console.log('here');
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>';
spyOn(utils,'detectType');
mermaid.init();
expect(utils.detectType).toHaveBeenCalled();
Expand Down
Loading

0 comments on commit 4c564eb

Please sign in to comment.