mustache-js-rails 0.0.3 → 0.0.4
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 +3 -3
- data/Rakefile +37 -5
- data/lib/mustache-js-rails/version.rb +1 -1
- data/vendor/assets/javascripts/jquery.mustache.js +11 -10
- data/vendor/assets/javascripts/mustache.js +164 -238
- 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: 2c8950f57591cccc2b9141b87adab0a59c666483
|
4
|
+
data.tar.gz: 7ca4c4bd78834a9a228229807b60fffb81205efa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b35fc37a6c0d75e7b2e9f1cdbcf0259bee2000c18976601ead750b13718dd9750ed576ef40b6b937211cd4c6db5969ef19369e219ec721a214bb0db52d0293f
|
7
|
+
data.tar.gz: 54f60d7614ab3b7ffca8c343ca87b80390aac995eb0164d4ef8b1e034748b1fd05ff146b3361b83368f6db3e9a765b08b288c55a6bc25b7ece8be08ca97162c3
|
data/README.md
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
mustache-js-rails integrates [mustache.js](https://github.com/janl/mustache.js)
|
4
4
|
and [mustache jQuery integration](https://github.com/jonnyreeves/jquery-Mustache) with rails 3.1+ asset pipeline.
|
5
5
|
|
6
|
-
|
6
|
+
Integrated versions are:
|
7
7
|
|
8
|
-
*
|
9
|
-
* mustache
|
8
|
+
* mustache.js - <b id="mustache-js-version">0.7.2</b>
|
9
|
+
* jQuery mustache - <b id="jQuery-mustache-version">0.2.7</b>
|
10
10
|
|
11
11
|
### Installation
|
12
12
|
|
data/Rakefile
CHANGED
@@ -1,10 +1,42 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
2
|
require 'bundler/setup'
|
3
|
-
|
4
|
-
Bundler::GemHelper.install_tasks
|
3
|
+
require 'bundler/gem_tasks'
|
5
4
|
|
6
5
|
task :update do
|
7
|
-
|
6
|
+
js_dir = 'vendor/assets/javascripts'
|
7
|
+
css_dir = 'vendor/assets/stylesheets'
|
8
|
+
img_dir = 'vendor/assets/images'
|
9
|
+
[js_dir, css_dir, img_dir].each do |dir|
|
10
|
+
FileUtils.rm_r(dir)
|
11
|
+
FileUtils.mkdir(dir)
|
12
|
+
FileUtils.touch(File.join(dir, '.gitkeep'))
|
13
|
+
end
|
14
|
+
|
15
|
+
puts 'Updating source files...'
|
16
|
+
`git submodule foreach git pull`
|
17
|
+
|
18
|
+
puts 'Copying source js files...'
|
19
|
+
FileUtils.cp('mustache.js/mustache.js', js_dir)
|
20
|
+
FileUtils.cp('jquery.mustache.js/jquery.mustache.js', js_dir)
|
21
|
+
|
22
|
+
puts 'Updating version...'
|
23
|
+
mustache_js_version = File.read('mustache.js/mustache.js.nuspec').match(/<version>([\.\d]+)<\/version>/)[1]
|
24
|
+
jquery_mustache_js_version = File.read('jquery.mustache.js/jquery.mustache.js').match(/jQuery Mustache - v([\.\d]+)/)[1]
|
25
|
+
puts "Current mustache.js version is: #{mustache_js_version}"
|
26
|
+
puts "Current jquery.mustache.js version is: #{jquery_mustache_js_version}"
|
27
|
+
readme = File.read('README.md')
|
28
|
+
readme = readme.gsub(/(?<=<b id="mustache-js-version">)[\d\.]+(?=<\/b>)/, mustache_js_version)
|
29
|
+
readme = readme.gsub(/(?<=<b id="jquery-mustache-js-version">)[\d\.]+(?=<\/b>)/, jquery_mustache_js_version)
|
30
|
+
File.open('README.md','w') { |f| f.write(readme) }
|
8
31
|
end
|
9
|
-
|
10
|
-
|
32
|
+
|
33
|
+
task :build do
|
34
|
+
FileUtils.rm_f Dir['*.gem']
|
35
|
+
`gem build jquery-colorbox-rails.gemspec`
|
36
|
+
built_gem_file = Dir['*.gem'].first
|
37
|
+
if built_gem_file
|
38
|
+
`gem push #{built_gem_file}`
|
39
|
+
else
|
40
|
+
raise "Gem was not built!"
|
41
|
+
end
|
42
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
/*! jQuery Mustache - v0.2.
|
1
|
+
/*! jQuery Mustache - v0.2.8 - 2013-06-23
|
2
2
|
* https://github.com/jonnyreeves/jquery-Mustache
|
3
3
|
* Copyright (c) 2013 Jonny Reeves; Licensed MIT */
|
4
4
|
|
5
5
|
/*global jQuery, window */
|
6
6
|
(function ($, window) {
|
7
|
-
|
7
|
+
'use strict';
|
8
8
|
|
9
|
-
|
9
|
+
var templateMap = {},
|
10
10
|
instance = null,
|
11
11
|
options = {
|
12
12
|
// Should an error be thrown if an attempt is made to render a non-existent template. If false, the
|
@@ -38,7 +38,7 @@
|
|
38
38
|
}
|
39
39
|
|
40
40
|
/**
|
41
|
-
*
|
41
|
+
* @return {boolean} if the supplied templateName has been added.
|
42
42
|
*/
|
43
43
|
function has(templateName) {
|
44
44
|
return templateMap[templateName] !== void 0;
|
@@ -84,12 +84,12 @@
|
|
84
84
|
$.each(templateElementIds, function() {
|
85
85
|
var templateElement = document.getElementById(this);
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
87
|
+
if (templateElement === null) {
|
88
|
+
$.error('No such elementId: #' + this);
|
89
|
+
}
|
90
|
+
else {
|
91
|
+
add(this, $(templateElement).html());
|
92
|
+
}
|
93
93
|
});
|
94
94
|
}
|
95
95
|
|
@@ -166,6 +166,7 @@
|
|
166
166
|
$.Mustache = {
|
167
167
|
options: options,
|
168
168
|
load: load,
|
169
|
+
has: has,
|
169
170
|
add: add,
|
170
171
|
addFromDom: addFromDom,
|
171
172
|
remove: remove,
|
@@ -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,21 @@
|
|
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
|
|
40
|
+
var Object_toString = Object.prototype.toString;
|
45
41
|
var isArray = Array.isArray || function (obj) {
|
46
|
-
return
|
42
|
+
return Object_toString.call(obj) === '[object Array]';
|
47
43
|
};
|
48
44
|
|
49
|
-
function
|
45
|
+
function escapeRegExp(string) {
|
50
46
|
return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
|
51
47
|
}
|
52
48
|
|
@@ -65,10 +61,6 @@
|
|
65
61
|
});
|
66
62
|
}
|
67
63
|
|
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
64
|
function Scanner(string) {
|
73
65
|
this.string = string;
|
74
66
|
this.tail = string;
|
@@ -124,19 +116,15 @@
|
|
124
116
|
};
|
125
117
|
|
126
118
|
function Context(view, parent) {
|
127
|
-
this.view = view;
|
119
|
+
this.view = view || {};
|
128
120
|
this.parent = parent;
|
129
|
-
this.
|
121
|
+
this._cache = {};
|
130
122
|
}
|
131
123
|
|
132
124
|
Context.make = function (view) {
|
133
125
|
return (view instanceof Context) ? view : new Context(view);
|
134
126
|
};
|
135
127
|
|
136
|
-
Context.prototype.clearCache = function () {
|
137
|
-
this._cache = {};
|
138
|
-
};
|
139
|
-
|
140
128
|
Context.prototype.push = function (view) {
|
141
129
|
return new Context(view, this);
|
142
130
|
};
|
@@ -145,17 +133,15 @@
|
|
145
133
|
var value = this._cache[name];
|
146
134
|
|
147
135
|
if (!value) {
|
148
|
-
if (name
|
136
|
+
if (name == '.') {
|
149
137
|
value = this.view;
|
150
138
|
} else {
|
151
139
|
var context = this;
|
152
140
|
|
153
141
|
while (context) {
|
154
|
-
if (name.indexOf(
|
155
|
-
var names = name.split("."), i = 0;
|
156
|
-
|
142
|
+
if (name.indexOf('.') > 0) {
|
157
143
|
value = context.view;
|
158
|
-
|
144
|
+
var names = name.split('.'), i = 0;
|
159
145
|
while (value && i < names.length) {
|
160
146
|
value = value[names[i++]];
|
161
147
|
}
|
@@ -163,9 +149,7 @@
|
|
163
149
|
value = context.view[name];
|
164
150
|
}
|
165
151
|
|
166
|
-
if (value != null)
|
167
|
-
break;
|
168
|
-
}
|
152
|
+
if (value != null) break;
|
169
153
|
|
170
154
|
context = context.parent;
|
171
155
|
}
|
@@ -174,9 +158,7 @@
|
|
174
158
|
this._cache[name] = value;
|
175
159
|
}
|
176
160
|
|
177
|
-
if (typeof value ===
|
178
|
-
value = value.call(this.view);
|
179
|
-
}
|
161
|
+
if (typeof value === 'function') value = value.call(this.view);
|
180
162
|
|
181
163
|
return value;
|
182
164
|
};
|
@@ -194,7 +176,7 @@
|
|
194
176
|
var fn = this._cache[template];
|
195
177
|
|
196
178
|
if (!fn) {
|
197
|
-
var tokens =
|
179
|
+
var tokens = mustache.parse(template, tags);
|
198
180
|
fn = this._cache[template] = this.compileTokens(tokens, template);
|
199
181
|
}
|
200
182
|
|
@@ -207,13 +189,19 @@
|
|
207
189
|
return fn;
|
208
190
|
};
|
209
191
|
|
192
|
+
Writer.prototype.getPartial = function (name) {
|
193
|
+
if (!(name in this._partialCache) && this._loadPartial) {
|
194
|
+
this.compilePartial(name, this._loadPartial(name));
|
195
|
+
}
|
196
|
+
|
197
|
+
return this._partialCache[name];
|
198
|
+
};
|
199
|
+
|
210
200
|
Writer.prototype.compileTokens = function (tokens, template) {
|
211
|
-
var fn = compileTokens(tokens);
|
212
201
|
var self = this;
|
213
|
-
|
214
202
|
return function (view, partials) {
|
215
203
|
if (partials) {
|
216
|
-
if (typeof partials ===
|
204
|
+
if (typeof partials === 'function') {
|
217
205
|
self._loadPartial = partials;
|
218
206
|
} else {
|
219
207
|
for (var name in partials) {
|
@@ -222,7 +210,7 @@
|
|
222
210
|
}
|
223
211
|
}
|
224
212
|
|
225
|
-
return
|
213
|
+
return renderTokens(tokens, self, Context.make(view), template);
|
226
214
|
};
|
227
215
|
};
|
228
216
|
|
@@ -230,125 +218,72 @@
|
|
230
218
|
return this.compile(template)(view, partials);
|
231
219
|
};
|
232
220
|
|
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
|
-
};
|
277
|
-
|
278
|
-
Writer.prototype._partial = function (name, context) {
|
279
|
-
if (!(name in this._partialCache) && this._loadPartial) {
|
280
|
-
this.compilePartial(name, this._loadPartial(name));
|
281
|
-
}
|
282
|
-
|
283
|
-
var fn = this._partialCache[name];
|
221
|
+
/**
|
222
|
+
* Low-level function that renders the given `tokens` using the given `writer`
|
223
|
+
* and `context`. The `template` string is only needed for templates that use
|
224
|
+
* higher-order sections to extract the portion of the original template that
|
225
|
+
* was contained in that section.
|
226
|
+
*/
|
227
|
+
function renderTokens(tokens, writer, context, template) {
|
228
|
+
var buffer = '';
|
284
229
|
|
285
|
-
|
286
|
-
|
230
|
+
var token, tokenValue, value;
|
231
|
+
for (var i = 0, len = tokens.length; i < len; ++i) {
|
232
|
+
token = tokens[i];
|
233
|
+
tokenValue = token[1];
|
287
234
|
|
288
|
-
|
289
|
-
|
235
|
+
switch (token[0]) {
|
236
|
+
case '#':
|
237
|
+
value = context.lookup(tokenValue);
|
290
238
|
|
291
|
-
|
292
|
-
|
293
|
-
|
239
|
+
if (typeof value === 'object') {
|
240
|
+
if (isArray(value)) {
|
241
|
+
for (var j = 0, jlen = value.length; j < jlen; ++j) {
|
242
|
+
buffer += renderTokens(token[4], writer, context.push(value[j]), template);
|
243
|
+
}
|
244
|
+
} else if (value) {
|
245
|
+
buffer += renderTokens(token[4], writer, context.push(value), template);
|
246
|
+
}
|
247
|
+
} else if (typeof value === 'function') {
|
248
|
+
var text = template == null ? null : template.slice(token[3], token[5]);
|
249
|
+
value = value.call(context.view, text, function (template) {
|
250
|
+
return writer.render(template, context);
|
251
|
+
});
|
252
|
+
if (value != null) buffer += value;
|
253
|
+
} else if (value) {
|
254
|
+
buffer += renderTokens(token[4], writer, context, template);
|
255
|
+
}
|
294
256
|
|
295
|
-
|
296
|
-
|
257
|
+
break;
|
258
|
+
case '^':
|
259
|
+
value = context.lookup(tokenValue);
|
297
260
|
|
298
|
-
|
299
|
-
|
300
|
-
|
261
|
+
// Use JavaScript's definition of falsy. Include empty arrays.
|
262
|
+
// See https://github.com/janl/mustache.js/issues/186
|
263
|
+
if (!value || (isArray(value) && value.length === 0)) {
|
264
|
+
buffer += renderTokens(token[4], writer, context, template);
|
265
|
+
}
|
301
266
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
267
|
+
break;
|
268
|
+
case '>':
|
269
|
+
value = writer.getPartial(tokenValue);
|
270
|
+
if (typeof value === 'function') buffer += value(context);
|
271
|
+
break;
|
272
|
+
case '&':
|
273
|
+
value = context.lookup(tokenValue);
|
274
|
+
if (value != null) buffer += value;
|
275
|
+
break;
|
276
|
+
case 'name':
|
277
|
+
value = context.lookup(tokenValue);
|
278
|
+
if (value != null) buffer += mustache.escape(value);
|
279
|
+
break;
|
280
|
+
case 'text':
|
281
|
+
buffer += tokenValue;
|
282
|
+
break;
|
315
283
|
}
|
316
|
-
|
317
|
-
return subRenders[i];
|
318
284
|
}
|
319
285
|
|
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
|
-
};
|
286
|
+
return buffer;
|
352
287
|
}
|
353
288
|
|
354
289
|
/**
|
@@ -395,12 +330,14 @@
|
|
395
330
|
var token, lastToken;
|
396
331
|
for (var i = 0, len = tokens.length; i < len; ++i) {
|
397
332
|
token = tokens[i];
|
398
|
-
if (token
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
333
|
+
if (token) {
|
334
|
+
if (token[0] === 'text' && lastToken && lastToken[0] === 'text') {
|
335
|
+
lastToken[1] += token[1];
|
336
|
+
lastToken[3] = token[3];
|
337
|
+
} else {
|
338
|
+
lastToken = token;
|
339
|
+
squashedTokens.push(token);
|
340
|
+
}
|
404
341
|
}
|
405
342
|
}
|
406
343
|
|
@@ -409,8 +346,8 @@
|
|
409
346
|
|
410
347
|
function escapeTags(tags) {
|
411
348
|
return [
|
412
|
-
new RegExp(
|
413
|
-
new RegExp("\\s*" +
|
349
|
+
new RegExp(escapeRegExp(tags[0]) + "\\s*"),
|
350
|
+
new RegExp("\\s*" + escapeRegExp(tags[1]))
|
414
351
|
];
|
415
352
|
}
|
416
353
|
|
@@ -420,14 +357,12 @@
|
|
420
357
|
* opening and closing tags used in the template (e.g. ["<%", "%>"]). Of
|
421
358
|
* course, the default is to use mustaches (i.e. Mustache.tags).
|
422
359
|
*/
|
423
|
-
|
360
|
+
function parseTemplate(template, tags) {
|
424
361
|
template = template || '';
|
425
|
-
tags = tags ||
|
362
|
+
tags = tags || mustache.tags;
|
426
363
|
|
427
364
|
if (typeof tags === 'string') tags = tags.split(spaceRe);
|
428
|
-
if (tags.length !== 2)
|
429
|
-
throw new Error('Invalid tags: ' + tags.join(', '));
|
430
|
-
}
|
365
|
+
if (tags.length !== 2) throw new Error('Invalid tags: ' + tags.join(', '));
|
431
366
|
|
432
367
|
var tagRes = escapeTags(tags);
|
433
368
|
var scanner = new Scanner(template);
|
@@ -443,7 +378,7 @@
|
|
443
378
|
function stripSpace() {
|
444
379
|
if (hasTag && !nonSpace) {
|
445
380
|
while (spaces.length) {
|
446
|
-
tokens
|
381
|
+
delete tokens[spaces.pop()];
|
447
382
|
}
|
448
383
|
} else {
|
449
384
|
spaces = [];
|
@@ -453,11 +388,12 @@
|
|
453
388
|
nonSpace = false;
|
454
389
|
}
|
455
390
|
|
456
|
-
var start, type, value, chr;
|
391
|
+
var start, type, value, chr, token;
|
457
392
|
while (!scanner.eos()) {
|
458
393
|
start = scanner.pos;
|
459
|
-
value = scanner.scanUntil(tagRes[0]);
|
460
394
|
|
395
|
+
// Match any text between tags.
|
396
|
+
value = scanner.scanUntil(tagRes[0]);
|
461
397
|
if (value) {
|
462
398
|
for (var i = 0, len = value.length; i < len; ++i) {
|
463
399
|
chr = value.charAt(i);
|
@@ -468,135 +404,127 @@
|
|
468
404
|
nonSpace = true;
|
469
405
|
}
|
470
406
|
|
471
|
-
tokens.push([
|
407
|
+
tokens.push(['text', chr, start, start + 1]);
|
472
408
|
start += 1;
|
473
409
|
|
474
|
-
|
475
|
-
|
476
|
-
}
|
410
|
+
// Check for whitespace on the current line.
|
411
|
+
if (chr == '\n') stripSpace();
|
477
412
|
}
|
478
413
|
}
|
479
414
|
|
480
|
-
start = scanner.pos;
|
481
|
-
|
482
415
|
// Match the opening tag.
|
483
|
-
if (!scanner.scan(tagRes[0]))
|
484
|
-
break;
|
485
|
-
}
|
486
|
-
|
416
|
+
if (!scanner.scan(tagRes[0])) break;
|
487
417
|
hasTag = true;
|
488
|
-
type = scanner.scan(tagRe) || "name";
|
489
418
|
|
490
|
-
//
|
419
|
+
// Get the tag type.
|
420
|
+
type = scanner.scan(tagRe) || 'name';
|
491
421
|
scanner.scan(whiteRe);
|
492
422
|
|
493
|
-
//
|
494
|
-
if (type ===
|
423
|
+
// Get the tag value.
|
424
|
+
if (type === '=') {
|
495
425
|
value = scanner.scanUntil(eqRe);
|
496
426
|
scanner.scan(eqRe);
|
497
427
|
scanner.scanUntil(tagRes[1]);
|
498
|
-
} else if (type ===
|
499
|
-
|
500
|
-
value = scanner.scanUntil(closeRe);
|
428
|
+
} else if (type === '{') {
|
429
|
+
value = scanner.scanUntil(new RegExp('\\s*' + escapeRegExp('}' + tags[1])));
|
501
430
|
scanner.scan(curlyRe);
|
502
431
|
scanner.scanUntil(tagRes[1]);
|
503
|
-
type =
|
432
|
+
type = '&';
|
504
433
|
} else {
|
505
434
|
value = scanner.scanUntil(tagRes[1]);
|
506
435
|
}
|
507
436
|
|
508
437
|
// 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
|
-
}
|
438
|
+
if (!scanner.scan(tagRes[1])) throw new Error('Unclosed tag at ' + scanner.pos);
|
525
439
|
|
526
|
-
|
440
|
+
token = [type, value, start, scanner.pos];
|
527
441
|
tokens.push(token);
|
528
442
|
|
529
443
|
if (type === '#' || type === '^') {
|
530
444
|
sections.push(token);
|
531
|
-
} else if (type ===
|
445
|
+
} else if (type === '/') {
|
446
|
+
// Check section nesting.
|
447
|
+
if (sections.length === 0) throw new Error('Unopened section "' + value + '" at ' + start);
|
448
|
+
var openSection = sections.pop();
|
449
|
+
if (openSection[1] !== value) throw new Error('Unclosed section "' + openSection[1] + '" at ' + start);
|
450
|
+
} else if (type === 'name' || type === '{' || type === '&') {
|
532
451
|
nonSpace = true;
|
533
|
-
} else if (type ===
|
452
|
+
} else if (type === '=') {
|
534
453
|
// Set the tags for the next time around.
|
535
454
|
tags = value.split(spaceRe);
|
536
|
-
|
537
|
-
if (tags.length !== 2) {
|
538
|
-
throw new Error('Invalid tags at ' + start + ': ' + tags.join(', '));
|
539
|
-
}
|
540
|
-
|
455
|
+
if (tags.length !== 2) throw new Error('Invalid tags at ' + start + ': ' + tags.join(', '));
|
541
456
|
tagRes = escapeTags(tags);
|
542
457
|
}
|
543
458
|
}
|
544
459
|
|
545
460
|
// Make sure there are no open sections when we're done.
|
546
|
-
var
|
547
|
-
if (section)
|
548
|
-
throw new Error('Unclosed section "' + section[1] + '" at ' + scanner.pos);
|
549
|
-
}
|
461
|
+
var openSection = sections.pop();
|
462
|
+
if (openSection) throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos);
|
550
463
|
|
551
|
-
|
552
|
-
|
464
|
+
tokens = squashTokens(tokens);
|
465
|
+
|
466
|
+
return nestTokens(tokens);
|
467
|
+
}
|
553
468
|
|
554
|
-
|
555
|
-
|
556
|
-
|
469
|
+
mustache.name = "mustache.js";
|
470
|
+
mustache.version = "0.7.2";
|
471
|
+
mustache.tags = ["{{", "}}"];
|
472
|
+
|
473
|
+
mustache.Scanner = Scanner;
|
474
|
+
mustache.Context = Context;
|
475
|
+
mustache.Writer = Writer;
|
476
|
+
|
477
|
+
mustache.parse = parseTemplate;
|
478
|
+
|
479
|
+
// Export the escaping function so that the user may override it.
|
480
|
+
// See https://github.com/janl/mustache.js/issues/244
|
481
|
+
mustache.escape = escapeHtml;
|
482
|
+
|
483
|
+
// All Mustache.* functions use this writer.
|
484
|
+
var defaultWriter = new Writer();
|
557
485
|
|
558
486
|
/**
|
559
487
|
* Clears all cached templates and partials in the default writer.
|
560
488
|
*/
|
561
|
-
|
562
|
-
return
|
489
|
+
mustache.clearCache = function () {
|
490
|
+
return defaultWriter.clearCache();
|
563
491
|
};
|
564
492
|
|
565
493
|
/**
|
566
494
|
* Compiles the given `template` to a reusable function using the default
|
567
495
|
* writer.
|
568
496
|
*/
|
569
|
-
|
570
|
-
return
|
497
|
+
mustache.compile = function (template, tags) {
|
498
|
+
return defaultWriter.compile(template, tags);
|
571
499
|
};
|
572
500
|
|
573
501
|
/**
|
574
502
|
* Compiles the partial with the given `name` and `template` to a reusable
|
575
503
|
* function using the default writer.
|
576
504
|
*/
|
577
|
-
|
578
|
-
return
|
505
|
+
mustache.compilePartial = function (name, template, tags) {
|
506
|
+
return defaultWriter.compilePartial(name, template, tags);
|
579
507
|
};
|
580
508
|
|
581
509
|
/**
|
582
510
|
* Compiles the given array of tokens (the output of a parse) to a reusable
|
583
511
|
* function using the default writer.
|
584
512
|
*/
|
585
|
-
|
586
|
-
return
|
513
|
+
mustache.compileTokens = function (tokens, template) {
|
514
|
+
return defaultWriter.compileTokens(tokens, template);
|
587
515
|
};
|
588
516
|
|
589
517
|
/**
|
590
518
|
* Renders the `template` with the given `view` and `partials` using the
|
591
519
|
* default writer.
|
592
520
|
*/
|
593
|
-
|
594
|
-
return
|
521
|
+
mustache.render = function (template, view, partials) {
|
522
|
+
return defaultWriter.render(template, view, partials);
|
595
523
|
};
|
596
524
|
|
597
525
|
// This is here for backwards compatibility with 0.4.x.
|
598
|
-
|
599
|
-
var result =
|
526
|
+
mustache.to_html = function (template, view, partials, send) {
|
527
|
+
var result = mustache.render(template, view, partials);
|
600
528
|
|
601
529
|
if (typeof send === "function") {
|
602
530
|
send(result);
|
@@ -605,6 +533,4 @@
|
|
605
533
|
}
|
606
534
|
};
|
607
535
|
|
608
|
-
|
609
|
-
|
610
|
-
}())));
|
536
|
+
}));
|
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.4
|
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-06-
|
11
|
+
date: 2013-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|