mustachejs-rails 0.7.3 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/mustachejs/rails/version.rb +1 -1
- data/vendor/assets/javascripts/mustache.js +1 -547
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69f25c4d0a148e59be8ef8f02e4941782849af70
|
4
|
+
data.tar.gz: a1eb7f995585f626994835c11c9d47158b04515d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ead7b7b2afa9d94fb9124942a1995bb12f63fea78ebb6c84ddfe73d2f0609d45c26288d3c4aef3339dcec722ed341a14b30f3f4fe490c66f2f8ca7ab95390ca
|
7
|
+
data.tar.gz: 2ef8ed192a6c5cf10ef1027d279198525c5d5aa2a2db051756434207cdba4aed58af1945fb80baccf1845f7a50a8afa1bb294c37d042a7cefcd8966c12fecd40
|
data/README.md
CHANGED
@@ -2,550 +2,4 @@
|
|
2
2
|
* mustache.js - Logic-less {{mustache}} templates with JavaScript
|
3
3
|
* http://github.com/janl/mustache.js
|
4
4
|
*/
|
5
|
-
|
6
|
-
/*global define: false*/
|
7
|
-
|
8
|
-
(function (root, factory) {
|
9
|
-
if (typeof exports === "object" && exports) {
|
10
|
-
factory(exports); // CommonJS
|
11
|
-
} else {
|
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
|
-
}
|
19
|
-
}
|
20
|
-
}(this, function (mustache) {
|
21
|
-
|
22
|
-
var whiteRe = /\s*/;
|
23
|
-
var spaceRe = /\s+/;
|
24
|
-
var nonSpaceRe = /\S/;
|
25
|
-
var eqRe = /\s*=/;
|
26
|
-
var curlyRe = /\s*\}/;
|
27
|
-
var tagRe = /#|\^|\/|>|\{|&|=|!/;
|
28
|
-
|
29
|
-
// Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
|
30
|
-
// See https://github.com/janl/mustache.js/issues/189
|
31
|
-
var RegExp_test = RegExp.prototype.test;
|
32
|
-
function testRegExp(re, string) {
|
33
|
-
return RegExp_test.call(re, string);
|
34
|
-
}
|
35
|
-
|
36
|
-
function isWhitespace(string) {
|
37
|
-
return !testRegExp(nonSpaceRe, string);
|
38
|
-
}
|
39
|
-
|
40
|
-
var Object_toString = Object.prototype.toString;
|
41
|
-
var isArray = Array.isArray || function (object) {
|
42
|
-
return Object_toString.call(object) === '[object Array]';
|
43
|
-
};
|
44
|
-
|
45
|
-
function isFunction(object) {
|
46
|
-
return typeof object === 'function';
|
47
|
-
}
|
48
|
-
|
49
|
-
function escapeRegExp(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
|
-
function Scanner(string) {
|
69
|
-
this.string = string;
|
70
|
-
this.tail = string;
|
71
|
-
this.pos = 0;
|
72
|
-
}
|
73
|
-
|
74
|
-
/**
|
75
|
-
* Returns `true` if the tail is empty (end of string).
|
76
|
-
*/
|
77
|
-
Scanner.prototype.eos = function () {
|
78
|
-
return this.tail === "";
|
79
|
-
};
|
80
|
-
|
81
|
-
/**
|
82
|
-
* Tries to match the given regular expression at the current position.
|
83
|
-
* Returns the matched text if it can match, the empty string otherwise.
|
84
|
-
*/
|
85
|
-
Scanner.prototype.scan = function (re) {
|
86
|
-
var match = this.tail.match(re);
|
87
|
-
|
88
|
-
if (match && match.index === 0) {
|
89
|
-
var string = match[0];
|
90
|
-
this.tail = this.tail.substring(string.length);
|
91
|
-
this.pos += string.length;
|
92
|
-
return string;
|
93
|
-
}
|
94
|
-
|
95
|
-
return "";
|
96
|
-
};
|
97
|
-
|
98
|
-
/**
|
99
|
-
* Skips all text until the given regular expression can be matched. Returns
|
100
|
-
* the skipped string, which is the entire tail if no match can be made.
|
101
|
-
*/
|
102
|
-
Scanner.prototype.scanUntil = function (re) {
|
103
|
-
var index = this.tail.search(re), match;
|
104
|
-
|
105
|
-
switch (index) {
|
106
|
-
case -1:
|
107
|
-
match = this.tail;
|
108
|
-
this.tail = "";
|
109
|
-
break;
|
110
|
-
case 0:
|
111
|
-
match = "";
|
112
|
-
break;
|
113
|
-
default:
|
114
|
-
match = this.tail.substring(0, index);
|
115
|
-
this.tail = this.tail.substring(index);
|
116
|
-
}
|
117
|
-
|
118
|
-
this.pos += match.length;
|
119
|
-
|
120
|
-
return match;
|
121
|
-
};
|
122
|
-
|
123
|
-
function Context(view, parent) {
|
124
|
-
this.view = view == null ? {} : view;
|
125
|
-
this.parent = parent;
|
126
|
-
this._cache = { '.': this.view };
|
127
|
-
}
|
128
|
-
|
129
|
-
Context.make = function (view) {
|
130
|
-
return (view instanceof Context) ? view : new Context(view);
|
131
|
-
};
|
132
|
-
|
133
|
-
Context.prototype.push = function (view) {
|
134
|
-
return new Context(view, this);
|
135
|
-
};
|
136
|
-
|
137
|
-
Context.prototype.lookup = function (name) {
|
138
|
-
var value;
|
139
|
-
if (name in this._cache) {
|
140
|
-
value = this._cache[name];
|
141
|
-
} else {
|
142
|
-
var context = this;
|
143
|
-
|
144
|
-
while (context) {
|
145
|
-
if (name.indexOf('.') > 0) {
|
146
|
-
value = context.view;
|
147
|
-
|
148
|
-
var names = name.split('.'), i = 0;
|
149
|
-
while (value != null && i < names.length) {
|
150
|
-
value = value[names[i++]];
|
151
|
-
}
|
152
|
-
} else {
|
153
|
-
value = context.view[name];
|
154
|
-
}
|
155
|
-
|
156
|
-
if (value != null) break;
|
157
|
-
|
158
|
-
context = context.parent;
|
159
|
-
}
|
160
|
-
|
161
|
-
this._cache[name] = value;
|
162
|
-
}
|
163
|
-
|
164
|
-
if (isFunction(value)) {
|
165
|
-
value = value.call(this.view);
|
166
|
-
}
|
167
|
-
|
168
|
-
return value;
|
169
|
-
};
|
170
|
-
|
171
|
-
function Writer() {
|
172
|
-
this.clearCache();
|
173
|
-
}
|
174
|
-
|
175
|
-
Writer.prototype.clearCache = function () {
|
176
|
-
this._cache = {};
|
177
|
-
this._partialCache = {};
|
178
|
-
};
|
179
|
-
|
180
|
-
Writer.prototype.compile = function (template, tags) {
|
181
|
-
var fn = this._cache[template];
|
182
|
-
|
183
|
-
if (!fn) {
|
184
|
-
var tokens = mustache.parse(template, tags);
|
185
|
-
fn = this._cache[template] = this.compileTokens(tokens, template);
|
186
|
-
}
|
187
|
-
|
188
|
-
return fn;
|
189
|
-
};
|
190
|
-
|
191
|
-
Writer.prototype.compilePartial = function (name, template, tags) {
|
192
|
-
var fn = this.compile(template, tags);
|
193
|
-
this._partialCache[name] = fn;
|
194
|
-
return fn;
|
195
|
-
};
|
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
|
-
|
205
|
-
Writer.prototype.compileTokens = function (tokens, template) {
|
206
|
-
var self = this;
|
207
|
-
return function (view, partials) {
|
208
|
-
if (partials) {
|
209
|
-
if (isFunction(partials)) {
|
210
|
-
self._loadPartial = partials;
|
211
|
-
} else {
|
212
|
-
for (var name in partials) {
|
213
|
-
self.compilePartial(name, partials[name]);
|
214
|
-
}
|
215
|
-
}
|
216
|
-
}
|
217
|
-
|
218
|
-
return renderTokens(tokens, self, Context.make(view), template);
|
219
|
-
};
|
220
|
-
};
|
221
|
-
|
222
|
-
Writer.prototype.render = function (template, view, partials) {
|
223
|
-
return this.compile(template)(view, partials);
|
224
|
-
};
|
225
|
-
|
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 = '';
|
234
|
-
|
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);
|
239
|
-
}
|
240
|
-
|
241
|
-
var token, tokenValue, value;
|
242
|
-
for (var i = 0, len = tokens.length; i < len; ++i) {
|
243
|
-
token = tokens[i];
|
244
|
-
tokenValue = token[1];
|
245
|
-
|
246
|
-
switch (token[0]) {
|
247
|
-
case '#':
|
248
|
-
value = context.lookup(tokenValue);
|
249
|
-
|
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
|
-
}
|
265
|
-
|
266
|
-
break;
|
267
|
-
case '^':
|
268
|
-
value = context.lookup(tokenValue);
|
269
|
-
|
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
|
-
}
|
275
|
-
|
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;
|
292
|
-
}
|
293
|
-
}
|
294
|
-
|
295
|
-
return buffer;
|
296
|
-
}
|
297
|
-
|
298
|
-
/**
|
299
|
-
* Forms the given array of `tokens` into a nested tree structure where
|
300
|
-
* tokens that represent a section have two additional items: 1) an array of
|
301
|
-
* all tokens that appear in that section and 2) the index in the original
|
302
|
-
* template that represents the end of that section.
|
303
|
-
*/
|
304
|
-
function nestTokens(tokens) {
|
305
|
-
var tree = [];
|
306
|
-
var collector = tree;
|
307
|
-
var sections = [];
|
308
|
-
|
309
|
-
var token;
|
310
|
-
for (var i = 0, len = tokens.length; i < len; ++i) {
|
311
|
-
token = tokens[i];
|
312
|
-
switch (token[0]) {
|
313
|
-
case '#':
|
314
|
-
case '^':
|
315
|
-
sections.push(token);
|
316
|
-
collector.push(token);
|
317
|
-
collector = token[4] = [];
|
318
|
-
break;
|
319
|
-
case '/':
|
320
|
-
var section = sections.pop();
|
321
|
-
section[5] = token[2];
|
322
|
-
collector = sections.length > 0 ? sections[sections.length - 1][4] : tree;
|
323
|
-
break;
|
324
|
-
default:
|
325
|
-
collector.push(token);
|
326
|
-
}
|
327
|
-
}
|
328
|
-
|
329
|
-
return tree;
|
330
|
-
}
|
331
|
-
|
332
|
-
/**
|
333
|
-
* Combines the values of consecutive text tokens in the given `tokens` array
|
334
|
-
* to a single token.
|
335
|
-
*/
|
336
|
-
function squashTokens(tokens) {
|
337
|
-
var squashedTokens = [];
|
338
|
-
|
339
|
-
var token, lastToken;
|
340
|
-
for (var i = 0, len = tokens.length; i < len; ++i) {
|
341
|
-
token = tokens[i];
|
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
|
-
}
|
350
|
-
}
|
351
|
-
}
|
352
|
-
|
353
|
-
return squashedTokens;
|
354
|
-
}
|
355
|
-
|
356
|
-
function escapeTags(tags) {
|
357
|
-
return [
|
358
|
-
new RegExp(escapeRegExp(tags[0]) + "\\s*"),
|
359
|
-
new RegExp("\\s*" + escapeRegExp(tags[1]))
|
360
|
-
];
|
361
|
-
}
|
362
|
-
|
363
|
-
/**
|
364
|
-
* Breaks up the given `template` string into a tree of token objects. If
|
365
|
-
* `tags` is given here it must be an array with two string values: the
|
366
|
-
* opening and closing tags used in the template (e.g. ["<%", "%>"]). Of
|
367
|
-
* course, the default is to use mustaches (i.e. Mustache.tags).
|
368
|
-
*/
|
369
|
-
function parseTemplate(template, tags) {
|
370
|
-
template = template || '';
|
371
|
-
tags = tags || mustache.tags;
|
372
|
-
|
373
|
-
if (typeof tags === 'string') tags = tags.split(spaceRe);
|
374
|
-
if (tags.length !== 2) throw new Error('Invalid tags: ' + tags.join(', '));
|
375
|
-
|
376
|
-
var tagRes = escapeTags(tags);
|
377
|
-
var scanner = new Scanner(template);
|
378
|
-
|
379
|
-
var sections = []; // Stack to hold section tokens
|
380
|
-
var tokens = []; // Buffer to hold the tokens
|
381
|
-
var spaces = []; // Indices of whitespace tokens on the current line
|
382
|
-
var hasTag = false; // Is there a {{tag}} on the current line?
|
383
|
-
var nonSpace = false; // Is there a non-space char on the current line?
|
384
|
-
|
385
|
-
// Strips all whitespace tokens array for the current line
|
386
|
-
// if there was a {{#tag}} on it and otherwise only space.
|
387
|
-
function stripSpace() {
|
388
|
-
if (hasTag && !nonSpace) {
|
389
|
-
while (spaces.length) {
|
390
|
-
delete tokens[spaces.pop()];
|
391
|
-
}
|
392
|
-
} else {
|
393
|
-
spaces = [];
|
394
|
-
}
|
395
|
-
|
396
|
-
hasTag = false;
|
397
|
-
nonSpace = false;
|
398
|
-
}
|
399
|
-
|
400
|
-
var start, type, value, chr, token, openSection;
|
401
|
-
while (!scanner.eos()) {
|
402
|
-
start = scanner.pos;
|
403
|
-
|
404
|
-
// Match any text between tags.
|
405
|
-
value = scanner.scanUntil(tagRes[0]);
|
406
|
-
if (value) {
|
407
|
-
for (var i = 0, len = value.length; i < len; ++i) {
|
408
|
-
chr = value.charAt(i);
|
409
|
-
|
410
|
-
if (isWhitespace(chr)) {
|
411
|
-
spaces.push(tokens.length);
|
412
|
-
} else {
|
413
|
-
nonSpace = true;
|
414
|
-
}
|
415
|
-
|
416
|
-
tokens.push(['text', chr, start, start + 1]);
|
417
|
-
start += 1;
|
418
|
-
|
419
|
-
// Check for whitespace on the current line.
|
420
|
-
if (chr == '\n') stripSpace();
|
421
|
-
}
|
422
|
-
}
|
423
|
-
|
424
|
-
// Match the opening tag.
|
425
|
-
if (!scanner.scan(tagRes[0])) break;
|
426
|
-
hasTag = true;
|
427
|
-
|
428
|
-
// Get the tag type.
|
429
|
-
type = scanner.scan(tagRe) || 'name';
|
430
|
-
scanner.scan(whiteRe);
|
431
|
-
|
432
|
-
// Get the tag value.
|
433
|
-
if (type === '=') {
|
434
|
-
value = scanner.scanUntil(eqRe);
|
435
|
-
scanner.scan(eqRe);
|
436
|
-
scanner.scanUntil(tagRes[1]);
|
437
|
-
} else if (type === '{') {
|
438
|
-
value = scanner.scanUntil(new RegExp('\\s*' + escapeRegExp('}' + tags[1])));
|
439
|
-
scanner.scan(curlyRe);
|
440
|
-
scanner.scanUntil(tagRes[1]);
|
441
|
-
type = '&';
|
442
|
-
} else {
|
443
|
-
value = scanner.scanUntil(tagRes[1]);
|
444
|
-
}
|
445
|
-
|
446
|
-
// Match the closing tag.
|
447
|
-
if (!scanner.scan(tagRes[1])) throw new Error('Unclosed tag at ' + scanner.pos);
|
448
|
-
|
449
|
-
token = [type, value, start, scanner.pos];
|
450
|
-
tokens.push(token);
|
451
|
-
|
452
|
-
if (type === '#' || type === '^') {
|
453
|
-
sections.push(token);
|
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 === '&') {
|
464
|
-
nonSpace = true;
|
465
|
-
} else if (type === '=') {
|
466
|
-
// Set the tags for the next time around.
|
467
|
-
tags = value.split(spaceRe);
|
468
|
-
if (tags.length !== 2) {
|
469
|
-
throw new Error('Invalid tags at ' + start + ': ' + tags.join(', '));
|
470
|
-
}
|
471
|
-
tagRes = escapeTags(tags);
|
472
|
-
}
|
473
|
-
}
|
474
|
-
|
475
|
-
// Make sure there are no open sections when we're done.
|
476
|
-
openSection = sections.pop();
|
477
|
-
if (openSection) {
|
478
|
-
throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos);
|
479
|
-
}
|
480
|
-
|
481
|
-
return nestTokens(squashTokens(tokens));
|
482
|
-
}
|
483
|
-
|
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();
|
500
|
-
|
501
|
-
/**
|
502
|
-
* Clears all cached templates and partials in the default writer.
|
503
|
-
*/
|
504
|
-
mustache.clearCache = function () {
|
505
|
-
return defaultWriter.clearCache();
|
506
|
-
};
|
507
|
-
|
508
|
-
/**
|
509
|
-
* Compiles the given `template` to a reusable function using the default
|
510
|
-
* writer.
|
511
|
-
*/
|
512
|
-
mustache.compile = function (template, tags) {
|
513
|
-
return defaultWriter.compile(template, tags);
|
514
|
-
};
|
515
|
-
|
516
|
-
/**
|
517
|
-
* Compiles the partial with the given `name` and `template` to a reusable
|
518
|
-
* function using the default writer.
|
519
|
-
*/
|
520
|
-
mustache.compilePartial = function (name, template, tags) {
|
521
|
-
return defaultWriter.compilePartial(name, template, tags);
|
522
|
-
};
|
523
|
-
|
524
|
-
/**
|
525
|
-
* Compiles the given array of tokens (the output of a parse) to a reusable
|
526
|
-
* function using the default writer.
|
527
|
-
*/
|
528
|
-
mustache.compileTokens = function (tokens, template) {
|
529
|
-
return defaultWriter.compileTokens(tokens, template);
|
530
|
-
};
|
531
|
-
|
532
|
-
/**
|
533
|
-
* Renders the `template` with the given `view` and `partials` using the
|
534
|
-
* default writer.
|
535
|
-
*/
|
536
|
-
mustache.render = function (template, view, partials) {
|
537
|
-
return defaultWriter.render(template, view, partials);
|
538
|
-
};
|
539
|
-
|
540
|
-
// This is here for backwards compatibility with 0.4.x.
|
541
|
-
mustache.to_html = function (template, view, partials, send) {
|
542
|
-
var result = mustache.render(template, view, partials);
|
543
|
-
|
544
|
-
if (isFunction(send)) {
|
545
|
-
send(result);
|
546
|
-
} else {
|
547
|
-
return result;
|
548
|
-
}
|
549
|
-
};
|
550
|
-
|
551
|
-
}));
|
5
|
+
(function(a,b){if(typeof exports==="object"&&exports){b(exports)}else{var c={};b(c);if(typeof define==="function"&&define.amd){define(c)}else{a.Mustache=c}}}(this,function(a){var f=/\s*/;var m=/\s+/;var k=/\S/;var i=/\s*=/;var o=/\s*\}/;var t=/#|\^|\/|>|\{|&|=|!/;var g=RegExp.prototype.test;function s(z,y){return g.call(z,y)}function h(y){return !s(k,y)}var v=Object.prototype.toString;var l=Array.isArray||function(y){return v.call(y)==="[object Array]"};function b(y){return typeof y==="function"}function e(y){return y.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}var d={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};function n(y){return String(y).replace(/[&<>"'\/]/g,function(z){return d[z]})}function r(y){if(!l(y)||y.length!==2){throw new Error("Invalid tags: "+y)}return[new RegExp(e(y[0])+"\\s*"),new RegExp("\\s*"+e(y[1]))]}function x(O,E){E=E||a.tags;O=O||"";if(typeof E==="string"){E=E.split(m)}var I=r(E);var A=new u(O);var G=[];var F=[];var D=[];var P=false;var N=false;function M(){if(P&&!N){while(D.length){delete F[D.pop()]}}else{D=[]}P=false;N=false}var B,z,H,J,C,y;while(!A.eos()){B=A.pos;H=A.scanUntil(I[0]);if(H){for(var K=0,L=H.length;K<L;++K){J=H.charAt(K);if(h(J)){D.push(F.length)}else{N=true}F.push(["text",J,B,B+1]);B+=1;if(J==="\n"){M()}}}if(!A.scan(I[0])){break}P=true;z=A.scan(t)||"name";A.scan(f);if(z==="="){H=A.scanUntil(i);A.scan(i);A.scanUntil(I[1])}else{if(z==="{"){H=A.scanUntil(new RegExp("\\s*"+e("}"+E[1])));A.scan(o);A.scanUntil(I[1]);z="&"}else{H=A.scanUntil(I[1])}}if(!A.scan(I[1])){throw new Error("Unclosed tag at "+A.pos)}C=[z,H,B,A.pos];F.push(C);if(z==="#"||z==="^"){G.push(C)}else{if(z==="/"){y=G.pop();if(!y){throw new Error('Unopened section "'+H+'" at '+B)}if(y[1]!==H){throw new Error('Unclosed section "'+y[1]+'" at '+B)}}else{if(z==="name"||z==="{"||z==="&"){N=true}else{if(z==="="){I=r(E=H.split(m))}}}}}y=G.pop();if(y){throw new Error('Unclosed section "'+y[1]+'" at '+A.pos)}return w(c(F))}function c(D){var A=[];var C,z;for(var B=0,y=D.length;B<y;++B){C=D[B];if(C){if(C[0]==="text"&&z&&z[0]==="text"){z[1]+=C[1];z[3]=C[3]}else{A.push(C);z=C}}}return A}function w(D){var F=[];var C=F;var E=[];var A,B;for(var z=0,y=D.length;z<y;++z){A=D[z];switch(A[0]){case"#":case"^":C.push(A);E.push(A);C=A[4]=[];break;case"/":B=E.pop();B[5]=A[2];C=E.length>0?E[E.length-1][4]:F;break;default:C.push(A)}}return F}function u(y){this.string=y;this.tail=y;this.pos=0}u.prototype.eos=function(){return this.tail===""};u.prototype.scan=function(A){var z=this.tail.match(A);if(z&&z.index===0){var y=z[0];this.tail=this.tail.substring(y.length);this.pos+=y.length;return y}return""};u.prototype.scanUntil=function(A){var z=this.tail.search(A),y;switch(z){case -1:y=this.tail;this.tail="";break;case 0:y="";break;default:y=this.tail.substring(0,z);this.tail=this.tail.substring(z)}this.pos+=y.length;return y};function q(z,y){this.view=z==null?{}:z;this.cache={".":this.view};this.parent=y}q.prototype.push=function(y){return new q(y,this)};q.prototype.lookup=function(y){var B;if(y in this.cache){B=this.cache[y]}else{var A=this;while(A){if(y.indexOf(".")>0){B=A.view;var C=y.split("."),z=0;while(B!=null&&z<C.length){B=B[C[z++]]}}else{B=A.view[y]}if(B!=null){break}A=A.parent}this.cache[y]=B}if(b(B)){B=B.call(this.view)}return B};function p(){this.cache={}}p.prototype.clearCache=function(){this.cache={}};p.prototype.parse=function(z,y){if(!(z in this.cache)){this.cache[z]=x(z,y)}return this.cache[z]};p.prototype.render=function(B,y,A){var C=this.parse(B);var z=(y instanceof q)?y:new q(y);return this.renderTokens(C,z,A,B)};p.prototype.renderTokens=function(G,y,E,I){var C="";var K=this;function z(L){return K.render(L,y,E)}var A,H;for(var D=0,F=G.length;D<F;++D){A=G[D];switch(A[0]){case"#":H=y.lookup(A[1]);if(!H){continue}if(l(H)){for(var B=0,J=H.length;B<J;++B){C+=this.renderTokens(A[4],y.push(H[B]),E,I)}}else{if(typeof H==="object"||typeof H==="string"){C+=this.renderTokens(A[4],y.push(H),E,I)}else{if(b(H)){if(typeof I!=="string"){throw new Error("Cannot use higher-order sections without the original template")}H=H.call(y.view,I.slice(A[3],A[5]),z);if(H!=null){C+=H}}else{C+=this.renderTokens(A[4],y,E,I)}}}break;case"^":H=y.lookup(A[1]);if(!H||(l(H)&&H.length===0)){C+=this.renderTokens(A[4],y,E,I)}break;case">":if(!E){continue}H=this.parse(b(E)?E(A[1]):E[A[1]]);if(H!=null){C+=this.renderTokens(H,y,E,I)}break;case"&":H=y.lookup(A[1]);if(H!=null){C+=H}break;case"name":H=y.lookup(A[1]);if(H!=null){C+=a.escape(H)}break;case"text":C+=A[1];break}}return C};a.name="mustache.js";a.version="0.8.0";a.tags=["{{","}}"];var j=new p();a.clearCache=function(){return j.clearCache()};a.parse=function(z,y){return j.parse(z,y)};a.render=function(A,y,z){return j.render(A,y,z)};a.to_html=function(B,z,A,C){var y=a.render(B,z,A);if(b(C)){C(y)}else{return y}};a.escape=n;a.Scanner=u;a.Context=q;a.Writer=p}));
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mustachejs-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon COURTOIS
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description: This gem provides mustache.js for your Rails 3 application.
|
@@ -31,7 +31,7 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
-
- .gitignore
|
34
|
+
- ".gitignore"
|
35
35
|
- Gemfile
|
36
36
|
- LICENSE.txt
|
37
37
|
- README.md
|
@@ -50,17 +50,17 @@ require_paths:
|
|
50
50
|
- lib
|
51
51
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- -
|
58
|
+
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
61
|
requirements: []
|
62
62
|
rubyforge_project:
|
63
|
-
rubygems_version: 2.
|
63
|
+
rubygems_version: 2.2.2
|
64
64
|
signing_key:
|
65
65
|
specification_version: 4
|
66
66
|
summary: Use mustache.js with Rails 3
|