Skip to content

Commit 9c505ec

Browse files
committed
Reformatted all the code with jscs, and now following the Google style guide.
1 parent 73e5bf3 commit 9c505ec

12 files changed

+1091
-1084
lines changed

src/diagram.js

Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -6,124 +6,126 @@
66
/*global grammar _ */
77

88
function Diagram() {
9-
this.title = undefined;
10-
this.actors = [];
11-
this.signals = [];
9+
this.title = undefined;
10+
this.actors = [];
11+
this.signals = [];
1212
}
1313
/*
1414
* Return an existing actor with this alias, or creates a new one with alias and name.
1515
*/
1616
Diagram.prototype.getActor = function(alias, name) {
17-
alias = alias.trim();
18-
19-
var i, actors = this.actors;
20-
for (i in actors) {
21-
if (actors[i].alias == alias)
22-
return actors[i];
23-
}
24-
i = actors.push( new Diagram.Actor(alias, (name || alias), actors.length) );
25-
return actors[ i - 1 ];
17+
alias = alias.trim();
18+
19+
var i;
20+
var actors = this.actors;
21+
for (i in actors) {
22+
if (actors[i].alias == alias) {
23+
return actors[i];
24+
}
25+
}
26+
i = actors.push(new Diagram.Actor(alias, (name || alias), actors.length));
27+
return actors[ i - 1 ];
2628
};
2729

2830
/*
2931
* Parses the input as either a alias, or a "name as alias", and returns the corresponding actor.
3032
*/
3133
Diagram.prototype.getActorWithAlias = function(input) {
32-
input = input.trim();
33-
34-
// We are lazy and do some of the parsing in javascript :(. TODO move into the .jison file.
35-
var s = /([\s\S]+) as (\S+)$/im.exec(input);
36-
var alias, name;
37-
if (s) {
38-
name = s[1].trim();
39-
alias = s[2].trim();
40-
} else {
41-
name = alias = input;
42-
}
43-
return this.getActor(alias, name);
34+
input = input.trim();
35+
36+
// We are lazy and do some of the parsing in javascript :(. TODO move into the .jison file.
37+
var s = /([\s\S]+) as (\S+)$/im.exec(input);
38+
var alias;
39+
var name;
40+
if (s) {
41+
name = s[1].trim();
42+
alias = s[2].trim();
43+
} else {
44+
name = alias = input;
45+
}
46+
return this.getActor(alias, name);
4447
};
4548

4649
Diagram.prototype.setTitle = function(title) {
47-
this.title = title;
50+
this.title = title;
4851
};
4952

5053
Diagram.prototype.addSignal = function(signal) {
51-
this.signals.push( signal );
54+
this.signals.push(signal);
5255
};
5356

5457
Diagram.Actor = function(alias, name, index) {
55-
this.alias = alias;
56-
this.name = name;
57-
this.index = index;
58+
this.alias = alias;
59+
this.name = name;
60+
this.index = index;
5861
};
5962

6063
Diagram.Signal = function(actorA, signaltype, actorB, message) {
61-
this.type = "Signal";
62-
this.actorA = actorA;
63-
this.actorB = actorB;
64-
this.linetype = signaltype & 3;
65-
this.arrowtype = (signaltype >> 2) & 3;
66-
this.message = message;
64+
this.type = 'Signal';
65+
this.actorA = actorA;
66+
this.actorB = actorB;
67+
this.linetype = signaltype & 3;
68+
this.arrowtype = (signaltype >> 2) & 3;
69+
this.message = message;
6770
};
6871

6972
Diagram.Signal.prototype.isSelf = function() {
70-
return this.actorA.index == this.actorB.index;
73+
return this.actorA.index == this.actorB.index;
7174
};
7275

7376
Diagram.Note = function(actor, placement, message) {
74-
this.type = "Note";
75-
this.actor = actor;
76-
this.placement = placement;
77-
this.message = message;
78-
79-
if (this.hasManyActors() && actor[0] == actor[1]) {
80-
throw new Error("Note should be over two different actors");
81-
}
77+
this.type = 'Note';
78+
this.actor = actor;
79+
this.placement = placement;
80+
this.message = message;
81+
82+
if (this.hasManyActors() && actor[0] == actor[1]) {
83+
throw new Error('Note should be over two different actors');
84+
}
8285
};
8386

