mirror of
				https://github.com/mermaid-js/mermaid.git
				synced 2025-11-04 04:44:08 +01:00 
			
		
		
		
	Options are working.
This commit is contained in:
		
							
								
								
									
										110
									
								
								dist/www/javascripts/lib/mermaid.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										110
									
								
								dist/www/javascripts/lib/mermaid.js
									
									
									
									
										vendored
									
									
								
							@@ -53482,6 +53482,21 @@ function isReachableFrom(currentCommit, otherCommit) {
 | 
			
		||||
exports.setDirection = function (dir) {
 | 
			
		||||
    direction = dir;
 | 
			
		||||
};
 | 
			
		||||
var options = {};
 | 
			
		||||
exports.setOptions = function (rawOptString) {
 | 
			
		||||
    log.debug("options str", rawOptString);
 | 
			
		||||
    rawOptString = rawOptString && rawOptString.trim();
 | 
			
		||||
    rawOptString = rawOptString || "{}";
 | 
			
		||||
    try {
 | 
			
		||||
        options = JSON.parse(rawOptString);
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
        log.error("error while parsing gitGraph options", e.message);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.getOptions = function () {
 | 
			
		||||
    return options;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
exports.commit = function (msg) {
 | 
			
		||||
    var commit = { id: getId(),
 | 
			
		||||
@@ -53640,7 +53655,10 @@ var config = {
 | 
			
		||||
    lineColor: "grey",
 | 
			
		||||
    leftMargin: 50
 | 
			
		||||
};
 | 
			
		||||
exports.setConf = function (config) {};
 | 
			
		||||
var apiConfig = {};
 | 
			
		||||
exports.setConf = function (c) {
 | 
			
		||||
    apiConfig = c;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
function svgCreateDefs(svg) {
 | 
			
		||||
    svg.append("defs").append("g").attr("id", "def-commit").append("circle").attr("r", 15).attr("cx", 0).attr("cy", 0);
 | 
			
		||||
@@ -53763,6 +53781,9 @@ exports.draw = function (txt, id, ver) {
 | 
			
		||||
        log.debug('in gitgraph renderer', txt, id, ver);
 | 
			
		||||
        // Parse the graph definition
 | 
			
		||||
        parser.parse(txt + "\n");
 | 
			
		||||
 | 
			
		||||
        config = _.extend(config, apiConfig, db.getOptions());
 | 
			
		||||
        log.debug("effective options", config);
 | 
			
		||||
        var direction = db.getDirection();
 | 
			
		||||
        allCommitsDict = db.getCommits();
 | 
			
		||||
        var branches = db.getBranchesAsObjArray();
 | 
			
		||||
@@ -53864,21 +53885,17 @@ var gitGraph = (function () {
 | 
			
		||||
    var o = function o(k, v, _o, l) {
 | 
			
		||||
        for (_o = _o || {}, l = k.length; l--; _o[k[l]] = v);return _o;
 | 
			
		||||
    },
 | 
			
		||||
        $V0 = [7, 11, 12, 14, 16, 17, 18],
 | 
			
		||||
        $V1 = [2, 3],
 | 
			
		||||
        $V2 = [1, 10],
 | 
			
		||||
        $V3 = [1, 11],
 | 
			
		||||
        $V4 = [1, 12],
 | 
			
		||||
        $V5 = [1, 13],
 | 
			
		||||
        $V6 = [1, 14],
 | 
			
		||||
        $V7 = [1, 15];
 | 
			
		||||
        $V0 = [2, 3],
 | 
			
		||||
        $V1 = [1, 7],
 | 
			
		||||
        $V2 = [7, 12, 15, 17, 19, 20, 21],
 | 
			
		||||
        $V3 = [7, 11, 12, 15, 17, 19, 20, 21];
 | 
			
		||||
    var parser = { trace: function trace() {
 | 
			
		||||
            Jison.print.apply(null, arguments);
 | 
			
		||||
        },
 | 
			
		||||
        yy: {},
 | 
			
		||||
        symbols_: { "error": 2, "start": 3, "GG": 4, ":": 5, "document": 6, "EOF": 7, "DIR": 8, "line": 9, "statement": 10, "NL": 11, "COMMIT": 12, "commit_arg": 13, "BRANCH": 14, "ID": 15, "CHECKOUT": 16, "MERGE": 17, "RESET": 18, "reset_arg": 19, "STR": 20, "HEAD": 21, "$accept": 0, "$end": 1 },
 | 
			
		||||
        terminals_: { 2: "error", 4: "GG", 5: ":", 7: "EOF", 8: "DIR", 11: "NL", 12: "COMMIT", 14: "BRANCH", 15: "ID", 16: "CHECKOUT", 17: "MERGE", 18: "RESET", 20: "STR", 21: "HEAD" },
 | 
			
		||||
        productions_: [0, [3, 4], [3, 5], [6, 0], [6, 2], [9, 2], [9, 1], [10, 2], [10, 2], [10, 2], [10, 2], [10, 2], [13, 0], [13, 1], [19, 1], [19, 1]],
 | 
			
		||||
        symbols_: { "error": 2, "start": 3, "GG": 4, ":": 5, "document": 6, "EOF": 7, "DIR": 8, "options": 9, "body": 10, "OPT": 11, "NL": 12, "line": 13, "statement": 14, "COMMIT": 15, "commit_arg": 16, "BRANCH": 17, "ID": 18, "CHECKOUT": 19, "MERGE": 20, "RESET": 21, "reset_arg": 22, "STR": 23, "HEAD": 24, "$accept": 0, "$end": 1 },
 | 
			
		||||
        terminals_: { 2: "error", 4: "GG", 5: ":", 7: "EOF", 8: "DIR", 11: "OPT", 12: "NL", 15: "COMMIT", 17: "BRANCH", 18: "ID", 19: "CHECKOUT", 20: "MERGE", 21: "RESET", 23: "STR", 24: "HEAD" },
 | 
			
		||||
        productions_: [0, [3, 4], [3, 5], [6, 0], [6, 2], [9, 2], [9, 1], [10, 0], [10, 2], [13, 2], [13, 1], [14, 2], [14, 2], [14, 2], [14, 2], [14, 2], [16, 0], [16, 1], [22, 1], [22, 1]],
 | 
			
		||||
        performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate, /* action[1] */$$, /* vstack */_$ /* lstack */) {
 | 
			
		||||
            /* this == yyval */
 | 
			
		||||
 | 
			
		||||
@@ -53890,40 +53907,46 @@ var gitGraph = (function () {
 | 
			
		||||
                case 2:
 | 
			
		||||
                    yy.setDirection($$[$0 - 3]);return $$[$0 - 1];
 | 
			
		||||
                    break;
 | 
			
		||||
                case 3:
 | 
			
		||||
                    this.$ = [];
 | 
			
		||||
                    break;
 | 
			
		||||
                case 4:
 | 
			
		||||
                    $$[$0 - 1].push($$[$0]);this.$ = $$[$0 - 1];
 | 
			
		||||
                    yy.setOptions($$[$0 - 1]);this.$ = $$[$0];
 | 
			
		||||
                    break;
 | 
			
		||||
                case 5:
 | 
			
		||||
                    this.$ = $$[$0 - 1];
 | 
			
		||||
                    $$[$0 - 1] += $$[$0];this.$ = $$[$0 - 1];
 | 
			
		||||
                    break;
 | 
			
		||||
                case 7:
 | 
			
		||||
                    yy.commit($$[$0]);
 | 
			
		||||
                    this.$ = [];
 | 
			
		||||
                    break;
 | 
			
		||||
                case 8:
 | 
			
		||||
                    yy.branch($$[$0]);
 | 
			
		||||
                    $$[$0 - 1].push($$[$0]);this.$ = $$[$0 - 1];
 | 
			
		||||
                    break;
 | 
			
		||||
                case 9:
 | 
			
		||||
                    yy.checkout($$[$0]);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 10:
 | 
			
		||||
                    yy.merge($$[$0]);
 | 
			
		||||
                    this.$ = $$[$0 - 1];
 | 
			
		||||
                    break;
 | 
			
		||||
                case 11:
 | 
			
		||||
                    yy.reset($$[$0]);
 | 
			
		||||
                    yy.commit($$[$0]);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 12:
 | 
			
		||||
                    this.$ = "";
 | 
			
		||||
                    yy.branch($$[$0]);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 13:
 | 
			
		||||
                    yy.checkout($$[$0]);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 14:
 | 
			
		||||
                    yy.merge($$[$0]);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 15:
 | 
			
		||||
                    yy.reset($$[$0]);
 | 
			
		||||
                    break;
 | 
			
		||||
                case 16:
 | 
			
		||||
                    this.$ = "";
 | 
			
		||||
                    break;
 | 
			
		||||
                case 17:
 | 
			
		||||
                    this.$ = $$[$0];
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
        },
 | 
			
		||||
        table: [{ 3: 1, 4: [1, 2] }, { 1: [3] }, { 5: [1, 3], 8: [1, 4] }, o($V0, $V1, { 6: 5 }), { 5: [1, 6] }, { 7: [1, 7], 9: 8, 10: 9, 11: $V2, 12: $V3, 14: $V4, 16: $V5, 17: $V6, 18: $V7 }, o($V0, $V1, { 6: 16 }), { 1: [2, 1] }, o($V0, [2, 4]), { 11: [1, 17] }, o($V0, [2, 6]), { 11: [2, 12], 13: 18, 20: [1, 19] }, { 15: [1, 20] }, { 15: [1, 21] }, { 15: [1, 22] }, { 15: [1, 25], 19: 23, 21: [1, 24] }, { 7: [1, 26], 9: 8, 10: 9, 11: $V2, 12: $V3, 14: $V4, 16: $V5, 17: $V6, 18: $V7 }, o($V0, [2, 5]), { 11: [2, 7] }, { 11: [2, 13] }, { 11: [2, 8] }, { 11: [2, 9] }, { 11: [2, 10] }, { 11: [2, 11] }, { 11: [2, 14] }, { 11: [2, 15] }, { 1: [2, 2] }],
 | 
			
		||||
        defaultActions: { 7: [2, 1], 18: [2, 7], 19: [2, 13], 20: [2, 8], 21: [2, 9], 22: [2, 10], 23: [2, 11], 24: [2, 14], 25: [2, 15], 26: [2, 2] },
 | 
			
		||||
        table: [{ 3: 1, 4: [1, 2] }, { 1: [3] }, { 5: [1, 3], 8: [1, 4] }, { 6: 5, 7: $V0, 9: 6, 12: $V1 }, { 5: [1, 8] }, { 7: [1, 9] }, o($V2, [2, 7], { 10: 10, 11: [1, 11] }), o($V3, [2, 6]), { 6: 12, 7: $V0, 9: 6, 12: $V1 }, { 1: [2, 1] }, { 7: [2, 4], 12: [1, 15], 13: 13, 14: 14, 15: [1, 16], 17: [1, 17], 19: [1, 18], 20: [1, 19], 21: [1, 20] }, o($V3, [2, 5]), { 7: [1, 21] }, o($V2, [2, 8]), { 12: [1, 22] }, o($V2, [2, 10]), { 12: [2, 16], 16: 23, 23: [1, 24] }, { 18: [1, 25] }, { 18: [1, 26] }, { 18: [1, 27] }, { 18: [1, 30], 22: 28, 24: [1, 29] }, { 1: [2, 2] }, o($V2, [2, 9]), { 12: [2, 11] }, { 12: [2, 17] }, { 12: [2, 12] }, { 12: [2, 13] }, { 12: [2, 14] }, { 12: [2, 15] }, { 12: [2, 18] }, { 12: [2, 19] }],
 | 
			
		||||
        defaultActions: { 9: [2, 1], 21: [2, 2], 23: [2, 11], 24: [2, 17], 25: [2, 12], 26: [2, 13], 27: [2, 14], 28: [2, 15], 29: [2, 18], 30: [2, 19] },
 | 
			
		||||
        parseError: function parseError(str, hash) {
 | 
			
		||||
            if (hash.recoverable) {
 | 
			
		||||
                this.trace(str);
 | 
			
		||||
@@ -54402,7 +54425,7 @@ var gitGraph = (function () {
 | 
			
		||||
                var YYSTATE = YY_START;
 | 
			
		||||
                switch ($avoiding_name_collisions) {
 | 
			
		||||
                    case 0:
 | 
			
		||||
                        return 11;
 | 
			
		||||
                        return 12;
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 1:
 | 
			
		||||
                        /* skip all whitespace */
 | 
			
		||||
@@ -54417,19 +54440,19 @@ var gitGraph = (function () {
 | 
			
		||||
                        return 4;
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 5:
 | 
			
		||||
                        return 12;
 | 
			
		||||
                        return 15;
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 6:
 | 
			
		||||
                        return 14;
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 7:
 | 
			
		||||
                        return 17;
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 7:
 | 
			
		||||
                        return 20;
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 8:
 | 
			
		||||
                        return 18;
 | 
			
		||||
                        return 21;
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 9:
 | 
			
		||||
                        return 16;
 | 
			
		||||
                        return 19;
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 10:
 | 
			
		||||
                        return 8;
 | 
			
		||||
@@ -54444,24 +54467,33 @@ var gitGraph = (function () {
 | 
			
		||||
                        return 5;
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 14:
 | 
			
		||||
                        this.begin("string");
 | 
			
		||||
                        this.begin("options");
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 15:
 | 
			
		||||
                        this.popState();
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 16:
 | 
			
		||||
                        return 20;
 | 
			
		||||
                        return 11;
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 17:
 | 
			
		||||
                        return 15;
 | 
			
		||||
                        this.begin("string");
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 18:
 | 
			
		||||
                        this.popState();
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 19:
 | 
			
		||||
                        return 23;
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 20:
 | 
			
		||||
                        return 18;
 | 
			
		||||
                        break;
 | 
			
		||||
                    case 21:
 | 
			
		||||
                        return 7;
 | 
			
		||||
                        break;
 | 
			
		||||
                }
 | 
			
		||||
            },
 | 
			
		||||
            rules: [/^(?:[\n|\r\n]+)/i, /^(?:\s+)/i, /^(?:#[^\n]*)/i, /^(?:%[^\n]*)/i, /^(?:gitGraph\b)/i, /^(?:commit\b)/i, /^(?:branch\b)/i, /^(?:merge\b)/i, /^(?:reset\b)/i, /^(?:checkout\b)/i, /^(?:LR\b)/i, /^(?:TB\b)/i, /^(?:BT\b)/i, /^(?::)/i, /^(?:["])/i, /^(?:["])/i, /^(?:[^"]*)/i, /^(?:[a-zA-Z][a-zA-Z0-9_]+)/i, /^(?:$)/i],
 | 
			
		||||
            conditions: { "string": { "rules": [15, 16], "inclusive": false }, "INITIAL": { "rules": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 18], "inclusive": true } }
 | 
			
		||||
            rules: [/^(?:(\r?\n)+)/i, /^(?:\s+)/i, /^(?:#[^\n]*)/i, /^(?:%[^\n]*)/i, /^(?:gitGraph\b)/i, /^(?:commit\b)/i, /^(?:branch\b)/i, /^(?:merge\b)/i, /^(?:reset\b)/i, /^(?:checkout\b)/i, /^(?:LR\b)/i, /^(?:TB\b)/i, /^(?:BT\b)/i, /^(?::)/i, /^(?:options\r?\n)/i, /^(?:end\r?\n)/i, /^(?:[^\n]+\r?\n)/i, /^(?:["])/i, /^(?:["])/i, /^(?:[^"]*)/i, /^(?:[a-zA-Z][a-zA-Z0-9_]+)/i, /^(?:$)/i],
 | 
			
		||||
            conditions: { "options": { "rules": [15, 16], "inclusive": false }, "string": { "rules": [18, 19], "inclusive": false }, "INITIAL": { "rules": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 17, 20, 21], "inclusive": true } }
 | 
			
		||||
        };
 | 
			
		||||
        return lexer;
 | 
			
		||||
    })();
 | 
			
		||||
 
 | 
			
		||||
@@ -51,6 +51,21 @@ function isReachableFrom(currentCommit, otherCommit) {
 | 
			
		||||
exports.setDirection = function(dir) {
 | 
			
		||||
    direction = dir;
 | 
			
		||||
}
 | 
			
		||||
var options = {};
 | 
			
		||||
exports.setOptions = function(rawOptString) {
 | 
			
		||||
    log.debug("options str", rawOptString);
 | 
			
		||||
    rawOptString = rawOptString && rawOptString.trim();
 | 
			
		||||
    rawOptString = rawOptString || "{}";
 | 
			
		||||
    try {
 | 
			
		||||
        options = JSON.parse(rawOptString)
 | 
			
		||||
    } catch(e) {
 | 
			
		||||
        log.error("error while parsing gitGraph options", e.message);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.getOptions = function() {
 | 
			
		||||
    return options;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.commit = function(msg) {
 | 
			
		||||
    var commit = { id: getId(),
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ describe('when parsing a gitGraph',function() {
 | 
			
		||||
 | 
			
		||||
        parser.parse(str);
 | 
			
		||||
        var commits = parser.yy.getCommits();
 | 
			
		||||
        console.log(commits);
 | 
			
		||||
        //console.log(commits);
 | 
			
		||||
 | 
			
		||||
        expect(Object.keys(commits).length).toBe(1);
 | 
			
		||||
        expect(parser.yy.getCurrentBranch()).toBe("master");
 | 
			
		||||
@@ -20,13 +20,64 @@ describe('when parsing a gitGraph',function() {
 | 
			
		||||
        expect(Object.keys(parser.yy.getBranches()).length).toBe(1);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('should handle a gitGraph defintion with empty options', function () {
 | 
			
		||||
        var str = 'gitGraph:\n' +
 | 
			
		||||
        'options\n' +
 | 
			
		||||
        'end\n' +
 | 
			
		||||
        'commit\n';
 | 
			
		||||
 | 
			
		||||
        parser.parse(str);
 | 
			
		||||
        var commits = parser.yy.getCommits();
 | 
			
		||||
        //console.log(commits);
 | 
			
		||||
 | 
			
		||||
        expect(parser.yy.getOptions()).toEqual({});
 | 
			
		||||
        expect(Object.keys(commits).length).toBe(1);
 | 
			
		||||
        expect(parser.yy.getCurrentBranch()).toBe("master");
 | 
			
		||||
        expect(parser.yy.getDirection()).toBe("LR");
 | 
			
		||||
        expect(Object.keys(parser.yy.getBranches()).length).toBe(1);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('should handle a gitGraph defintion with valid options', function () {
 | 
			
		||||
        var str = 'gitGraph:\n' +
 | 
			
		||||
        'options\n' +
 | 
			
		||||
        '{"key": "value"}\n' +
 | 
			
		||||
        'end\n' +
 | 
			
		||||
        'commit\n';
 | 
			
		||||
 | 
			
		||||
        parser.parse(str);
 | 
			
		||||
        var commits = parser.yy.getCommits();
 | 
			
		||||
        //console.log(commits);
 | 
			
		||||
        console.log("options object", parser.yy.getOptions());
 | 
			
		||||
        expect(parser.yy.getOptions()["key"]).toBe("value");
 | 
			
		||||
        expect(Object.keys(commits).length).toBe(1);
 | 
			
		||||
        expect(parser.yy.getCurrentBranch()).toBe("master");
 | 
			
		||||
        expect(parser.yy.getDirection()).toBe("LR");
 | 
			
		||||
        expect(Object.keys(parser.yy.getBranches()).length).toBe(1);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('should not fail on a gitGraph with malformed json', function () {
 | 
			
		||||
        var str = 'gitGraph:\n' +
 | 
			
		||||
        'options\n' +
 | 
			
		||||
        '{"key": "value"\n' +
 | 
			
		||||
        'end\n' +
 | 
			
		||||
        'commit\n';
 | 
			
		||||
 | 
			
		||||
        parser.parse(str);
 | 
			
		||||
        var commits = parser.yy.getCommits();
 | 
			
		||||
        //console.log(commits);
 | 
			
		||||
        expect(Object.keys(commits).length).toBe(1);
 | 
			
		||||
        expect(parser.yy.getCurrentBranch()).toBe("master");
 | 
			
		||||
        expect(parser.yy.getDirection()).toBe("LR");
 | 
			
		||||
        expect(Object.keys(parser.yy.getBranches()).length).toBe(1);
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('should handle set direction', function () {
 | 
			
		||||
        var str = 'gitGraph TB:\n' +
 | 
			
		||||
        'commit\n';
 | 
			
		||||
 | 
			
		||||
        parser.parse(str);
 | 
			
		||||
        var commits = parser.yy.getCommits();
 | 
			
		||||
        console.log(commits);
 | 
			
		||||
        //console.log(commits);
 | 
			
		||||
 | 
			
		||||
        expect(Object.keys(commits).length).toBe(1);
 | 
			
		||||
        expect(parser.yy.getCurrentBranch()).toBe("master");
 | 
			
		||||
@@ -68,7 +119,7 @@ describe('when parsing a gitGraph',function() {
 | 
			
		||||
 | 
			
		||||
        parser.parse(str);
 | 
			
		||||
        var commits = parser.yy.getCommits();
 | 
			
		||||
        console.log(commits);
 | 
			
		||||
        //console.log(commits);
 | 
			
		||||
 | 
			
		||||
        expect(Object.keys(commits).length).toBe(1);
 | 
			
		||||
        var key = Object.keys(commits)[0];
 | 
			
		||||
@@ -107,7 +158,7 @@ describe('when parsing a gitGraph',function() {
 | 
			
		||||
        parser.parse(str);
 | 
			
		||||
 | 
			
		||||
        var commits = parser.yy.getCommits();
 | 
			
		||||
        console.log(commits);
 | 
			
		||||
        //console.log(commits);
 | 
			
		||||
        expect(Object.keys(commits).length).toBe(3);
 | 
			
		||||
        expect(parser.yy.getCurrentBranch()).toBe("master");
 | 
			
		||||
        expect(parser.yy.getBranches()["newbranch"]).toEqual(parser.yy.getBranches()["master"]);
 | 
			
		||||
@@ -126,7 +177,7 @@ describe('when parsing a gitGraph',function() {
 | 
			
		||||
        parser.parse(str);
 | 
			
		||||
 | 
			
		||||
        var commits = parser.yy.getCommits();
 | 
			
		||||
        console.log(commits);
 | 
			
		||||
        //console.log(commits);
 | 
			
		||||
        expect(Object.keys(commits).length).toBe(3);
 | 
			
		||||
        expect(parser.yy.getCurrentBranch()).toBe("newbranch");
 | 
			
		||||
        expect(parser.yy.getBranches()["newbranch"]).not.toEqual(parser.yy.getBranches()["master"]);
 | 
			
		||||
@@ -147,7 +198,7 @@ describe('when parsing a gitGraph',function() {
 | 
			
		||||
        parser.parse(str);
 | 
			
		||||
 | 
			
		||||
        var commits = parser.yy.getCommits();
 | 
			
		||||
        console.log(commits);
 | 
			
		||||
        //console.log(commits);
 | 
			
		||||
        expect(Object.keys(commits).length).toBe(5);
 | 
			
		||||
        expect(parser.yy.getCurrentBranch()).toBe("master");
 | 
			
		||||
        expect(parser.yy.getBranches()["newbranch"]).not.toEqual(parser.yy.getBranches()["master"]);
 | 
			
		||||
@@ -171,7 +222,7 @@ describe('when parsing a gitGraph',function() {
 | 
			
		||||
        parser.parse(str);
 | 
			
		||||
 | 
			
		||||
        var commits = parser.yy.getCommits();
 | 
			
		||||
        console.log(commits);
 | 
			
		||||
        //console.log(commits);
 | 
			
		||||
        expect(Object.keys(commits).length).toBe(6);
 | 
			
		||||
        expect(parser.yy.getCurrentBranch()).toBe("newbranch");
 | 
			
		||||
        expect(parser.yy.getBranches()["newbranch"]).toEqual(parser.yy.getBranches()["master"]);
 | 
			
		||||
 
 | 
			
		||||
@@ -14,8 +14,9 @@ var config = {
 | 
			
		||||
    lineColor: "grey",
 | 
			
		||||
    leftMargin: 50
 | 
			
		||||
}
 | 
			
		||||
exports.setConf = function(config) {
 | 
			
		||||
 | 
			
		||||
var apiConfig = {};
 | 
			
		||||
exports.setConf = function(c) {
 | 
			
		||||
    apiConfig = c;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -175,6 +176,9 @@ exports.draw = function(txt, id, ver) {
 | 
			
		||||
        log.debug('in gitgraph renderer', txt, id, ver);
 | 
			
		||||
        // Parse the graph definition
 | 
			
		||||
        parser.parse(txt + "\n");
 | 
			
		||||
 | 
			
		||||
        config = _.extend(config, apiConfig, db.getOptions());
 | 
			
		||||
        log.debug("effective options", config);
 | 
			
		||||
        var direction = db.getDirection();
 | 
			
		||||
        allCommitsDict = db.getCommits();
 | 
			
		||||
        var branches = db.getBranchesAsObjArray();
 | 
			
		||||
 
 | 
			
		||||
@@ -9,11 +9,12 @@
 | 
			
		||||
%lex
 | 
			
		||||
 | 
			
		||||
%x string
 | 
			
		||||
%x options
 | 
			
		||||
%options case-insensitive
 | 
			
		||||
 | 
			
		||||
%%
 | 
			
		||||
 | 
			
		||||
[\n|\r\n]+                           return 'NL';
 | 
			
		||||
(\r?\n)+                           return 'NL';
 | 
			
		||||
\s+                             /* skip all whitespace */
 | 
			
		||||
\#[^\n]*                        /* skip comments */
 | 
			
		||||
\%%[^\n]*                       /* skip comments */
 | 
			
		||||
@@ -27,9 +28,12 @@
 | 
			
		||||
"TB"                            return 'DIR';
 | 
			
		||||
"BT"                            return 'DIR';
 | 
			
		||||
":"                             return ':';
 | 
			
		||||
"options"\r?\n                       this.begin("options");
 | 
			
		||||
<options>"end"\r?\n                   this.popState();
 | 
			
		||||
<options>[^\n]+\r?\n                 return 'OPT';
 | 
			
		||||
["]                             this.begin("string");
 | 
			
		||||
<string>["]                     this.popState();
 | 
			
		||||
<string>[^"]*                   return 'STR';
 | 
			
		||||
<string>[^"]*                     return 'STR';
 | 
			
		||||
[a-zA-Z][a-zA-Z0-9_]+           return 'ID';
 | 
			
		||||
<<EOF>>                         return 'EOF';
 | 
			
		||||
 | 
			
		||||
@@ -46,11 +50,20 @@ start
 | 
			
		||||
    | GG DIR ':' document EOF {yy.setDirection($2); return $4;}
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
document
 | 
			
		||||
    : /* empty */ {$$ =[]}
 | 
			
		||||
    | document line {$1.push($2); $$ = $1}
 | 
			
		||||
    : /*empty*/
 | 
			
		||||
    | options body { yy.setOptions($1); $$ = $2}
 | 
			
		||||
    ;
 | 
			
		||||
 | 
			
		||||
options
 | 
			
		||||
    : options OPT {$1 +=$2; $$=$1}
 | 
			
		||||
    | NL
 | 
			
		||||
    ;
 | 
			
		||||
body
 | 
			
		||||
    : /*emmpty*/ {$$ = []}
 | 
			
		||||
    | body line {$1.push($2); $$=$1;}
 | 
			
		||||
    ;
 | 
			
		||||
line
 | 
			
		||||
    : statement NL{$$ =$1}
 | 
			
		||||
    | NL
 | 
			
		||||
 
 | 
			
		||||
@@ -72,14 +72,14 @@
 | 
			
		||||
  }
 | 
			
		||||
*/
 | 
			
		||||
var gitGraph = (function(){
 | 
			
		||||
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[7,11,12,14,16,17,18],$V1=[2,3],$V2=[1,10],$V3=[1,11],$V4=[1,12],$V5=[1,13],$V6=[1,14],$V7=[1,15];
 | 
			
		||||
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[2,3],$V1=[1,7],$V2=[7,12,15,17,19,20,21],$V3=[7,11,12,15,17,19,20,21];
 | 
			
		||||
var parser = {trace: function trace() {
 | 
			
		||||
        Jison.print.apply(null, arguments);
 | 
			
		||||
    },
 | 
			
		||||
yy: {},
 | 
			
		||||
symbols_: {"error":2,"start":3,"GG":4,":":5,"document":6,"EOF":7,"DIR":8,"line":9,"statement":10,"NL":11,"COMMIT":12,"commit_arg":13,"BRANCH":14,"ID":15,"CHECKOUT":16,"MERGE":17,"RESET":18,"reset_arg":19,"STR":20,"HEAD":21,"$accept":0,"$end":1},
 | 
			
		||||
terminals_: {2:"error",4:"GG",5:":",7:"EOF",8:"DIR",11:"NL",12:"COMMIT",14:"BRANCH",15:"ID",16:"CHECKOUT",17:"MERGE",18:"RESET",20:"STR",21:"HEAD"},
 | 
			
		||||
productions_: [0,[3,4],[3,5],[6,0],[6,2],[9,2],[9,1],[10,2],[10,2],[10,2],[10,2],[10,2],[13,0],[13,1],[19,1],[19,1]],
 | 
			
		||||
symbols_: {"error":2,"start":3,"GG":4,":":5,"document":6,"EOF":7,"DIR":8,"options":9,"body":10,"OPT":11,"NL":12,"line":13,"statement":14,"COMMIT":15,"commit_arg":16,"BRANCH":17,"ID":18,"CHECKOUT":19,"MERGE":20,"RESET":21,"reset_arg":22,"STR":23,"HEAD":24,"$accept":0,"$end":1},
 | 
			
		||||
terminals_: {2:"error",4:"GG",5:":",7:"EOF",8:"DIR",11:"OPT",12:"NL",15:"COMMIT",17:"BRANCH",18:"ID",19:"CHECKOUT",20:"MERGE",21:"RESET",23:"STR",24:"HEAD"},
 | 
			
		||||
productions_: [0,[3,4],[3,5],[6,0],[6,2],[9,2],[9,1],[10,0],[10,2],[13,2],[13,1],[14,2],[14,2],[14,2],[14,2],[14,2],[16,0],[16,1],[22,1],[22,1]],
 | 
			
		||||
performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
 | 
			
		||||
/* this == yyval */
 | 
			
		||||
 | 
			
		||||
@@ -91,40 +91,46 @@ break;
 | 
			
		||||
case 2:
 | 
			
		||||
yy.setDirection($$[$0-3]); return $$[$0-1];
 | 
			
		||||
break;
 | 
			
		||||
case 3:
 | 
			
		||||
this.$ =[]
 | 
			
		||||
break;
 | 
			
		||||
case 4:
 | 
			
		||||
$$[$0-1].push($$[$0]); this.$ = $$[$0-1]
 | 
			
		||||
 yy.setOptions($$[$0-1]); this.$ = $$[$0]
 | 
			
		||||
break;
 | 
			
		||||
case 5:
 | 
			
		||||
this.$ =$$[$0-1]
 | 
			
		||||
$$[$0-1] +=$$[$0]; this.$=$$[$0-1]
 | 
			
		||||
break;
 | 
			
		||||
case 7:
 | 
			
		||||
yy.commit($$[$0])
 | 
			
		||||
this.$ = []
 | 
			
		||||
break;
 | 
			
		||||
case 8:
 | 
			
		||||
yy.branch($$[$0])
 | 
			
		||||
$$[$0-1].push($$[$0]); this.$=$$[$0-1];
 | 
			
		||||
break;
 | 
			
		||||
case 9:
 | 
			
		||||
yy.checkout($$[$0])
 | 
			
		||||
break;
 | 
			
		||||
case 10:
 | 
			
		||||
yy.merge($$[$0])
 | 
			
		||||
this.$ =$$[$0-1]
 | 
			
		||||
break;
 | 
			
		||||
case 11:
 | 
			
		||||
yy.reset($$[$0])
 | 
			
		||||
yy.commit($$[$0])
 | 
			
		||||
break;
 | 
			
		||||
case 12:
 | 
			
		||||
this.$ = ""
 | 
			
		||||
yy.branch($$[$0])
 | 
			
		||||
break;
 | 
			
		||||
case 13:
 | 
			
		||||
yy.checkout($$[$0])
 | 
			
		||||
break;
 | 
			
		||||
case 14:
 | 
			
		||||
yy.merge($$[$0])
 | 
			
		||||
break;
 | 
			
		||||
case 15:
 | 
			
		||||
yy.reset($$[$0])
 | 
			
		||||
break;
 | 
			
		||||
case 16:
 | 
			
		||||
this.$ = ""
 | 
			
		||||
break;
 | 
			
		||||
case 17:
 | 
			
		||||
this.$=$$[$0]
 | 
			
		||||
break;
 | 
			
		||||
}
 | 
			
		||||
},
 | 
			
		||||
table: [{3:1,4:[1,2]},{1:[3]},{5:[1,3],8:[1,4]},o($V0,$V1,{6:5}),{5:[1,6]},{7:[1,7],9:8,10:9,11:$V2,12:$V3,14:$V4,16:$V5,17:$V6,18:$V7},o($V0,$V1,{6:16}),{1:[2,1]},o($V0,[2,4]),{11:[1,17]},o($V0,[2,6]),{11:[2,12],13:18,20:[1,19]},{15:[1,20]},{15:[1,21]},{15:[1,22]},{15:[1,25],19:23,21:[1,24]},{7:[1,26],9:8,10:9,11:$V2,12:$V3,14:$V4,16:$V5,17:$V6,18:$V7},o($V0,[2,5]),{11:[2,7]},{11:[2,13]},{11:[2,8]},{11:[2,9]},{11:[2,10]},{11:[2,11]},{11:[2,14]},{11:[2,15]},{1:[2,2]}],
 | 
			
		||||
defaultActions: {7:[2,1],18:[2,7],19:[2,13],20:[2,8],21:[2,9],22:[2,10],23:[2,11],24:[2,14],25:[2,15],26:[2,2]},
 | 
			
		||||
table: [{3:1,4:[1,2]},{1:[3]},{5:[1,3],8:[1,4]},{6:5,7:$V0,9:6,12:$V1},{5:[1,8]},{7:[1,9]},o($V2,[2,7],{10:10,11:[1,11]}),o($V3,[2,6]),{6:12,7:$V0,9:6,12:$V1},{1:[2,1]},{7:[2,4],12:[1,15],13:13,14:14,15:[1,16],17:[1,17],19:[1,18],20:[1,19],21:[1,20]},o($V3,[2,5]),{7:[1,21]},o($V2,[2,8]),{12:[1,22]},o($V2,[2,10]),{12:[2,16],16:23,23:[1,24]},{18:[1,25]},{18:[1,26]},{18:[1,27]},{18:[1,30],22:28,24:[1,29]},{1:[2,2]},o($V2,[2,9]),{12:[2,11]},{12:[2,17]},{12:[2,12]},{12:[2,13]},{12:[2,14]},{12:[2,15]},{12:[2,18]},{12:[2,19]}],
 | 
			
		||||
defaultActions: {9:[2,1],21:[2,2],23:[2,11],24:[2,17],25:[2,12],26:[2,13],27:[2,14],28:[2,15],29:[2,18],30:[2,19]},
 | 
			
		||||
parseError: function parseError(str, hash) {
 | 
			
		||||
    if (hash.recoverable) {
 | 
			
		||||
        this.trace(str);
 | 
			
		||||
@@ -603,7 +609,7 @@ options: {"case-insensitive":true},
 | 
			
		||||
performAction: function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) {
 | 
			
		||||
var YYSTATE=YY_START;
 | 
			
		||||
switch($avoiding_name_collisions) {
 | 
			
		||||
case 0:return 11;
 | 
			
		||||
case 0:return 12;
 | 
			
		||||
break;
 | 
			
		||||
case 1:/* skip all whitespace */
 | 
			
		||||
break;
 | 
			
		||||
@@ -613,15 +619,15 @@ case 3:/* skip comments */
 | 
			
		||||
break;
 | 
			
		||||
case 4:return 4;
 | 
			
		||||
break;
 | 
			
		||||
case 5:return 12;
 | 
			
		||||
case 5:return 15;
 | 
			
		||||
break;
 | 
			
		||||
case 6:return 14;
 | 
			
		||||
case 6:return 17;
 | 
			
		||||
break;
 | 
			
		||||
case 7:return 17;
 | 
			
		||||
case 7:return 20;
 | 
			
		||||
break;
 | 
			
		||||
case 8:return 18;
 | 
			
		||||
case 8:return 21;
 | 
			
		||||
break;
 | 
			
		||||
case 9:return 16;
 | 
			
		||||
case 9:return 19;
 | 
			
		||||
break;
 | 
			
		||||
case 10:return 8;
 | 
			
		||||
break;
 | 
			
		||||
@@ -631,20 +637,26 @@ case 12:return 8;
 | 
			
		||||
break;
 | 
			
		||||
case 13:return 5;
 | 
			
		||||
break;
 | 
			
		||||
case 14:this.begin("string");
 | 
			
		||||
case 14:this.begin("options");
 | 
			
		||||
break;
 | 
			
		||||
case 15:this.popState();
 | 
			
		||||
break;
 | 
			
		||||
case 16:return 20;
 | 
			
		||||
case 16:return 11;
 | 
			
		||||
break;
 | 
			
		||||
case 17:return 15;
 | 
			
		||||
case 17:this.begin("string");
 | 
			
		||||
break;
 | 
			
		||||
case 18:return 7;
 | 
			
		||||
case 18:this.popState();
 | 
			
		||||
break;
 | 
			
		||||
case 19:return 23;
 | 
			
		||||
break;
 | 
			
		||||
case 20:return 18;
 | 
			
		||||
break;
 | 
			
		||||
case 21:return 7;
 | 
			
		||||
break;
 | 
			
		||||
}
 | 
			
		||||
},
 | 
			
		||||
rules: [/^(?:[\n|\r\n]+)/i,/^(?:\s+)/i,/^(?:#[^\n]*)/i,/^(?:%[^\n]*)/i,/^(?:gitGraph\b)/i,/^(?:commit\b)/i,/^(?:branch\b)/i,/^(?:merge\b)/i,/^(?:reset\b)/i,/^(?:checkout\b)/i,/^(?:LR\b)/i,/^(?:TB\b)/i,/^(?:BT\b)/i,/^(?::)/i,/^(?:["])/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:[a-zA-Z][a-zA-Z0-9_]+)/i,/^(?:$)/i],
 | 
			
		||||
conditions: {"string":{"rules":[15,16],"inclusive":false},"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,18],"inclusive":true}}
 | 
			
		||||
rules: [/^(?:(\r?\n)+)/i,/^(?:\s+)/i,/^(?:#[^\n]*)/i,/^(?:%[^\n]*)/i,/^(?:gitGraph\b)/i,/^(?:commit\b)/i,/^(?:branch\b)/i,/^(?:merge\b)/i,/^(?:reset\b)/i,/^(?:checkout\b)/i,/^(?:LR\b)/i,/^(?:TB\b)/i,/^(?:BT\b)/i,/^(?::)/i,/^(?:options\r?\n)/i,/^(?:end\r?\n)/i,/^(?:[^\n]+\r?\n)/i,/^(?:["])/i,/^(?:["])/i,/^(?:[^"]*)/i,/^(?:[a-zA-Z][a-zA-Z0-9_]+)/i,/^(?:$)/i],
 | 
			
		||||
conditions: {"options":{"rules":[15,16],"inclusive":false},"string":{"rules":[18,19],"inclusive":false},"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,17,20,21],"inclusive":true}}
 | 
			
		||||
});
 | 
			
		||||
return lexer;
 | 
			
		||||
})();
 | 
			
		||||
 
 | 
			
		||||
@@ -1,26 +1,7 @@
 | 
			
		||||
gitGraph :
 | 
			
		||||
options
 | 
			
		||||
{"key": "value",
 | 
			
		||||
"nodeWidth": 100
 | 
			
		||||
}
 | 
			
		||||
end
 | 
			
		||||
    commit
 | 
			
		||||
    commit
 | 
			
		||||
    branch newbranch
 | 
			
		||||
    checkout newbranch
 | 
			
		||||
    commit
 | 
			
		||||
    commit
 | 
			
		||||
    branch other
 | 
			
		||||
    checkout other
 | 
			
		||||
    commit
 | 
			
		||||
    commit
 | 
			
		||||
    commit
 | 
			
		||||
    checkout master
 | 
			
		||||
    commit
 | 
			
		||||
    merge newbranch
 | 
			
		||||
    commit
 | 
			
		||||
    merge other
 | 
			
		||||
    commit
 | 
			
		||||
    branch bug
 | 
			
		||||
    checkout bug
 | 
			
		||||
    commit
 | 
			
		||||
    commit
 | 
			
		||||
    checkout master
 | 
			
		||||
    commit
 | 
			
		||||
    checkout bug
 | 
			
		||||
    merge master
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user