mustache-js-rails 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of mustache-js-rails might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/mustache-js-rails/version.rb +1 -1
- data/vendor/assets/javascripts/mustache.js +67 -52
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5016f09bb6a7d5d85e61bbed6a6ef13248db23fa
|
4
|
+
data.tar.gz: 677f8b752d447377da5f320f463965e0fe168795
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 451118b3037b7ea473b6e00daa927f0eec1423d3d955b2529f45adab32732d7376542bbc66025a3061b3e0587f6d917b97621186002141ddc82456b933f6eca1
|
7
|
+
data.tar.gz: e8e40d3914ca288375bb2566185ac0e87054f39bd230a780729e21e4690751d2fa36b56e9360921b2c6667e0a16a622e5975a0152da57838e484bd109fbb9d41
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@ and [mustache jQuery integration](https://github.com/jonnyreeves/jquery-Mustache
|
|
5
5
|
|
6
6
|
Integrated versions are:
|
7
7
|
|
8
|
-
* mustache.js - <b id="mustache-js-version">0.7.
|
8
|
+
* mustache.js - <b id="mustache-js-version">0.7.3</b>
|
9
9
|
* jQuery mustache - <b id="jQuery-mustache-version">0.2.7</b>
|
10
10
|
|
11
11
|
### Installation
|
@@ -38,10 +38,14 @@
|
|
38
38
|
}
|
39
39
|
|
40
40
|
var Object_toString = Object.prototype.toString;
|
41
|
-
var isArray = Array.isArray || function (
|
42
|
-
return Object_toString.call(
|
41
|
+
var isArray = Array.isArray || function (object) {
|
42
|
+
return Object_toString.call(object) === '[object Array]';
|
43
43
|
};
|
44
44
|
|
45
|
+
function isFunction(object) {
|
46
|
+
return typeof object === 'function';
|
47
|
+
}
|
48
|
+
|
45
49
|
function escapeRegExp(string) {
|
46
50
|
return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
|
47
51
|
}
|
@@ -82,9 +86,10 @@
|
|
82
86
|
var match = this.tail.match(re);
|
83
87
|
|
84
88
|
if (match && match.index === 0) {
|
85
|
-
|
86
|
-
this.
|
87
|
-
|
89
|
+
var string = match[0];
|
90
|
+
this.tail = this.tail.substring(string.length);
|
91
|
+
this.pos += string.length;
|
92
|
+
return string;
|
88
93
|
}
|
89
94
|
|
90
95
|
return "";
|
@@ -95,30 +100,30 @@
|
|
95
100
|
* the skipped string, which is the entire tail if no match can be made.
|
96
101
|
*/
|
97
102
|
Scanner.prototype.scanUntil = function (re) {
|
98
|
-
var
|
103
|
+
var index = this.tail.search(re), match;
|
99
104
|
|
100
|
-
switch (
|
105
|
+
switch (index) {
|
101
106
|
case -1:
|
102
107
|
match = this.tail;
|
103
|
-
this.pos += this.tail.length;
|
104
108
|
this.tail = "";
|
105
109
|
break;
|
106
110
|
case 0:
|
107
111
|
match = "";
|
108
112
|
break;
|
109
113
|
default:
|
110
|
-
match = this.tail.substring(0,
|
111
|
-
this.tail = this.tail.substring(
|
112
|
-
this.pos += pos;
|
114
|
+
match = this.tail.substring(0, index);
|
115
|
+
this.tail = this.tail.substring(index);
|
113
116
|
}
|
114
117
|
|
118
|
+
this.pos += match.length;
|
119
|
+
|
115
120
|
return match;
|
116
121
|
};
|
117
122
|
|
118
123
|
function Context(view, parent) {
|
119
|
-
this.view = view
|
124
|
+
this.view = view == null ? {} : view;
|
120
125
|
this.parent = parent;
|
121
|
-
this._cache = {};
|
126
|
+
this._cache = { '.': this.view };
|
122
127
|
}
|
123
128
|
|
124
129
|
Context.make = function (view) {
|
@@ -130,35 +135,35 @@
|
|
130
135
|
};
|
131
136
|
|
132
137
|
Context.prototype.lookup = function (name) {
|
133
|
-
var value
|
138
|
+
var value;
|
139
|
+
if (name in this._cache) {
|
140
|
+
value = this._cache[name];
|
141
|
+
} else {
|
142
|
+
var context = this;
|
134
143
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
if (name.indexOf('.') > 0) {
|
143
|
-
value = context.view;
|
144
|
-
var names = name.split('.'), i = 0;
|
145
|
-
while (value && i < names.length) {
|
146
|
-
value = value[names[i++]];
|
147
|
-
}
|
148
|
-
} else {
|
149
|
-
value = context.view[name];
|
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++]];
|
150
151
|
}
|
152
|
+
} else {
|
153
|
+
value = context.view[name];
|
154
|
+
}
|
151
155
|
|
152
|
-
|
156
|
+
if (value != null) break;
|
153
157
|
|
154
|
-
|
155
|
-
}
|
158
|
+
context = context.parent;
|
156
159
|
}
|
157
160
|
|
158
161
|
this._cache[name] = value;
|
159
162
|
}
|
160
163
|
|
161
|
-
if (
|
164
|
+
if (isFunction(value)) {
|
165
|
+
value = value.call(this.view);
|
166
|
+
}
|
162
167
|
|
163
168
|
return value;
|
164
169
|
};
|
@@ -201,7 +206,7 @@
|
|
201
206
|
var self = this;
|
202
207
|
return function (view, partials) {
|
203
208
|
if (partials) {
|
204
|
-
if (
|
209
|
+
if (isFunction(partials)) {
|
205
210
|
self._loadPartial = partials;
|
206
211
|
} else {
|
207
212
|
for (var name in partials) {
|
@@ -227,6 +232,12 @@
|
|
227
232
|
function renderTokens(tokens, writer, context, template) {
|
228
233
|
var buffer = '';
|
229
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
|
+
|
230
241
|
var token, tokenValue, value;
|
231
242
|
for (var i = 0, len = tokens.length; i < len; ++i) {
|
232
243
|
token = tokens[i];
|
@@ -236,7 +247,7 @@
|
|
236
247
|
case '#':
|
237
248
|
value = context.lookup(tokenValue);
|
238
249
|
|
239
|
-
if (typeof value === 'object') {
|
250
|
+
if (typeof value === 'object' || typeof value === 'string') {
|
240
251
|
if (isArray(value)) {
|
241
252
|
for (var j = 0, jlen = value.length; j < jlen; ++j) {
|
242
253
|
buffer += renderTokens(token[4], writer, context.push(value[j]), template);
|
@@ -244,11 +255,9 @@
|
|
244
255
|
} else if (value) {
|
245
256
|
buffer += renderTokens(token[4], writer, context.push(value), template);
|
246
257
|
}
|
247
|
-
} else if (
|
258
|
+
} else if (isFunction(value)) {
|
248
259
|
var text = template == null ? null : template.slice(token[3], token[5]);
|
249
|
-
value = value.call(context.view, text,
|
250
|
-
return writer.render(template, context);
|
251
|
-
});
|
260
|
+
value = value.call(context.view, text, subRender);
|
252
261
|
if (value != null) buffer += value;
|
253
262
|
} else if (value) {
|
254
263
|
buffer += renderTokens(token[4], writer, context, template);
|
@@ -267,7 +276,7 @@
|
|
267
276
|
break;
|
268
277
|
case '>':
|
269
278
|
value = writer.getPartial(tokenValue);
|
270
|
-
if (
|
279
|
+
if (isFunction(value)) buffer += value(context);
|
271
280
|
break;
|
272
281
|
case '&':
|
273
282
|
value = context.lookup(tokenValue);
|
@@ -388,7 +397,7 @@
|
|
388
397
|
nonSpace = false;
|
389
398
|
}
|
390
399
|
|
391
|
-
var start, type, value, chr, token;
|
400
|
+
var start, type, value, chr, token, openSection;
|
392
401
|
while (!scanner.eos()) {
|
393
402
|
start = scanner.pos;
|
394
403
|
|
@@ -444,30 +453,36 @@
|
|
444
453
|
sections.push(token);
|
445
454
|
} else if (type === '/') {
|
446
455
|
// Check section nesting.
|
447
|
-
|
448
|
-
|
449
|
-
|
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
|
+
}
|
450
463
|
} else if (type === 'name' || type === '{' || type === '&') {
|
451
464
|
nonSpace = true;
|
452
465
|
} else if (type === '=') {
|
453
466
|
// Set the tags for the next time around.
|
454
467
|
tags = value.split(spaceRe);
|
455
|
-
if (tags.length !== 2)
|
468
|
+
if (tags.length !== 2) {
|
469
|
+
throw new Error('Invalid tags at ' + start + ': ' + tags.join(', '));
|
470
|
+
}
|
456
471
|
tagRes = escapeTags(tags);
|
457
472
|
}
|
458
473
|
}
|
459
474
|
|
460
475
|
// Make sure there are no open sections when we're done.
|
461
|
-
|
462
|
-
if (openSection)
|
463
|
-
|
464
|
-
|
476
|
+
openSection = sections.pop();
|
477
|
+
if (openSection) {
|
478
|
+
throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos);
|
479
|
+
}
|
465
480
|
|
466
|
-
return nestTokens(tokens);
|
481
|
+
return nestTokens(squashTokens(tokens));
|
467
482
|
}
|
468
483
|
|
469
484
|
mustache.name = "mustache.js";
|
470
|
-
mustache.version = "0.7.
|
485
|
+
mustache.version = "0.7.3";
|
471
486
|
mustache.tags = ["{{", "}}"];
|
472
487
|
|
473
488
|
mustache.Scanner = Scanner;
|
@@ -526,7 +541,7 @@
|
|
526
541
|
mustache.to_html = function (template, view, partials, send) {
|
527
542
|
var result = mustache.render(template, view, partials);
|
528
543
|
|
529
|
-
if (
|
544
|
+
if (isFunction(send)) {
|
530
545
|
send(result);
|
531
546
|
} else {
|
532
547
|
return result;
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mustache-js-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Krzysztof Knapik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|