8487
Diagram.Note.prototype.hasManyActors = function() {
85-
return _.isArray(this.actor);
88+
return _.isArray(this.actor);
8689
};
8790

8891
Diagram.unescape = function(s) {
89-
// Turn "\\n" into "\n"
90-
return s.trim().replace(/^"(.*)"$/m, "$1").replace(/\\n/gm, "\n");
92+
// Turn "\\n" into "\n"
93+
return s.trim().replace(/^"(.*)"$/m, '$1').replace(/\\n/gm, '\n');
9194
};
9295

9396
Diagram.LINETYPE = {
94-
SOLID : 0,
95-
DOTTED : 1
97+
SOLID: 0,
98+
DOTTED: 1
9699
};
97100

98101
Diagram.ARROWTYPE = {
99-
FILLED : 0,
100-
OPEN : 1
102+
FILLED: 0,
103+
OPEN: 1
101104
};
102105

103106
Diagram.PLACEMENT = {
104-
LEFTOF : 0,
105-
RIGHTOF : 1,
106-
OVER : 2
107+
LEFTOF: 0,
108+
RIGHTOF: 1,
109+
OVER: 2
107110
};
108111

109-
110112
// Some older browsers don't have getPrototypeOf, thus we polyfill it
111113
// https://github.com/bramp/js-sequence-diagrams/issues/57
112114
// https://github.com/zaach/jison/issues/194
113115
// Taken from http://ejohn.org/blog/objectgetprototypeof/
114-
if ( typeof Object.getPrototypeOf !== "function" ) {
115-
/* jshint -W103 */
116-
if ( typeof "test".__proto__ === "object" ) {
117-
Object.getPrototypeOf = function(object){
118-
return object.__proto__;
119-
};
120-
} else {
121-
Object.getPrototypeOf = function(object){
122-
// May break if the constructor has been tampered with
123-
return object.constructor.prototype;
124-
};
125-
}
126-
/* jshint +W103 */
116+
if (typeof Object.getPrototypeOf !== 'function') {
117+
/* jshint -W103 */
118+
if (typeof 'test'.__proto__ === 'object') {
119+
Object.getPrototypeOf = function(object) {
120+
return object.__proto__;
121+
};
122+
} else {
123+
Object.getPrototypeOf = function(object) {
124+
// May break if the constructor has been tampered with
125+
return object.constructor.prototype;
126+
};
127+
}
128+
/* jshint +W103 */
127129
}
128130

129131
/** The following is included by preprocessor */
@@ -134,30 +136,28 @@ if ( typeof Object.getPrototypeOf !== "function" ) {
134136
* This is brittle as it depends on jison internals
135137
*/
136138
function ParseError(message, hash) {
137-
_.extend(this, hash);
139+
_.extend(this, hash);
138140

139-
this.name = "ParseError";
140-
this.message = (message || "");
141+
this.name = 'ParseError';
142+
this.message = (message || '');
141143
}
142144
ParseError.prototype = new Error();
143145
Diagram.ParseError = ParseError;
144146

145147
Diagram.parse = function(input) {
146-
// TODO jison v0.4.17 changed their API slightly, so parser is no longer defined:
148+
// TODO jison v0.4.17 changed their API slightly, so parser is no longer defined:
147149

148-
// Create the object to track state and deal with errors
149-
parser.yy = new Diagram();
150-
parser.yy.parseError = function(message, hash) {
151-
throw new ParseError(message, hash);
152-
};
150+
// Create the object to track state and deal with errors
151+
parser.yy = new Diagram();
152+
parser.yy.parseError = function(message, hash) {
153+
throw new ParseError(message, hash);
154+
};
153155

154-
// Parse
155-
var diagram = parser.parse(input);
156+
// Parse
157+
var diagram = parser.parse(input);
156158

157-
// Then clean up the parseError key that a user won't care about
158-
delete diagram.parseError;
159-
return diagram;
159+
// Then clean up the parseError key that a user won't care about
160+
delete diagram.parseError;
161+
return diagram;
160162
};
161163

162-
163-

src/jquery-plugin.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
*/
66
/*global jQuery */
77
if (typeof jQuery != 'undefined') {
8-
(function( $ ) {
9-
$.fn.sequenceDiagram = function( options ) {
10-
return this.each(function() {
11-
var $this = $(this);
12-
var diagram = Diagram.parse($this.text());
13-
$this.html('');
14-
diagram.drawSVG(this, options);
15-
});
16-
};
17-
})( jQuery );
18-
}
8+
(function($) {
9+
$.fn.sequenceDiagram = function(options) {
10+
return this.each(function() {
11+
var $this = $(this);
12+
var diagram = Diagram.parse($this.text());
13+
$this.html('');
14+
diagram.drawSVG(this, options);
15+
});
16+
};
17+
})(jQuery);
18+
}

src/main.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,41 @@
33
* (c) 2012-2015 Andrew Brampton (bramp.net)
44
* @license Simplified BSD license.
55
*/
6-
(function () {
7-
"use strict";
8-
/*global Diagram */
6+
(function() {
7+
'use strict';
8+
/*global Diagram */
99

10-
// The following are included by preprocessor */
11-
// #include "build/diagram-grammar.js"
12-
// #include "src/theme.js"
10+
// The following are included by preprocessor */
11+
// #include "build/diagram-grammar.js"
12+
// #include "src/theme.js"
1313

14-
// #ifdef SNAP
15-
// #include "src/theme-snap.js"
16-
// #endif
14+
// #ifdef SNAP
15+
// #include "src/theme-snap.js"
16+
// #endif
1717

18-
// #ifdef RAPHAEL
19-
// #include "src/theme-raphael.js"
20-
// #include "fonts/daniel/daniel_700.font.js"
21-
// #endif
18+
// #ifdef RAPHAEL
19+
// #include "src/theme-raphael.js"
20+
// #include "fonts/daniel/daniel_700.font.js"
21+
// #endif
2222

23-
// #include "src/sequence-diagram.js"
24-
// #include "src/jquery-plugin.js"
23+
// #include "src/sequence-diagram.js"
24+
// #include "src/jquery-plugin.js"
2525

26-
// Taken from underscore.js:
27-
// Establish the root object, `window` (`self`) in the browser, or `global` on the server.
28-
// We use `self` instead of `window` for `WebWorker` support.
29-
var root = (typeof self == 'object' && self.self == self && self) ||
30-
(typeof global == 'object' && global.global == global && global);
26+
// Taken from underscore.js:
27+
// Establish the root object, `window` (`self`) in the browser, or `global` on the server.
28+
// We use `self` instead of `window` for `WebWorker` support.
29+
var root = (typeof self == 'object' && self.self == self && self) ||
30+
(typeof global == 'object' && global.global == global && global);
3131

32-
// Export the Diagram object for **Node.js**, with
33-
// backwards-compatibility for their old module API. If we're in
34-
// the browser, add `Diagram` as a global object.
35-
if (typeof exports !== 'undefined') {
36-
if (typeof module !== 'undefined' && module.exports) {
37-
exports = module.exports = Diagram;
38-
}
39-
exports.Diagram = Diagram;
40-
} else {
41-
root.Diagram = Diagram;
42-
}
32+
// Export the Diagram object for **Node.js**, with
33+
// backwards-compatibility for their old module API. If we're in
34+
// the browser, add `Diagram` as a global object.
35+
if (typeof exports !== 'undefined') {
36+
if (typeof module !== 'undefined' && module.exports) {
37+
exports = module.exports = Diagram;
38+
}
39+
exports.Diagram = Diagram;
40+
} else {
41+
root.Diagram = Diagram;
42+
}
4343
}());

0 commit comments

Comments
 (0)