furnace-xray 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +1 -0
- data/bin/furnace-xray +23 -0
- data/furnace-xray.gemspec +33 -0
- data/lib/furnace-xray.rb +1 -0
- data/lib/furnace-xray/app/app.rb +56 -0
- data/lib/furnace-xray/app/assets/images/chosen-sprite.png +0 -0
- data/lib/furnace-xray/app/assets/images/evil_martians_bw_logo.svg +3 -0
- data/lib/furnace-xray/app/assets/images/evil_martians_logo.svg +3 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_diagonal-maze_20_6e4f1c_10x10.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_diagonal-maze_40_000000_10x10.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_fine-grain_10_eceadf_60x60.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_fine-grain_10_f8f7f6_60x60.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_fine-grain_15_eceadf_60x60.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_fine-grain_15_f7f3de_60x60.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_fine-grain_15_ffffff_60x60.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_fine-grain_65_654b24_60x60.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-bg_fine-grain_68_b83400_60x60.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-icons_222222_256x240.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-icons_3572ac_256x240.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-icons_8c291d_256x240.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-icons_b83400_256x240.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-icons_fbdb93_256x240.png +0 -0
- data/lib/furnace-xray/app/assets/images/ui/ui-icons_ffffff_256x240.png +0 -0
- data/lib/furnace-xray/app/assets/javascripts/application.js.coffee +219 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/drawer.js.coffee +206 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/graph.js.coffee +26 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/input.js.coffee +134 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/input_state.js.coffee +8 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/map.js.coffee +45 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/nodes/argument.js.coffee +7 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/nodes/block.js.coffee +76 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/nodes/function.js.coffee +15 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/nodes/instruction.js.coffee +33 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/nodes/operand.js.coffee +21 -0
- data/lib/furnace-xray/app/assets/javascripts/lib/nodes/type.js.coffee +12 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/chosen.jquery.js +1090 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/d3.v3.js +7806 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/dagre.js +4053 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/hotkeys.jquery.js +106 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/jquery.js +9472 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/mustache.js +532 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/stacktrace-0.4.js +424 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/sugar-1.3.8.js +8615 -0
- data/lib/furnace-xray/app/assets/javascripts/vendor/ui.jquery.js +14850 -0
- data/lib/furnace-xray/app/assets/stylesheets/app.css.sass +199 -0
- data/lib/furnace-xray/app/assets/stylesheets/chosen.jquery.css +413 -0
- data/lib/furnace-xray/app/assets/stylesheets/elements.css.sass +31 -0
- data/lib/furnace-xray/app/assets/stylesheets/graph.css.sass +29 -0
- data/lib/furnace-xray/app/assets/stylesheets/ui.jquery.css +1174 -0
- data/lib/furnace-xray/app/public/fonts/iconic_stroke.afm +170 -0
- data/lib/furnace-xray/app/public/fonts/iconic_stroke.eot +0 -0
- data/lib/furnace-xray/app/public/fonts/iconic_stroke.otf +0 -0
- data/lib/furnace-xray/app/public/fonts/iconic_stroke.svg +553 -0
- data/lib/furnace-xray/app/public/fonts/iconic_stroke.ttf +0 -0
- data/lib/furnace-xray/app/public/fonts/iconic_stroke.woff +0 -0
- data/lib/furnace-xray/app/public/fonts/iconic_stroke_demo.html +1 -0
- data/lib/furnace-xray/app/views/index.haml +52 -0
- data/lib/furnace-xray/app/views/nodes/argument.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/block.jst.mustache +4 -0
- data/lib/furnace-xray/app/views/nodes/diff/added_line.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/diff/changed_line.jst.mustache +2 -0
- data/lib/furnace-xray/app/views/nodes/diff/removed_line.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/diff/unchanged_line.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/function.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/function_removed.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/instruction_typed.jst.mustache +3 -0
- data/lib/furnace-xray/app/views/nodes/instruction_void.jst.mustache +3 -0
- data/lib/furnace-xray/app/views/nodes/operand_argument.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/operand_basic_block.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/operand_constant.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/operand_constant_function.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/operand_instruction.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/type_constant.jst.mustache +1 -0
- data/lib/furnace-xray/app/views/nodes/type_parametric.jst.mustache +3 -0
- data/lib/furnace-xray/lib/jst_pages.rb +226 -0
- data/lib/furnace-xray/version.rb +5 -0
- data/sample.json +1 -0
- metadata +251 -0
@@ -0,0 +1,532 @@
|
|
1
|
+
/*!
|
2
|
+
* mustache.js - Logic-less {{mustache}} templates with JavaScript
|
3
|
+
* http://github.com/janl/mustache.js
|
4
|
+
*/
|
5
|
+
|
6
|
+
/*global define: false*/
|
7
|
+
|
8
|
+
(function (root, factory) {
|
9
|
+
if (typeof exports === "object" && exports) {
|
10
|
+
module.exports = factory; // CommonJS
|
11
|
+
} else if (typeof define === "function" && define.amd) {
|
12
|
+
define(factory); // AMD
|
13
|
+
} else {
|
14
|
+
root.Mustache = factory; // <script>
|
15
|
+
}
|
16
|
+
}(this, (function () {
|
17
|
+
|
18
|
+
var exports = {};
|
19
|
+
|
20
|
+
exports.name = "mustache.js";
|
21
|
+
exports.version = "0.7.2";
|
22
|
+
exports.tags = ["{{", "}}"];
|
23
|
+
|
24
|
+
exports.Scanner = Scanner;
|
25
|
+
exports.Context = Context;
|
26
|
+
exports.Writer = Writer;
|
27
|
+
|
28
|
+
var whiteRe = /\s*/;
|
29
|
+
var spaceRe = /\s+/;
|
30
|
+
var nonSpaceRe = /\S/;
|
31
|
+
var eqRe = /\s*=/;
|
32
|
+
var curlyRe = /\s*\}/;
|
33
|
+
var tagRe = /#|\^|\/|>|\{|&|=|!/;
|
34
|
+
|
35
|
+
// Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
|
36
|
+
// See https://github.com/janl/mustache.js/issues/189
|
37
|
+
function testRe(re, string) {
|
38
|
+
return RegExp.prototype.test.call(re, string);
|
39
|
+
}
|
40
|
+
|
41
|
+
function isWhitespace(string) {
|
42
|
+
return !testRe(nonSpaceRe, string);
|
43
|
+
}
|
44
|
+
|
45
|
+
var isArray = Array.isArray || function (obj) {
|
46
|
+
return Object.prototype.toString.call(obj) === "[object Array]";
|
47
|
+
};
|
48
|
+
|
49
|
+
function escapeRe(string) {
|
50
|
+
return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
|
51
|
+
}
|
52
|
+
|
53
|
+
var entityMap = {
|
54
|
+
"&": "&",
|
55
|
+
"<": "<",
|
56
|
+
">": ">",
|
57
|
+
'"': '"',
|
58
|
+
"'": ''',
|
59
|
+
"/": '/'
|
60
|
+
};
|
61
|
+
|
62
|
+
function escapeHtml(string) {
|
63
|
+
return String(string).replace(/[&<>"'\/]/g, function (s) {
|
64
|
+
return entityMap[s];
|
65
|
+
});
|
66
|
+
}
|
67
|
+
|
68
|
+
// Export the escaping function so that the user may override it.
|
69
|
+
// See https://github.com/janl/mustache.js/issues/244
|
70
|
+
exports.escape = escapeHtml;
|
71
|
+
|
72
|
+
function Scanner(string) {
|
73
|
+
this.string = string;
|
74
|
+
this.tail = string;
|
75
|
+
this.pos = 0;
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Returns `true` if the tail is empty (end of string).
|
80
|
+
*/
|
81
|
+
Scanner.prototype.eos = function () {
|
82
|
+
return this.tail === "";
|
83
|
+
};
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Tries to match the given regular expression at the current position.
|
87
|
+
* Returns the matched text if it can match, the empty string otherwise.
|
88
|
+
*/
|
89
|
+
Scanner.prototype.scan = function (re) {
|
90
|
+
var match = this.tail.match(re);
|
91
|
+
|
92
|
+
if (match && match.index === 0) {
|
93
|
+
this.tail = this.tail.substring(match[0].length);
|
94
|
+
this.pos += match[0].length;
|
95
|
+
return match[0];
|
96
|
+
}
|
97
|
+
|
98
|
+
return "";
|
99
|
+
};
|
100
|
+
|
101
|
+
/**
|
102
|
+
* Skips all text until the given regular expression can be matched. Returns
|
103
|
+
* the skipped string, which is the entire tail if no match can be made.
|
104
|
+
*/
|
105
|
+
Scanner.prototype.scanUntil = function (re) {
|
106
|
+
var match, pos = this.tail.search(re);
|
107
|
+
|
108
|
+
switch (pos) {
|
109
|
+
case -1:
|
110
|
+
match = this.tail;
|
111
|
+
this.pos += this.tail.length;
|
112
|
+
this.tail = "";
|
113
|
+
break;
|
114
|
+
case 0:
|
115
|
+
match = "";
|
116
|
+
break;
|
117
|
+
default:
|
118
|
+
match = this.tail.substring(0, pos);
|
119
|
+
this.tail = this.tail.substring(pos);
|
120
|
+
this.pos += pos;
|
121
|
+
}
|
122
|
+
|
123
|
+
return match;
|
124
|
+
};
|
125
|
+
|
126
|
+
function Context(view, parent) {
|
127
|
+
this.view = view;
|
128
|
+
this.parent = parent;
|
129
|
+
this._cache = {};
|
130
|
+
}
|
131
|
+
|
132
|
+
Context.make = function (view) {
|
133
|
+
return (view instanceof Context) ? view : new Context(view);
|
134
|
+
};
|
135
|
+
|
136
|
+
Context.prototype.push = function (view) {
|
137
|
+
return new Context(view, this);
|
138
|
+
};
|
139
|
+
|
140
|
+
Context.prototype.lookup = function (name) {
|
141
|
+
var value = this._cache[name];
|
142
|
+
|
143
|
+
if (!value) {
|
144
|
+
if (name == '.') {
|
145
|
+
value = this.view;
|
146
|
+
} else {
|
147
|
+
var context = this;
|
148
|
+
|
149
|
+
while (context) {
|
150
|
+
if (name.indexOf('.') > 0) {
|
151
|
+
value = context.view;
|
152
|
+
var names = name.split('.'), i = 0;
|
153
|
+
while (value && i < names.length) {
|
154
|
+
value = value[names[i++]];
|
155
|
+
}
|
156
|
+
} else {
|
157
|
+
value = context.view[name];
|
158
|
+
}
|
159
|
+
|
160
|
+
if (value != null) break;
|
161
|
+
|
162
|
+
context = context.parent;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
this._cache[name] = value;
|
167
|
+
}
|
168
|
+
|
169
|
+
if (typeof value === 'function') value = value.call(this.view);
|
170
|
+
|
171
|
+
return value;
|
172
|
+
};
|
173
|
+
|
174
|
+
function Writer() {
|
175
|
+
this.clearCache();
|
176
|
+
}
|
177
|
+
|
178
|
+
Writer.prototype.clearCache = function () {
|
179
|
+
this._cache = {};
|
180
|
+
this._partialCache = {};
|
181
|
+
};
|
182
|
+
|
183
|
+
Writer.prototype.compile = function (template, tags) {
|
184
|
+
var fn = this._cache[template];
|
185
|
+
|
186
|
+
if (!fn) {
|
187
|
+
var tokens = exports.parse(template, tags);
|
188
|
+
fn = this._cache[template] = this.compileTokens(tokens, template);
|
189
|
+
}
|
190
|
+
|
191
|
+
return fn;
|
192
|
+
};
|
193
|
+
|
194
|
+
Writer.prototype.compilePartial = function (name, template, tags) {
|
195
|
+
var fn = this.compile(template, tags);
|
196
|
+
this._partialCache[name] = fn;
|
197
|
+
return fn;
|
198
|
+
};
|
199
|
+
|
200
|
+
Writer.prototype.getPartial = function (name) {
|
201
|
+
if (!(name in this._partialCache) && this._loadPartial) {
|
202
|
+
this.compilePartial(name, this._loadPartial(name));
|
203
|
+
}
|
204
|
+
|
205
|
+
return this._partialCache[name];
|
206
|
+
};
|
207
|
+
|
208
|
+
Writer.prototype.compileTokens = function (tokens, template) {
|
209
|
+
var self = this;
|
210
|
+
return function (view, partials) {
|
211
|
+
if (partials) {
|
212
|
+
if (typeof partials === 'function') {
|
213
|
+
self._loadPartial = partials;
|
214
|
+
} else {
|
215
|
+
for (var name in partials) {
|
216
|
+
self.compilePartial(name, partials[name]);
|
217
|
+
}
|
218
|
+
}
|
219
|
+
}
|
220
|
+
|
221
|
+
return renderTokens(tokens, self, Context.make(view), template);
|
222
|
+
};
|
223
|
+
};
|
224
|
+
|
225
|
+
Writer.prototype.render = function (template, view, partials) {
|
226
|
+
return this.compile(template)(view, partials);
|
227
|
+
};
|
228
|
+
|
229
|
+
/**
|
230
|
+
* Low-level function that renders the given `tokens` using the given `writer`
|
231
|
+
* and `context`. The `template` string is only needed for templates that use
|
232
|
+
* higher-order sections to extract the portion of the original template that
|
233
|
+
* was contained in that section.
|
234
|
+
*/
|
235
|
+
function renderTokens(tokens, writer, context, template) {
|
236
|
+
var buffer = '';
|
237
|
+
|
238
|
+
var token, tokenValue, value;
|
239
|
+
for (var i = 0, len = tokens.length; i < len; ++i) {
|
240
|
+
token = tokens[i];
|
241
|
+
tokenValue = token[1];
|
242
|
+
|
243
|
+
switch (token[0]) {
|
244
|
+
case '#':
|
245
|
+
value = context.lookup(tokenValue);
|
246
|
+
|
247
|
+
if (typeof value === 'object') {
|
248
|
+
if (isArray(value)) {
|
249
|
+
for (var j = 0, jlen = value.length; j < jlen; ++j) {
|
250
|
+
buffer += renderTokens(token[4], writer, context.push(value[j]), template);
|
251
|
+
}
|
252
|
+
} else if (value) {
|
253
|
+
buffer += renderTokens(token[4], writer, context.push(value), template);
|
254
|
+
}
|
255
|
+
} else if (typeof value === 'function') {
|
256
|
+
var text = template == null ? null : template.slice(token[3], token[5]);
|
257
|
+
value = value.call(context.view, text, function (template) {
|
258
|
+
return writer.render(template, context);
|
259
|
+
});
|
260
|
+
if (value != null) buffer += value;
|
261
|
+
} else if (value) {
|
262
|
+
buffer += renderTokens(token[4], writer, context, template);
|
263
|
+
}
|
264
|
+
|
265
|
+
break;
|
266
|
+
case '^':
|
267
|
+
value = context.lookup(tokenValue);
|
268
|
+
|
269
|
+
// Use JavaScript's definition of falsy. Include empty arrays.
|
270
|
+
// See https://github.com/janl/mustache.js/issues/186
|
271
|
+
if (!value || (isArray(value) && value.length === 0)) {
|
272
|
+
buffer += renderTokens(token[4], writer, context, template);
|
273
|
+
}
|
274
|
+
|
275
|
+
break;
|
276
|
+
case '>':
|
277
|
+
value = writer.getPartial(tokenValue);
|
278
|
+
if (typeof value === 'function') buffer += value(context);
|
279
|
+
break;
|
280
|
+
case '&':
|
281
|
+
value = context.lookup(tokenValue);
|
282
|
+
if (value != null) buffer += value;
|
283
|
+
break;
|
284
|
+
case 'name':
|
285
|
+
value = context.lookup(tokenValue);
|
286
|
+
if (value != null) buffer += exports.escape(value);
|
287
|
+
break;
|
288
|
+
case 'text':
|
289
|
+
buffer += tokenValue;
|
290
|
+
break;
|
291
|
+
}
|
292
|
+
}
|
293
|
+
|
294
|
+
return buffer;
|
295
|
+
}
|
296
|
+
|
297
|
+
/**
|
298
|
+
* Forms the given array of `tokens` into a nested tree structure where
|
299
|
+
* tokens that represent a section have two additional items: 1) an array of
|
300
|
+
* all tokens that appear in that section and 2) the index in the original
|
301
|
+
* template that represents the end of that section.
|
302
|
+
*/
|
303
|
+
function nestTokens(tokens) {
|
304
|
+
var tree = [];
|
305
|
+
var collector = tree;
|
306
|
+
var sections = [];
|
307
|
+
|
308
|
+
var token;
|
309
|
+
for (var i = 0, len = tokens.length; i < len; ++i) {
|
310
|
+
token = tokens[i];
|
311
|
+
switch (token[0]) {
|
312
|
+
case '#':
|
313
|
+
case '^':
|
314
|
+
sections.push(token);
|
315
|
+
collector.push(token);
|
316
|
+
collector = token[4] = [];
|
317
|
+
break;
|
318
|
+
case '/':
|
319
|
+
var section = sections.pop();
|
320
|
+
section[5] = token[2];
|
321
|
+
collector = sections.length > 0 ? sections[sections.length - 1][4] : tree;
|
322
|
+
break;
|
323
|
+
default:
|
324
|
+
collector.push(token);
|
325
|
+
}
|
326
|
+
}
|
327
|
+
|
328
|
+
return tree;
|
329
|
+
}
|
330
|
+
|
331
|
+
/**
|
332
|
+
* Combines the values of consecutive text tokens in the given `tokens` array
|
333
|
+
* to a single token.
|
334
|
+
*/
|
335
|
+
function squashTokens(tokens) {
|
336
|
+
var squashedTokens = [];
|
337
|
+
|
338
|
+
var token, lastToken;
|
339
|
+
for (var i = 0, len = tokens.length; i < len; ++i) {
|
340
|
+
token = tokens[i];
|
341
|
+
if (token) {
|
342
|
+
if (token[0] === 'text' && lastToken && lastToken[0] === 'text') {
|
343
|
+
lastToken[1] += token[1];
|
344
|
+
lastToken[3] = token[3];
|
345
|
+
} else {
|
346
|
+
lastToken = token;
|
347
|
+
squashedTokens.push(token);
|
348
|
+
}
|
349
|
+
}
|
350
|
+
}
|
351
|
+
|
352
|
+
return squashedTokens;
|
353
|
+
}
|
354
|
+
|
355
|
+
function escapeTags(tags) {
|
356
|
+
return [
|
357
|
+
new RegExp(escapeRe(tags[0]) + "\\s*"),
|
358
|
+
new RegExp("\\s*" + escapeRe(tags[1]))
|
359
|
+
];
|
360
|
+
}
|
361
|
+
|
362
|
+
/**
|
363
|
+
* Breaks up the given `template` string into a tree of token objects. If
|
364
|
+
* `tags` is given here it must be an array with two string values: the
|
365
|
+
* opening and closing tags used in the template (e.g. ["<%", "%>"]). Of
|
366
|
+
* course, the default is to use mustaches (i.e. Mustache.tags).
|
367
|
+
*/
|
368
|
+
exports.parse = function (template, tags) {
|
369
|
+
template = template || '';
|
370
|
+
tags = tags || exports.tags;
|
371
|
+
|
372
|
+
if (typeof tags === 'string') tags = tags.split(spaceRe);
|
373
|
+
if (tags.length !== 2) throw new Error('Invalid tags: ' + tags.join(', '));
|
374
|
+
|
375
|
+
var tagRes = escapeTags(tags);
|
376
|
+
var scanner = new Scanner(template);
|
377
|
+
|
378
|
+
var sections = []; // Stack to hold section tokens
|
379
|
+
var tokens = []; // Buffer to hold the tokens
|
380
|
+
var spaces = []; // Indices of whitespace tokens on the current line
|
381
|
+
var hasTag = false; // Is there a {{tag}} on the current line?
|
382
|
+
var nonSpace = false; // Is there a non-space char on the current line?
|
383
|
+
|
384
|
+
// Strips all whitespace tokens array for the current line
|
385
|
+
// if there was a {{#tag}} on it and otherwise only space.
|
386
|
+
function stripSpace() {
|
387
|
+
if (hasTag && !nonSpace) {
|
388
|
+
while (spaces.length) {
|
389
|
+
delete tokens[spaces.pop()];
|
390
|
+
}
|
391
|
+
} else {
|
392
|
+
spaces = [];
|
393
|
+
}
|
394
|
+
|
395
|
+
hasTag = false;
|
396
|
+
nonSpace = false;
|
397
|
+
}
|
398
|
+
|
399
|
+
var start, type, value, chr, token;
|
400
|
+
while (!scanner.eos()) {
|
401
|
+
start = scanner.pos;
|
402
|
+
|
403
|
+
// Match any text between tags.
|
404
|
+
value = scanner.scanUntil(tagRes[0]);
|
405
|
+
if (value) {
|
406
|
+
for (var i = 0, len = value.length; i < len; ++i) {
|
407
|
+
chr = value.charAt(i);
|
408
|
+
|
409
|
+
if (isWhitespace(chr)) {
|
410
|
+
spaces.push(tokens.length);
|
411
|
+
} else {
|
412
|
+
nonSpace = true;
|
413
|
+
}
|
414
|
+
|
415
|
+
tokens.push(['text', chr, start, start + 1]);
|
416
|
+
start += 1;
|
417
|
+
|
418
|
+
// Check for whitespace on the current line.
|
419
|
+
if (chr == '\n') stripSpace();
|
420
|
+
}
|
421
|
+
}
|
422
|
+
|
423
|
+
// Match the opening tag.
|
424
|
+
if (!scanner.scan(tagRes[0])) break;
|
425
|
+
hasTag = true;
|
426
|
+
|
427
|
+
// Get the tag type.
|
428
|
+
type = scanner.scan(tagRe) || 'name';
|
429
|
+
scanner.scan(whiteRe);
|
430
|
+
|
431
|
+
// Get the tag value.
|
432
|
+
if (type === '=') {
|
433
|
+
value = scanner.scanUntil(eqRe);
|
434
|
+
scanner.scan(eqRe);
|
435
|
+
scanner.scanUntil(tagRes[1]);
|
436
|
+
} else if (type === '{') {
|
437
|
+
value = scanner.scanUntil(new RegExp('\\s*' + escapeRe('}' + tags[1])));
|
438
|
+
scanner.scan(curlyRe);
|
439
|
+
scanner.scanUntil(tagRes[1]);
|
440
|
+
type = '&';
|
441
|
+
} else {
|
442
|
+
value = scanner.scanUntil(tagRes[1]);
|
443
|
+
}
|
444
|
+
|
445
|
+
// Match the closing tag.
|
446
|
+
if (!scanner.scan(tagRes[1])) throw new Error('Unclosed tag at ' + scanner.pos);
|
447
|
+
|
448
|
+
token = [type, value, start, scanner.pos];
|
449
|
+
tokens.push(token);
|
450
|
+
|
451
|
+
if (type === '#' || type === '^') {
|
452
|
+
sections.push(token);
|
453
|
+
} else if (type === '/') {
|
454
|
+
// Check section nesting.
|
455
|
+
if (sections.length === 0) throw new Error('Unopened section "' + value + '" at ' + start);
|
456
|
+
var openSection = sections.pop();
|
457
|
+
if (openSection[1] !== value) throw new Error('Unclosed section "' + openSection[1] + '" at ' + start);
|
458
|
+
} else if (type === 'name' || type === '{' || type === '&') {
|
459
|
+
nonSpace = true;
|
460
|
+
} else if (type === '=') {
|
461
|
+
// Set the tags for the next time around.
|
462
|
+
tags = value.split(spaceRe);
|
463
|
+
if (tags.length !== 2) throw new Error('Invalid tags at ' + start + ': ' + tags.join(', '));
|
464
|
+
tagRes = escapeTags(tags);
|
465
|
+
}
|
466
|
+
}
|
467
|
+
|
468
|
+
// Make sure there are no open sections when we're done.
|
469
|
+
var openSection = sections.pop();
|
470
|
+
if (openSection) throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos);
|
471
|
+
|
472
|
+
tokens = squashTokens(tokens);
|
473
|
+
|
474
|
+
return nestTokens(tokens);
|
475
|
+
};
|
476
|
+
|
477
|
+
// All Mustache.* functions use this writer.
|
478
|
+
var _writer = new Writer();
|
479
|
+
|
480
|
+
/**
|
481
|
+
* Clears all cached templates and partials in the default writer.
|
482
|
+
*/
|
483
|
+
exports.clearCache = function () {
|
484
|
+
return _writer.clearCache();
|
485
|
+
};
|
486
|
+
|
487
|
+
/**
|
488
|
+
* Compiles the given `template` to a reusable function using the default
|
489
|
+
* writer.
|
490
|
+
*/
|
491
|
+
exports.compile = function (template, tags) {
|
492
|
+
return _writer.compile(template, tags);
|
493
|
+
};
|
494
|
+
|
495
|
+
/**
|
496
|
+
* Compiles the partial with the given `name` and `template` to a reusable
|
497
|
+
* function using the default writer.
|
498
|
+
*/
|
499
|
+
exports.compilePartial = function (name, template, tags) {
|
500
|
+
return _writer.compilePartial(name, template, tags);
|
501
|
+
};
|
502
|
+
|
503
|
+
/**
|
504
|
+
* Compiles the given array of tokens (the output of a parse) to a reusable
|
505
|
+
* function using the default writer.
|
506
|
+
*/
|
507
|
+
exports.compileTokens = function (tokens, template) {
|
508
|
+
return _writer.compileTokens(tokens, template);
|
509
|
+
};
|
510
|
+
|
511
|
+
/**
|
512
|
+
* Renders the `template` with the given `view` and `partials` using the
|
513
|
+
* default writer.
|
514
|
+
*/
|
515
|
+
exports.render = function (template, view, partials) {
|
516
|
+
return _writer.render(template, view, partials);
|
517
|
+
};
|
518
|
+
|
519
|
+
// This is here for backwards compatibility with 0.4.x.
|
520
|
+
exports.to_html = function (template, view, partials, send) {
|
521
|
+
var result = exports.render(template, view, partials);
|
522
|
+
|
523
|
+
if (typeof send === "function") {
|
524
|
+
send(result);
|
525
|
+
} else {
|
526
|
+
return result;
|
527
|
+
}
|
528
|
+
};
|
529
|
+
|
530
|
+
return exports;
|
531
|
+
|
532
|
+
}())));
|