mustachejs-rails 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mustachejs/rails/version.rb +1 -1
- data/vendor/assets/javascripts/mustache.js +195 -254
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30b027e628a3d7cb5eb041fb73b787e0a1f475fb
|
4
|
+
data.tar.gz: 066a7094d0c64d2c6ab7893b24015dbba11828e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c8436eaf5e16de466152fa90e8a567cce981a49383d82d47233af25556541e98f481ae1f238fe9f8f4e3b496407f527b4455716dbe334cb791207434dd64b83
|
7
|
+
data.tar.gz: b5090be7f8eac1ea1627eee6542000cc5e8f9216cf9c039e2fd1d5589b7cec8851b0e7b8dcafc2c58fcef58e4d11ff2195d633acf581eeb376b54d80ac4c0b2b
|
@@ -7,23 +7,17 @@
|
|
7
7
|
|
8
8
|
(function (root, factory) {
|
9
9
|
if (typeof exports === "object" && exports) {
|
10
|
-
|
11
|
-
} else if (typeof define === "function" && define.amd) {
|
12
|
-
define(factory); // AMD
|
10
|
+
factory(exports); // CommonJS
|
13
11
|
} else {
|
14
|
-
|
12
|
+
var mustache = {};
|
13
|
+
factory(mustache);
|
14
|
+
if (typeof define === "function" && define.amd) {
|
15
|
+
define(mustache); // AMD
|
16
|
+
} else {
|
17
|
+
root.Mustache = mustache; // <script>
|
18
|
+
}
|
15
19
|
}
|
16
|
-
}(this,
|
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;
|
20
|
+
}(this, function (mustache) {
|
27
21
|
|
28
22
|
var whiteRe = /\s*/;
|
29
23
|
var spaceRe = /\s+/;
|
@@ -34,19 +28,25 @@
|
|
34
28
|
|
35
29
|
// Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
|
36
30
|
// See https://github.com/janl/mustache.js/issues/189
|
37
|
-
|
38
|
-
|
31
|
+
var RegExp_test = RegExp.prototype.test;
|
32
|
+
function testRegExp(re, string) {
|
33
|
+
return RegExp_test.call(re, string);
|
39
34
|
}
|
40
35
|
|
41
36
|
function isWhitespace(string) {
|
42
|
-
return !
|
37
|
+
return !testRegExp(nonSpaceRe, string);
|
43
38
|
}
|
44
39
|
|
45
|
-
var
|
46
|
-
|
40
|
+
var Object_toString = Object.prototype.toString;
|
41
|
+
var isArray = Array.isArray || function (object) {
|
42
|
+
return Object_toString.call(object) === '[object Array]';
|
47
43
|
};
|
48
44
|
|
49
|
-
function
|
45
|
+
function isFunction(object) {
|
46
|
+
return typeof object === 'function';
|
47
|
+
}
|
48
|
+
|
49
|
+
function escapeRegExp(string) {
|
50
50
|
return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
|
51
51
|
}
|
52
52
|
|
@@ -65,10 +65,6 @@
|
|
65
65
|
});
|
66
66
|
}
|
67
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
68
|
function Scanner(string) {
|
73
69
|
this.string = string;
|
74
70
|
this.tail = string;
|
@@ -90,9 +86,10 @@
|
|
90
86
|
var match = this.tail.match(re);
|
91
87
|
|
92
88
|
if (match && match.index === 0) {
|
93
|
-
|
94
|
-
this.
|
95
|
-
|
89
|
+
var string = match[0];
|
90
|
+
this.tail = this.tail.substring(string.length);
|
91
|
+
this.pos += string.length;
|
92
|
+
return string;
|
96
93
|
}
|
97
94
|
|
98
95
|
return "";
|
@@ -103,78 +100,68 @@
|
|
103
100
|
* the skipped string, which is the entire tail if no match can be made.
|
104
101
|
*/
|
105
102
|
Scanner.prototype.scanUntil = function (re) {
|
106
|
-
var
|
103
|
+
var index = this.tail.search(re), match;
|
107
104
|
|
108
|
-
switch (
|
105
|
+
switch (index) {
|
109
106
|
case -1:
|
110
107
|
match = this.tail;
|
111
|
-
this.pos += this.tail.length;
|
112
108
|
this.tail = "";
|
113
109
|
break;
|
114
110
|
case 0:
|
115
111
|
match = "";
|
116
112
|
break;
|
117
113
|
default:
|
118
|
-
match = this.tail.substring(0,
|
119
|
-
this.tail = this.tail.substring(
|
120
|
-
this.pos += pos;
|
114
|
+
match = this.tail.substring(0, index);
|
115
|
+
this.tail = this.tail.substring(index);
|
121
116
|
}
|
122
117
|
|
118
|
+
this.pos += match.length;
|
119
|
+
|
123
120
|
return match;
|
124
121
|
};
|
125
122
|
|
126
123
|
function Context(view, parent) {
|
127
|
-
this.view = view;
|
124
|
+
this.view = view == null ? {} : view;
|
128
125
|
this.parent = parent;
|
129
|
-
this.
|
126
|
+
this._cache = { '.': this.view };
|
130
127
|
}
|
131
128
|
|
132
129
|
Context.make = function (view) {
|
133
130
|
return (view instanceof Context) ? view : new Context(view);
|
134
131
|
};
|
135
132
|
|
136
|
-
Context.prototype.clearCache = function () {
|
137
|
-
this._cache = {};
|
138
|
-
};
|
139
|
-
|
140
133
|
Context.prototype.push = function (view) {
|
141
134
|
return new Context(view, this);
|
142
135
|
};
|
143
136
|
|
144
137
|
Context.prototype.lookup = function (name) {
|
145
|
-
var value
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
} else {
|
151
|
-
var context = this;
|
152
|
-
|
153
|
-
while (context) {
|
154
|
-
if (name.indexOf(".") > 0) {
|
155
|
-
var names = name.split("."), i = 0;
|
138
|
+
var value;
|
139
|
+
if (name in this._cache) {
|
140
|
+
value = this._cache[name];
|
141
|
+
} else {
|
142
|
+
var context = this;
|
156
143
|
|
157
|
-
|
144
|
+
while (context) {
|
145
|
+
if (name.indexOf('.') > 0) {
|
146
|
+
value = context.view;
|
158
147
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
} else {
|
163
|
-
value = context.view[name];
|
148
|
+
var names = name.split('.'), i = 0;
|
149
|
+
while (value != null && i < names.length) {
|
150
|
+
value = value[names[i++]];
|
164
151
|
}
|
152
|
+
} else {
|
153
|
+
value = context.view[name];
|
154
|
+
}
|
165
155
|
|
166
|
-
|
167
|
-
break;
|
168
|
-
}
|
156
|
+
if (value != null) break;
|
169
157
|
|
170
|
-
|
171
|
-
}
|
158
|
+
context = context.parent;
|
172
159
|
}
|
173
160
|
|
174
161
|
this._cache[name] = value;
|
175
162
|
}
|
176
163
|
|
177
|
-
if (
|
164
|
+
if (isFunction(value)) {
|
178
165
|
value = value.call(this.view);
|
179
166
|
}
|
180
167
|
|
@@ -194,7 +181,7 @@
|
|
194
181
|
var fn = this._cache[template];
|
195
182
|
|
196
183
|
if (!fn) {
|
197
|
-
var tokens =
|
184
|
+
var tokens = mustache.parse(template, tags);
|
198
185
|
fn = this._cache[template] = this.compileTokens(tokens, template);
|
199
186
|
}
|
200
187
|
|
@@ -207,13 +194,19 @@
|
|
207
194
|
return fn;
|
208
195
|
};
|
209
196
|
|
197
|
+
Writer.prototype.getPartial = function (name) {
|
198
|
+
if (!(name in this._partialCache) && this._loadPartial) {
|
199
|
+
this.compilePartial(name, this._loadPartial(name));
|
200
|
+
}
|
201
|
+
|
202
|
+
return this._partialCache[name];
|
203
|
+
};
|
204
|
+
|
210
205
|
Writer.prototype.compileTokens = function (tokens, template) {
|
211
|
-
var fn = compileTokens(tokens);
|
212
206
|
var self = this;
|
213
|
-
|
214
207
|
return function (view, partials) {
|
215
208
|
if (partials) {
|
216
|
-
if (
|
209
|
+
if (isFunction(partials)) {
|
217
210
|
self._loadPartial = partials;
|
218
211
|
} else {
|
219
212
|
for (var name in partials) {
|
@@ -222,7 +215,7 @@
|
|
222
215
|
}
|
223
216
|
}
|
224
217
|
|
225
|
-
return
|
218
|
+
return renderTokens(tokens, self, Context.make(view), template);
|
226
219
|
};
|
227
220
|
};
|
228
221
|
|
@@ -230,125 +223,76 @@
|
|
230
223
|
return this.compile(template)(view, partials);
|
231
224
|
};
|
232
225
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
for (var i = 0, len = value.length; i < len; ++i) {
|
242
|
-
buffer += callback(this, context.push(value[i]));
|
243
|
-
}
|
244
|
-
|
245
|
-
return buffer;
|
246
|
-
}
|
247
|
-
|
248
|
-
return value ? callback(this, context.push(value)) : "";
|
249
|
-
case "function":
|
250
|
-
var self = this;
|
251
|
-
var scopedRender = function (template) {
|
252
|
-
return self.render(template, context);
|
253
|
-
};
|
254
|
-
|
255
|
-
var result = value.call(context.view, text, scopedRender);
|
256
|
-
return result != null ? result : "";
|
257
|
-
default:
|
258
|
-
if (value) {
|
259
|
-
return callback(this, context);
|
260
|
-
}
|
261
|
-
}
|
262
|
-
|
263
|
-
return "";
|
264
|
-
};
|
265
|
-
|
266
|
-
Writer.prototype._inverted = function (name, context, callback) {
|
267
|
-
var value = context.lookup(name);
|
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
|
-
return callback(this, context);
|
273
|
-
}
|
274
|
-
|
275
|
-
return "";
|
276
|
-
};
|
226
|
+
/**
|
227
|
+
* Low-level function that renders the given `tokens` using the given `writer`
|
228
|
+
* and `context`. The `template` string is only needed for templates that use
|
229
|
+
* higher-order sections to extract the portion of the original template that
|
230
|
+
* was contained in that section.
|
231
|
+
*/
|
232
|
+
function renderTokens(tokens, writer, context, template) {
|
233
|
+
var buffer = '';
|
277
234
|
|
278
|
-
|
279
|
-
|
280
|
-
|
235
|
+
// This function is used to render an artbitrary template
|
236
|
+
// in the current context by higher-order functions.
|
237
|
+
function subRender(template) {
|
238
|
+
return writer.render(template, context);
|
281
239
|
}
|
282
240
|
|
283
|
-
var
|
284
|
-
|
285
|
-
|
286
|
-
|
241
|
+
var token, tokenValue, value;
|
242
|
+
for (var i = 0, len = tokens.length; i < len; ++i) {
|
243
|
+
token = tokens[i];
|
244
|
+
tokenValue = token[1];
|
287
245
|
|
288
|
-
|
289
|
-
|
246
|
+
switch (token[0]) {
|
247
|
+
case '#':
|
248
|
+
value = context.lookup(tokenValue);
|
290
249
|
|
291
|
-
|
292
|
-
|
293
|
-
|
250
|
+
if (typeof value === 'object' || typeof value === 'string') {
|
251
|
+
if (isArray(value)) {
|
252
|
+
for (var j = 0, jlen = value.length; j < jlen; ++j) {
|
253
|
+
buffer += renderTokens(token[4], writer, context.push(value[j]), template);
|
254
|
+
}
|
255
|
+
} else if (value) {
|
256
|
+
buffer += renderTokens(token[4], writer, context.push(value), template);
|
257
|
+
}
|
258
|
+
} else if (isFunction(value)) {
|
259
|
+
var text = template == null ? null : template.slice(token[3], token[5]);
|
260
|
+
value = value.call(context.view, text, subRender);
|
261
|
+
if (value != null) buffer += value;
|
262
|
+
} else if (value) {
|
263
|
+
buffer += renderTokens(token[4], writer, context, template);
|
264
|
+
}
|
294
265
|
|
295
|
-
|
296
|
-
|
266
|
+
break;
|
267
|
+
case '^':
|
268
|
+
value = context.lookup(tokenValue);
|
297
269
|
|
298
|
-
|
299
|
-
|
300
|
-
|
270
|
+
// Use JavaScript's definition of falsy. Include empty arrays.
|
271
|
+
// See https://github.com/janl/mustache.js/issues/186
|
272
|
+
if (!value || (isArray(value) && value.length === 0)) {
|
273
|
+
buffer += renderTokens(token[4], writer, context, template);
|
274
|
+
}
|
301
275
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
276
|
+
break;
|
277
|
+
case '>':
|
278
|
+
value = writer.getPartial(tokenValue);
|
279
|
+
if (isFunction(value)) buffer += value(context);
|
280
|
+
break;
|
281
|
+
case '&':
|
282
|
+
value = context.lookup(tokenValue);
|
283
|
+
if (value != null) buffer += value;
|
284
|
+
break;
|
285
|
+
case 'name':
|
286
|
+
value = context.lookup(tokenValue);
|
287
|
+
if (value != null) buffer += mustache.escape(value);
|
288
|
+
break;
|
289
|
+
case 'text':
|
290
|
+
buffer += tokenValue;
|
291
|
+
break;
|
315
292
|
}
|
316
|
-
|
317
|
-
return subRenders[i];
|
318
293
|
}
|
319
294
|
|
320
|
-
return
|
321
|
-
var buffer = "";
|
322
|
-
var token, sectionText;
|
323
|
-
|
324
|
-
for (var i = 0, len = tokens.length; i < len; ++i) {
|
325
|
-
token = tokens[i];
|
326
|
-
|
327
|
-
switch (token[0]) {
|
328
|
-
case "#":
|
329
|
-
sectionText = template.slice(token[3], token[5]);
|
330
|
-
buffer += writer._section(token[1], context, sectionText, subRender(i, token[4], template));
|
331
|
-
break;
|
332
|
-
case "^":
|
333
|
-
buffer += writer._inverted(token[1], context, subRender(i, token[4], template));
|
334
|
-
break;
|
335
|
-
case ">":
|
336
|
-
buffer += writer._partial(token[1], context);
|
337
|
-
break;
|
338
|
-
case "&":
|
339
|
-
buffer += writer._name(token[1], context);
|
340
|
-
break;
|
341
|
-
case "name":
|
342
|
-
buffer += writer._escaped(token[1], context);
|
343
|
-
break;
|
344
|
-
case "text":
|
345
|
-
buffer += token[1];
|
346
|
-
break;
|
347
|
-
}
|
348
|
-
}
|
349
|
-
|
350
|
-
return buffer;
|
351
|
-
};
|
295
|
+
return buffer;
|
352
296
|
}
|
353
297
|
|
354
298
|
/**
|
@@ -395,12 +339,14 @@
|
|
395
339
|
var token, lastToken;
|
396
340
|
for (var i = 0, len = tokens.length; i < len; ++i) {
|
397
341
|
token = tokens[i];
|
398
|
-
if (token
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
342
|
+
if (token) {
|
343
|
+
if (token[0] === 'text' && lastToken && lastToken[0] === 'text') {
|
344
|
+
lastToken[1] += token[1];
|
345
|
+
lastToken[3] = token[3];
|
346
|
+
} else {
|
347
|
+
lastToken = token;
|
348
|
+
squashedTokens.push(token);
|
349
|
+
}
|
404
350
|
}
|
405
351
|
}
|
406
352
|
|
@@ -409,8 +355,8 @@
|
|
409
355
|
|
410
356
|
function escapeTags(tags) {
|
411
357
|
return [
|
412
|
-
new RegExp(
|
413
|
-
new RegExp("\\s*" +
|
358
|
+
new RegExp(escapeRegExp(tags[0]) + "\\s*"),
|
359
|
+
new RegExp("\\s*" + escapeRegExp(tags[1]))
|
414
360
|
];
|
415
361
|
}
|
416
362
|
|
@@ -420,14 +366,12 @@
|
|
420
366
|
* opening and closing tags used in the template (e.g. ["<%", "%>"]). Of
|
421
367
|
* course, the default is to use mustaches (i.e. Mustache.tags).
|
422
368
|
*/
|
423
|
-
|
369
|
+
function parseTemplate(template, tags) {
|
424
370
|
template = template || '';
|
425
|
-
tags = tags ||
|
371
|
+
tags = tags || mustache.tags;
|
426
372
|
|
427
373
|
if (typeof tags === 'string') tags = tags.split(spaceRe);
|
428
|
-
if (tags.length !== 2)
|
429
|
-
throw new Error('Invalid tags: ' + tags.join(', '));
|
430
|
-
}
|
374
|
+
if (tags.length !== 2) throw new Error('Invalid tags: ' + tags.join(', '));
|
431
375
|
|
432
376
|
var tagRes = escapeTags(tags);
|
433
377
|
var scanner = new Scanner(template);
|
@@ -443,7 +387,7 @@
|
|
443
387
|
function stripSpace() {
|
444
388
|
if (hasTag && !nonSpace) {
|
445
389
|
while (spaces.length) {
|
446
|
-
tokens
|
390
|
+
delete tokens[spaces.pop()];
|
447
391
|
}
|
448
392
|
} else {
|
449
393
|
spaces = [];
|
@@ -453,11 +397,12 @@
|
|
453
397
|
nonSpace = false;
|
454
398
|
}
|
455
399
|
|
456
|
-
var start, type, value, chr;
|
400
|
+
var start, type, value, chr, token, openSection;
|
457
401
|
while (!scanner.eos()) {
|
458
402
|
start = scanner.pos;
|
459
|
-
value = scanner.scanUntil(tagRes[0]);
|
460
403
|
|
404
|
+
// Match any text between tags.
|
405
|
+
value = scanner.scanUntil(tagRes[0]);
|
461
406
|
if (value) {
|
462
407
|
for (var i = 0, len = value.length; i < len; ++i) {
|
463
408
|
chr = value.charAt(i);
|
@@ -468,143 +413,139 @@
|
|
468
413
|
nonSpace = true;
|
469
414
|
}
|
470
415
|
|
471
|
-
tokens.push([
|
416
|
+
tokens.push(['text', chr, start, start + 1]);
|
472
417
|
start += 1;
|
473
418
|
|
474
|
-
|
475
|
-
|
476
|
-
}
|
419
|
+
// Check for whitespace on the current line.
|
420
|
+
if (chr == '\n') stripSpace();
|
477
421
|
}
|
478
422
|
}
|
479
423
|
|
480
|
-
start = scanner.pos;
|
481
|
-
|
482
424
|
// Match the opening tag.
|
483
|
-
if (!scanner.scan(tagRes[0]))
|
484
|
-
break;
|
485
|
-
}
|
486
|
-
|
425
|
+
if (!scanner.scan(tagRes[0])) break;
|
487
426
|
hasTag = true;
|
488
|
-
type = scanner.scan(tagRe) || "name";
|
489
427
|
|
490
|
-
//
|
428
|
+
// Get the tag type.
|
429
|
+
type = scanner.scan(tagRe) || 'name';
|
491
430
|
scanner.scan(whiteRe);
|
492
431
|
|
493
|
-
//
|
494
|
-
if (type ===
|
432
|
+
// Get the tag value.
|
433
|
+
if (type === '=') {
|
495
434
|
value = scanner.scanUntil(eqRe);
|
496
435
|
scanner.scan(eqRe);
|
497
436
|
scanner.scanUntil(tagRes[1]);
|
498
|
-
} else if (type ===
|
499
|
-
|
500
|
-
value = scanner.scanUntil(closeRe);
|
437
|
+
} else if (type === '{') {
|
438
|
+
value = scanner.scanUntil(new RegExp('\\s*' + escapeRegExp('}' + tags[1])));
|
501
439
|
scanner.scan(curlyRe);
|
502
440
|
scanner.scanUntil(tagRes[1]);
|
503
|
-
type =
|
441
|
+
type = '&';
|
504
442
|
} else {
|
505
443
|
value = scanner.scanUntil(tagRes[1]);
|
506
444
|
}
|
507
445
|
|
508
446
|
// Match the closing tag.
|
509
|
-
if (!scanner.scan(tagRes[1]))
|
510
|
-
throw new Error('Unclosed tag at ' + scanner.pos);
|
511
|
-
}
|
512
|
-
|
513
|
-
// Check section nesting.
|
514
|
-
if (type === '/') {
|
515
|
-
if (sections.length === 0) {
|
516
|
-
throw new Error('Unopened section "' + value + '" at ' + start);
|
517
|
-
}
|
518
|
-
|
519
|
-
var section = sections.pop();
|
520
|
-
|
521
|
-
if (section[1] !== value) {
|
522
|
-
throw new Error('Unclosed section "' + section[1] + '" at ' + start);
|
523
|
-
}
|
524
|
-
}
|
447
|
+
if (!scanner.scan(tagRes[1])) throw new Error('Unclosed tag at ' + scanner.pos);
|
525
448
|
|
526
|
-
|
449
|
+
token = [type, value, start, scanner.pos];
|
527
450
|
tokens.push(token);
|
528
451
|
|
529
452
|
if (type === '#' || type === '^') {
|
530
453
|
sections.push(token);
|
531
|
-
} else if (type ===
|
454
|
+
} else if (type === '/') {
|
455
|
+
// Check section nesting.
|
456
|
+
openSection = sections.pop();
|
457
|
+
if (!openSection) {
|
458
|
+
throw new Error('Unopened section "' + value + '" at ' + start);
|
459
|
+
}
|
460
|
+
if (openSection[1] !== value) {
|
461
|
+
throw new Error('Unclosed section "' + openSection[1] + '" at ' + start);
|
462
|
+
}
|
463
|
+
} else if (type === 'name' || type === '{' || type === '&') {
|
532
464
|
nonSpace = true;
|
533
|
-
} else if (type ===
|
465
|
+
} else if (type === '=') {
|
534
466
|
// Set the tags for the next time around.
|
535
467
|
tags = value.split(spaceRe);
|
536
|
-
|
537
468
|
if (tags.length !== 2) {
|
538
469
|
throw new Error('Invalid tags at ' + start + ': ' + tags.join(', '));
|
539
470
|
}
|
540
|
-
|
541
471
|
tagRes = escapeTags(tags);
|
542
472
|
}
|
543
473
|
}
|
544
474
|
|
545
475
|
// Make sure there are no open sections when we're done.
|
546
|
-
|
547
|
-
if (
|
548
|
-
throw new Error('Unclosed section "' +
|
476
|
+
openSection = sections.pop();
|
477
|
+
if (openSection) {
|
478
|
+
throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos);
|
549
479
|
}
|
550
480
|
|
551
481
|
return nestTokens(squashTokens(tokens));
|
552
|
-
}
|
482
|
+
}
|
553
483
|
|
554
|
-
|
555
|
-
|
556
|
-
|
484
|
+
mustache.name = "mustache.js";
|
485
|
+
mustache.version = "0.7.3";
|
486
|
+
mustache.tags = ["{{", "}}"];
|
487
|
+
|
488
|
+
mustache.Scanner = Scanner;
|
489
|
+
mustache.Context = Context;
|
490
|
+
mustache.Writer = Writer;
|
491
|
+
|
492
|
+
mustache.parse = parseTemplate;
|
493
|
+
|
494
|
+
// Export the escaping function so that the user may override it.
|
495
|
+
// See https://github.com/janl/mustache.js/issues/244
|
496
|
+
mustache.escape = escapeHtml;
|
497
|
+
|
498
|
+
// All Mustache.* functions use this writer.
|
499
|
+
var defaultWriter = new Writer();
|
557
500
|
|
558
501
|
/**
|
559
502
|
* Clears all cached templates and partials in the default writer.
|
560
503
|
*/
|
561
|
-
|
562
|
-
return
|
504
|
+
mustache.clearCache = function () {
|
505
|
+
return defaultWriter.clearCache();
|
563
506
|
};
|
564
507
|
|
565
508
|
/**
|
566
509
|
* Compiles the given `template` to a reusable function using the default
|
567
510
|
* writer.
|
568
511
|
*/
|
569
|
-
|
570
|
-
return
|
512
|
+
mustache.compile = function (template, tags) {
|
513
|
+
return defaultWriter.compile(template, tags);
|
571
514
|
};
|
572
515
|
|
573
516
|
/**
|
574
517
|
* Compiles the partial with the given `name` and `template` to a reusable
|
575
518
|
* function using the default writer.
|
576
519
|
*/
|
577
|
-
|
578
|
-
return
|
520
|
+
mustache.compilePartial = function (name, template, tags) {
|
521
|
+
return defaultWriter.compilePartial(name, template, tags);
|
579
522
|
};
|
580
523
|
|
581
524
|
/**
|
582
525
|
* Compiles the given array of tokens (the output of a parse) to a reusable
|
583
526
|
* function using the default writer.
|
584
527
|
*/
|
585
|
-
|
586
|
-
return
|
528
|
+
mustache.compileTokens = function (tokens, template) {
|
529
|
+
return defaultWriter.compileTokens(tokens, template);
|
587
530
|
};
|
588
531
|
|
589
532
|
/**
|
590
533
|
* Renders the `template` with the given `view` and `partials` using the
|
591
534
|
* default writer.
|
592
535
|
*/
|
593
|
-
|
594
|
-
return
|
536
|
+
mustache.render = function (template, view, partials) {
|
537
|
+
return defaultWriter.render(template, view, partials);
|
595
538
|
};
|
596
539
|
|
597
540
|
// This is here for backwards compatibility with 0.4.x.
|
598
|
-
|
599
|
-
var result =
|
541
|
+
mustache.to_html = function (template, view, partials, send) {
|
542
|
+
var result = mustache.render(template, view, partials);
|
600
543
|
|
601
|
-
if (
|
544
|
+
if (isFunction(send)) {
|
602
545
|
send(result);
|
603
546
|
} else {
|
604
547
|
return result;
|
605
548
|
}
|
606
549
|
};
|
607
550
|
|
608
|
-
|
609
|
-
|
610
|
-
}())));
|
551
|
+
}));
|