smt_rails 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.ruby-version +1 -0
- data/lib/smt_rails/tilt.rb +40 -12
- data/lib/smt_rails/version.rb +1 -1
- data/smt_rails.gemspec +1 -3
- data/vendor/assets/javascripts/mustache.js +156 -243
- metadata +40 -19
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0
|
data/lib/smt_rails/tilt.rb
CHANGED
@@ -1,6 +1,38 @@
|
|
1
1
|
require 'tilt'
|
2
|
+
require 'execjs'
|
3
|
+
require 'pathname'
|
2
4
|
|
3
5
|
module SmtRails
|
6
|
+
class MustacheCompile
|
7
|
+
class << self
|
8
|
+
def compile(source, options = {})
|
9
|
+
context.eval("Mustache.compile(#{source.inspect})")
|
10
|
+
end
|
11
|
+
|
12
|
+
def compilePartial(name, source, options = {})
|
13
|
+
context.eval("Mustache.compilePartial(#{name.inspect}, #{source.inspect})")
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def context
|
19
|
+
@context ||= ExecJS.compile(source)
|
20
|
+
end
|
21
|
+
|
22
|
+
def source
|
23
|
+
@source ||= path.read
|
24
|
+
end
|
25
|
+
|
26
|
+
def path
|
27
|
+
@path ||= assets_path.join('javascripts', 'mustache.js')
|
28
|
+
end
|
29
|
+
|
30
|
+
def assets_path
|
31
|
+
@assets_path ||= Pathname(__FILE__).dirname.join('..', '..', 'vendor', 'assets')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
4
36
|
class Tilt < Tilt::Template
|
5
37
|
def self.default_mime_type
|
6
38
|
'application/javascript'
|
@@ -15,24 +47,20 @@ module SmtRails
|
|
15
47
|
def evaluate(scope, locals, &block)
|
16
48
|
template_key = path_to_key scope
|
17
49
|
<<-MustacheTemplate
|
18
|
-
(function() {
|
50
|
+
(function() {
|
19
51
|
#{namespace} || (#{namespace} = {});
|
20
|
-
#{namespace}
|
21
|
-
|
52
|
+
#{namespace}Cache || (#{namespace}Cache = {});
|
53
|
+
#{namespace}Cache[#{template_key.inspect}] = Mustache.compile(#{data.inspect});
|
54
|
+
Mustache.compilePartial(#{template_key.inspect}, #{data.inspect});
|
55
|
+
|
22
56
|
#{namespace}[#{template_key.inspect}] = function(object) {
|
23
|
-
|
24
|
-
|
25
|
-
return template;
|
26
|
-
} else {
|
27
|
-
return Mustache.render(template, object, #{SmtRails.template_namespace}Partials);
|
28
|
-
}
|
57
|
+
if (!object){ object = {}; }
|
58
|
+
return #{SmtRails.template_namespace}Cache[#{template_key.inspect}](object);
|
29
59
|
};
|
30
|
-
|
31
|
-
#{namespace}Partials[#{template_key.inspect}] = #{namespace}[#{template_key.inspect}]();
|
32
60
|
}).call(this);
|
33
61
|
MustacheTemplate
|
34
62
|
end
|
35
|
-
|
63
|
+
|
36
64
|
def path_to_key(scope)
|
37
65
|
path = scope.logical_path.to_s.split('/')
|
38
66
|
path.last.gsub!(/^_/, '')
|
data/lib/smt_rails/version.rb
CHANGED
data/smt_rails.gemspec
CHANGED
@@ -7,12 +7,10 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.description = %q{Shared mustache templates for rails 3}
|
8
8
|
gem.summary = %q{Shared mustache templates for rails 3}
|
9
9
|
gem.homepage = "https://github.com/railsware/smt_rails"
|
10
|
-
|
10
|
+
|
11
11
|
gem.extra_rdoc_files = [ "LICENSE", "README.md" ]
|
12
12
|
gem.rdoc_options = ["--charset=UTF-8"]
|
13
13
|
|
14
|
-
#gem.add_development_dependency "jasmine", ">= 1.0.0"
|
15
|
-
|
16
14
|
gem.add_runtime_dependency "rails", ">= 3.1.0"
|
17
15
|
gem.add_runtime_dependency "tilt", ">= 1.3.3"
|
18
16
|
gem.add_runtime_dependency "sprockets", ">= 2.0.3"
|
@@ -5,22 +5,20 @@
|
|
5
5
|
|
6
6
|
/*global define: false*/
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
if (typeof
|
12
|
-
|
13
|
-
} else if (typeof define === "function") {
|
14
|
-
define(exports); // AMD
|
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
|
15
13
|
} else {
|
16
|
-
Mustache =
|
14
|
+
root.Mustache = factory; // <script>
|
17
15
|
}
|
18
|
-
}((function () {
|
16
|
+
}(this, (function () {
|
19
17
|
|
20
18
|
var exports = {};
|
21
19
|
|
22
20
|
exports.name = "mustache.js";
|
23
|
-
exports.version = "0.7.
|
21
|
+
exports.version = "0.7.2";
|
24
22
|
exports.tags = ["{{", "}}"];
|
25
23
|
|
26
24
|
exports.Scanner = Scanner;
|
@@ -34,10 +32,13 @@ var Mustache;
|
|
34
32
|
var curlyRe = /\s*\}/;
|
35
33
|
var tagRe = /#|\^|\/|>|\{|&|=|!/;
|
36
34
|
|
35
|
+
var _test = RegExp.prototype.test;
|
36
|
+
var _toString = Object.prototype.toString;
|
37
|
+
|
37
38
|
// Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
|
38
39
|
// See https://github.com/janl/mustache.js/issues/189
|
39
40
|
function testRe(re, string) {
|
40
|
-
return
|
41
|
+
return _test.call(re, string);
|
41
42
|
}
|
42
43
|
|
43
44
|
function isWhitespace(string) {
|
@@ -45,7 +46,7 @@ var Mustache;
|
|
45
46
|
}
|
46
47
|
|
47
48
|
var isArray = Array.isArray || function (obj) {
|
48
|
-
return
|
49
|
+
return _toString.call(obj) === '[object Array]';
|
49
50
|
};
|
50
51
|
|
51
52
|
function escapeRe(string) {
|
@@ -128,17 +129,13 @@ var Mustache;
|
|
128
129
|
function Context(view, parent) {
|
129
130
|
this.view = view;
|
130
131
|
this.parent = parent;
|
131
|
-
this.
|
132
|
+
this._cache = {};
|
132
133
|
}
|
133
134
|
|
134
135
|
Context.make = function (view) {
|
135
136
|
return (view instanceof Context) ? view : new Context(view);
|
136
137
|
};
|
137
138
|
|
138
|
-
Context.prototype.clearCache = function () {
|
139
|
-
this._cache = {};
|
140
|
-
};
|
141
|
-
|
142
139
|
Context.prototype.push = function (view) {
|
143
140
|
return new Context(view, this);
|
144
141
|
};
|
@@ -147,17 +144,15 @@ var Mustache;
|
|
147
144
|
var value = this._cache[name];
|
148
145
|
|
149
146
|
if (!value) {
|
150
|
-
if (name
|
147
|
+
if (name == '.') {
|
151
148
|
value = this.view;
|
152
149
|
} else {
|
153
150
|
var context = this;
|
154
151
|
|
155
152
|
while (context) {
|
156
|
-
if (name.indexOf(
|
157
|
-
var names = name.split("."), i = 0;
|
158
|
-
|
153
|
+
if (name.indexOf('.') > 0) {
|
159
154
|
value = context.view;
|
160
|
-
|
155
|
+
var names = name.split('.'), i = 0;
|
161
156
|
while (value && i < names.length) {
|
162
157
|
value = value[names[i++]];
|
163
158
|
}
|
@@ -165,9 +160,7 @@ var Mustache;
|
|
165
160
|
value = context.view[name];
|
166
161
|
}
|
167
162
|
|
168
|
-
if (value != null)
|
169
|
-
break;
|
170
|
-
}
|
163
|
+
if (value != null) break;
|
171
164
|
|
172
165
|
context = context.parent;
|
173
166
|
}
|
@@ -176,9 +169,7 @@ var Mustache;
|
|
176
169
|
this._cache[name] = value;
|
177
170
|
}
|
178
171
|
|
179
|
-
if (typeof value ===
|
180
|
-
value = value.call(this.view);
|
181
|
-
}
|
172
|
+
if (typeof value === 'function') value = value.call(this.view);
|
182
173
|
|
183
174
|
return value;
|
184
175
|
};
|
@@ -209,13 +200,19 @@ var Mustache;
|
|
209
200
|
return fn;
|
210
201
|
};
|
211
202
|
|
203
|
+
Writer.prototype.getPartial = function (name) {
|
204
|
+
if (!(name in this._partialCache) && this._loadPartial) {
|
205
|
+
this.compilePartial(name, this._loadPartial(name));
|
206
|
+
}
|
207
|
+
|
208
|
+
return this._partialCache[name];
|
209
|
+
};
|
210
|
+
|
212
211
|
Writer.prototype.compileTokens = function (tokens, template) {
|
213
|
-
var fn = compileTokens(tokens);
|
214
212
|
var self = this;
|
215
|
-
|
216
213
|
return function (view, partials) {
|
217
214
|
if (partials) {
|
218
|
-
if (typeof partials ===
|
215
|
+
if (typeof partials === 'function') {
|
219
216
|
self._loadPartial = partials;
|
220
217
|
} else {
|
221
218
|
for (var name in partials) {
|
@@ -224,7 +221,7 @@ var Mustache;
|
|
224
221
|
}
|
225
222
|
}
|
226
223
|
|
227
|
-
return
|
224
|
+
return renderTokens(tokens, self, Context.make(view), template);
|
228
225
|
};
|
229
226
|
};
|
230
227
|
|
@@ -232,195 +229,105 @@ var Mustache;
|
|
232
229
|
return this.compile(template)(view, partials);
|
233
230
|
};
|
234
231
|
|
235
|
-
Writer.prototype._section = function (name, context, text, callback) {
|
236
|
-
var value = context.lookup(name);
|
237
|
-
|
238
|
-
switch (typeof value) {
|
239
|
-
case "object":
|
240
|
-
if (isArray(value)) {
|
241
|
-
var buffer = "";
|
242
|
-
|
243
|
-
for (var i = 0, len = value.length; i < len; ++i) {
|
244
|
-
buffer += callback(this, context.push(value[i]));
|
245
|
-
}
|
246
|
-
|
247
|
-
return buffer;
|
248
|
-
}
|
249
|
-
|
250
|
-
return value ? callback(this, context.push(value)) : "";
|
251
|
-
case "function":
|
252
|
-
var self = this;
|
253
|
-
var scopedRender = function (template) {
|
254
|
-
return self.render(template, context);
|
255
|
-
};
|
256
|
-
|
257
|
-
return value.call(context.view, text, scopedRender) || "";
|
258
|
-
default:
|
259
|
-
if (value) {
|
260
|
-
return callback(this, context);
|
261
|
-
}
|
262
|
-
}
|
263
|
-
|
264
|
-
return "";
|
265
|
-
};
|
266
|
-
|
267
|
-
Writer.prototype._inverted = function (name, context, callback) {
|
268
|
-
var value = context.lookup(name);
|
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
|
-
return callback(this, context);
|
274
|
-
}
|
275
|
-
|
276
|
-
return "";
|
277
|
-
};
|
278
|
-
|
279
|
-
Writer.prototype._partial = function (name, context) {
|
280
|
-
if (!(name in this._partialCache) && this._loadPartial) {
|
281
|
-
this.compilePartial(name, this._loadPartial(name));
|
282
|
-
}
|
283
|
-
|
284
|
-
var fn = this._partialCache[name];
|
285
|
-
|
286
|
-
return fn ? fn(context) : "";
|
287
|
-
};
|
288
|
-
|
289
|
-
Writer.prototype._name = function (name, context) {
|
290
|
-
var value = context.lookup(name);
|
291
|
-
|
292
|
-
if (typeof value === "function") {
|
293
|
-
value = value.call(context.view);
|
294
|
-
}
|
295
|
-
|
296
|
-
return (value == null) ? "" : String(value);
|
297
|
-
};
|
298
|
-
|
299
|
-
Writer.prototype._escaped = function (name, context) {
|
300
|
-
return exports.escape(this._name(name, context));
|
301
|
-
};
|
302
|
-
|
303
232
|
/**
|
304
|
-
*
|
305
|
-
*
|
306
|
-
*
|
233
|
+
* Low-level function that renders the given `tokens` using the given `writer`
|
234
|
+
* and `context`. The `template` string is only needed for templates that use
|
235
|
+
* higher-order sections to extract the portion of the original template that
|
236
|
+
* was contained in that section.
|
307
237
|
*/
|
308
|
-
function
|
309
|
-
var
|
310
|
-
var end = start;
|
311
|
-
|
312
|
-
var tokens;
|
313
|
-
while ((tokens = token[4]) && tokens.length) {
|
314
|
-
token = tokens[tokens.length - 1];
|
315
|
-
end = token[3];
|
316
|
-
}
|
238
|
+
function renderTokens(tokens, writer, context, template) {
|
239
|
+
var buffer = '';
|
317
240
|
|
318
|
-
|
319
|
-
|
241
|
+
var token, tokenValue, value;
|
242
|
+
for (var i = 0, len = tokens.length; i < len; ++i) {
|
243
|
+
token = tokens[i];
|
244
|
+
tokenValue = token[1];
|
320
245
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
*/
|
325
|
-
function compileTokens(tokens) {
|
326
|
-
var subRenders = {};
|
327
|
-
|
328
|
-
function subRender(i, tokens, template) {
|
329
|
-
if (!subRenders[i]) {
|
330
|
-
var fn = compileTokens(tokens);
|
331
|
-
subRenders[i] = function (writer, context) {
|
332
|
-
return fn(writer, context, template);
|
333
|
-
};
|
334
|
-
}
|
246
|
+
switch (token[0]) {
|
247
|
+
case '#':
|
248
|
+
value = context.lookup(tokenValue);
|
335
249
|
|
336
|
-
|
337
|
-
|
250
|
+
if (typeof value === 'object') {
|
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 (typeof value === 'function') {
|
259
|
+
var text = template == null ? null : template.slice(token[3], token[5]);
|
260
|
+
value = value.call(context.view, text, function (template) {
|
261
|
+
return writer.render(template, context);
|
262
|
+
});
|
263
|
+
if (value != null) buffer += value;
|
264
|
+
} else if (value) {
|
265
|
+
buffer += renderTokens(token[4], writer, context, template);
|
266
|
+
}
|
338
267
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
case "#":
|
348
|
-
sectionText = template.slice.apply(template, sectionBounds(token));
|
349
|
-
buffer += writer._section(token[1], context, sectionText, subRender(i, token[4], template));
|
350
|
-
break;
|
351
|
-
case "^":
|
352
|
-
buffer += writer._inverted(token[1], context, subRender(i, token[4], template));
|
353
|
-
break;
|
354
|
-
case ">":
|
355
|
-
buffer += writer._partial(token[1], context);
|
356
|
-
break;
|
357
|
-
case "&":
|
358
|
-
buffer += writer._name(token[1], context);
|
359
|
-
break;
|
360
|
-
case "name":
|
361
|
-
buffer += writer._escaped(token[1], context);
|
362
|
-
break;
|
363
|
-
case "text":
|
364
|
-
buffer += token[1];
|
365
|
-
break;
|
268
|
+
break;
|
269
|
+
case '^':
|
270
|
+
value = context.lookup(tokenValue);
|
271
|
+
|
272
|
+
// Use JavaScript's definition of falsy. Include empty arrays.
|
273
|
+
// See https://github.com/janl/mustache.js/issues/186
|
274
|
+
if (!value || (isArray(value) && value.length === 0)) {
|
275
|
+
buffer += renderTokens(token[4], writer, context, template);
|
366
276
|
}
|
277
|
+
|
278
|
+
break;
|
279
|
+
case '>':
|
280
|
+
value = writer.getPartial(tokenValue);
|
281
|
+
if (typeof value === 'function') buffer += value(context);
|
282
|
+
break;
|
283
|
+
case '&':
|
284
|
+
value = context.lookup(tokenValue);
|
285
|
+
if (value != null) buffer += value;
|
286
|
+
break;
|
287
|
+
case 'name':
|
288
|
+
value = context.lookup(tokenValue);
|
289
|
+
if (value != null) buffer += exports.escape(value);
|
290
|
+
break;
|
291
|
+
case 'text':
|
292
|
+
buffer += tokenValue;
|
293
|
+
break;
|
367
294
|
}
|
295
|
+
}
|
368
296
|
|
369
|
-
|
370
|
-
};
|
297
|
+
return buffer;
|
371
298
|
}
|
372
299
|
|
373
300
|
/**
|
374
301
|
* Forms the given array of `tokens` into a nested tree structure where
|
375
|
-
* tokens that represent a section have
|
376
|
-
* all tokens in that section
|
302
|
+
* tokens that represent a section have two additional items: 1) an array of
|
303
|
+
* all tokens that appear in that section and 2) the index in the original
|
304
|
+
* template that represents the end of that section.
|
377
305
|
*/
|
378
306
|
function nestTokens(tokens) {
|
379
307
|
var tree = [];
|
380
308
|
var collector = tree;
|
381
309
|
var sections = [];
|
382
|
-
var token, section;
|
383
310
|
|
384
|
-
|
311
|
+
var token;
|
312
|
+
for (var i = 0, len = tokens.length; i < len; ++i) {
|
385
313
|
token = tokens[i];
|
386
|
-
|
387
314
|
switch (token[0]) {
|
388
|
-
case
|
389
|
-
case
|
390
|
-
token[4] = [];
|
315
|
+
case '#':
|
316
|
+
case '^':
|
391
317
|
sections.push(token);
|
392
318
|
collector.push(token);
|
393
|
-
collector = token[4];
|
319
|
+
collector = token[4] = [];
|
394
320
|
break;
|
395
|
-
case
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
section = sections.pop();
|
401
|
-
|
402
|
-
if (section[1] !== token[1]) {
|
403
|
-
throw new Error("Unclosed section: " + section[1]);
|
404
|
-
}
|
405
|
-
|
406
|
-
if (sections.length > 0) {
|
407
|
-
collector = sections[sections.length - 1][4];
|
408
|
-
} else {
|
409
|
-
collector = tree;
|
410
|
-
}
|
321
|
+
case '/':
|
322
|
+
var section = sections.pop();
|
323
|
+
section[5] = token[2];
|
324
|
+
collector = sections.length > 0 ? sections[sections.length - 1][4] : tree;
|
411
325
|
break;
|
412
326
|
default:
|
413
327
|
collector.push(token);
|
414
328
|
}
|
415
329
|
}
|
416
330
|
|
417
|
-
// Make sure there were no open sections when we're done.
|
418
|
-
section = sections.pop();
|
419
|
-
|
420
|
-
if (section) {
|
421
|
-
throw new Error("Unclosed section: " + section[1]);
|
422
|
-
}
|
423
|
-
|
424
331
|
return tree;
|
425
332
|
}
|
426
333
|
|
@@ -429,26 +336,26 @@ var Mustache;
|
|
429
336
|
* to a single token.
|
430
337
|
*/
|
431
338
|
function squashTokens(tokens) {
|
432
|
-
var
|
339
|
+
var squashedTokens = [];
|
433
340
|
|
434
|
-
|
341
|
+
var token, lastToken;
|
342
|
+
for (var i = 0, len = tokens.length; i < len; ++i) {
|
435
343
|
token = tokens[i];
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
344
|
+
if (token) {
|
345
|
+
if (token[0] === 'text' && lastToken && lastToken[0] === 'text') {
|
346
|
+
lastToken[1] += token[1];
|
347
|
+
lastToken[3] = token[3];
|
348
|
+
} else {
|
349
|
+
lastToken = token;
|
350
|
+
squashedTokens.push(token);
|
351
|
+
}
|
443
352
|
}
|
444
353
|
}
|
354
|
+
|
355
|
+
return squashedTokens;
|
445
356
|
}
|
446
357
|
|
447
358
|
function escapeTags(tags) {
|
448
|
-
if (tags.length !== 2) {
|
449
|
-
throw new Error("Invalid tags: " + tags.join(" "));
|
450
|
-
}
|
451
|
-
|
452
359
|
return [
|
453
360
|
new RegExp(escapeRe(tags[0]) + "\\s*"),
|
454
361
|
new RegExp("\\s*" + escapeRe(tags[1]))
|
@@ -462,22 +369,27 @@ var Mustache;
|
|
462
369
|
* course, the default is to use mustaches (i.e. Mustache.tags).
|
463
370
|
*/
|
464
371
|
exports.parse = function (template, tags) {
|
372
|
+
template = template || '';
|
465
373
|
tags = tags || exports.tags;
|
466
374
|
|
375
|
+
if (typeof tags === 'string') tags = tags.split(spaceRe);
|
376
|
+
if (tags.length !== 2) throw new Error('Invalid tags: ' + tags.join(', '));
|
377
|
+
|
467
378
|
var tagRes = escapeTags(tags);
|
468
379
|
var scanner = new Scanner(template);
|
469
380
|
|
470
|
-
var
|
471
|
-
|
472
|
-
|
473
|
-
|
381
|
+
var sections = []; // Stack to hold section tokens
|
382
|
+
var tokens = []; // Buffer to hold the tokens
|
383
|
+
var spaces = []; // Indices of whitespace tokens on the current line
|
384
|
+
var hasTag = false; // Is there a {{tag}} on the current line?
|
385
|
+
var nonSpace = false; // Is there a non-space char on the current line?
|
474
386
|
|
475
387
|
// Strips all whitespace tokens array for the current line
|
476
388
|
// if there was a {{#tag}} on it and otherwise only space.
|
477
389
|
function stripSpace() {
|
478
390
|
if (hasTag && !nonSpace) {
|
479
391
|
while (spaces.length) {
|
480
|
-
tokens
|
392
|
+
delete tokens[spaces.pop()];
|
481
393
|
}
|
482
394
|
} else {
|
483
395
|
spaces = [];
|
@@ -487,12 +399,12 @@ var Mustache;
|
|
487
399
|
nonSpace = false;
|
488
400
|
}
|
489
401
|
|
490
|
-
var start, type, value, chr;
|
491
|
-
|
402
|
+
var start, type, value, chr, token;
|
492
403
|
while (!scanner.eos()) {
|
493
404
|
start = scanner.pos;
|
494
|
-
value = scanner.scanUntil(tagRes[0]);
|
495
405
|
|
406
|
+
// Match any text between tags.
|
407
|
+
value = scanner.scanUntil(tagRes[0]);
|
496
408
|
if (value) {
|
497
409
|
for (var i = 0, len = value.length; i < len; ++i) {
|
498
410
|
chr = value.charAt(i);
|
@@ -503,68 +415,69 @@ var Mustache;
|
|
503
415
|
nonSpace = true;
|
504
416
|
}
|
505
417
|
|
506
|
-
tokens.push([
|
418
|
+
tokens.push(['text', chr, start, start + 1]);
|
507
419
|
start += 1;
|
508
420
|
|
509
|
-
|
510
|
-
|
511
|
-
}
|
421
|
+
// Check for whitespace on the current line.
|
422
|
+
if (chr == '\n') stripSpace();
|
512
423
|
}
|
513
424
|
}
|
514
425
|
|
515
|
-
start = scanner.pos;
|
516
|
-
|
517
426
|
// Match the opening tag.
|
518
|
-
if (!scanner.scan(tagRes[0]))
|
519
|
-
break;
|
520
|
-
}
|
521
|
-
|
427
|
+
if (!scanner.scan(tagRes[0])) break;
|
522
428
|
hasTag = true;
|
523
|
-
type = scanner.scan(tagRe) || "name";
|
524
429
|
|
525
|
-
//
|
430
|
+
// Get the tag type.
|
431
|
+
type = scanner.scan(tagRe) || 'name';
|
526
432
|
scanner.scan(whiteRe);
|
527
433
|
|
528
|
-
//
|
529
|
-
if (type ===
|
434
|
+
// Get the tag value.
|
435
|
+
if (type === '=') {
|
530
436
|
value = scanner.scanUntil(eqRe);
|
531
437
|
scanner.scan(eqRe);
|
532
438
|
scanner.scanUntil(tagRes[1]);
|
533
|
-
} else if (type ===
|
534
|
-
|
535
|
-
value = scanner.scanUntil(closeRe);
|
439
|
+
} else if (type === '{') {
|
440
|
+
value = scanner.scanUntil(new RegExp('\\s*' + escapeRe('}' + tags[1])));
|
536
441
|
scanner.scan(curlyRe);
|
537
442
|
scanner.scanUntil(tagRes[1]);
|
538
|
-
type =
|
443
|
+
type = '&';
|
539
444
|
} else {
|
540
445
|
value = scanner.scanUntil(tagRes[1]);
|
541
446
|
}
|
542
447
|
|
543
448
|
// Match the closing tag.
|
544
|
-
if (!scanner.scan(tagRes[1]))
|
545
|
-
throw new Error("Unclosed tag at " + scanner.pos);
|
546
|
-
}
|
449
|
+
if (!scanner.scan(tagRes[1])) throw new Error('Unclosed tag at ' + scanner.pos);
|
547
450
|
|
548
|
-
|
451
|
+
token = [type, value, start, scanner.pos];
|
452
|
+
tokens.push(token);
|
549
453
|
|
550
|
-
if (type ===
|
454
|
+
if (type === '#' || type === '^') {
|
455
|
+
sections.push(token);
|
456
|
+
} else if (type === '/') {
|
457
|
+
// Check section nesting.
|
458
|
+
if (sections.length === 0) throw new Error('Unopened section "' + value + '" at ' + start);
|
459
|
+
var openSection = sections.pop();
|
460
|
+
if (openSection[1] !== value) throw new Error('Unclosed section "' + openSection[1] + '" at ' + start);
|
461
|
+
} else if (type === 'name' || type === '{' || type === '&') {
|
551
462
|
nonSpace = true;
|
552
|
-
}
|
553
|
-
|
554
|
-
// Set the tags for the next time around.
|
555
|
-
if (type === "=") {
|
463
|
+
} else if (type === '=') {
|
464
|
+
// Set the tags for the next time around.
|
556
465
|
tags = value.split(spaceRe);
|
466
|
+
if (tags.length !== 2) throw new Error('Invalid tags at ' + start + ': ' + tags.join(', '));
|
557
467
|
tagRes = escapeTags(tags);
|
558
468
|
}
|
559
469
|
}
|
560
470
|
|
561
|
-
|
471
|
+
// Make sure there are no open sections when we're done.
|
472
|
+
var openSection = sections.pop();
|
473
|
+
if (openSection) throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos);
|
474
|
+
|
475
|
+
tokens = squashTokens(tokens);
|
562
476
|
|
563
477
|
return nestTokens(tokens);
|
564
478
|
};
|
565
479
|
|
566
|
-
//
|
567
|
-
// use this default writer.
|
480
|
+
// All Mustache.* functions use this writer.
|
568
481
|
var _writer = new Writer();
|
569
482
|
|
570
483
|
/**
|
@@ -619,4 +532,4 @@ var Mustache;
|
|
619
532
|
|
620
533
|
return exports;
|
621
534
|
|
622
|
-
}())));
|
535
|
+
}())));
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smt_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,52 +10,72 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-04-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
17
|
-
requirement:
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
|
-
- -
|
20
|
+
- - '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 3.1.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 3.1.0
|
26
31
|
- !ruby/object:Gem::Dependency
|
27
32
|
name: tilt
|
28
|
-
requirement:
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
29
34
|
none: false
|
30
35
|
requirements:
|
31
|
-
- -
|
36
|
+
- - '>='
|
32
37
|
- !ruby/object:Gem::Version
|
33
38
|
version: 1.3.3
|
34
39
|
type: :runtime
|
35
40
|
prerelease: false
|
36
|
-
version_requirements:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.3.3
|
37
47
|
- !ruby/object:Gem::Dependency
|
38
48
|
name: sprockets
|
39
|
-
requirement:
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
40
50
|
none: false
|
41
51
|
requirements:
|
42
|
-
- -
|
52
|
+
- - '>='
|
43
53
|
- !ruby/object:Gem::Version
|
44
54
|
version: 2.0.3
|
45
55
|
type: :runtime
|
46
56
|
prerelease: false
|
47
|
-
version_requirements:
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.0.3
|
48
63
|
- !ruby/object:Gem::Dependency
|
49
64
|
name: mustache
|
50
|
-
requirement:
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
51
66
|
none: false
|
52
67
|
requirements:
|
53
|
-
- -
|
68
|
+
- - '>='
|
54
69
|
- !ruby/object:Gem::Version
|
55
70
|
version: 0.99.4
|
56
71
|
type: :runtime
|
57
72
|
prerelease: false
|
58
|
-
version_requirements:
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 0.99.4
|
59
79
|
description: Shared mustache templates for rails 3
|
60
80
|
email:
|
61
81
|
- contacts@railsware.com
|
@@ -66,6 +86,7 @@ extra_rdoc_files:
|
|
66
86
|
- README.md
|
67
87
|
files:
|
68
88
|
- .gitignore
|
89
|
+
- .ruby-version
|
69
90
|
- Gemfile
|
70
91
|
- LICENSE
|
71
92
|
- README.md
|
@@ -90,24 +111,24 @@ require_paths:
|
|
90
111
|
required_ruby_version: !ruby/object:Gem::Requirement
|
91
112
|
none: false
|
92
113
|
requirements:
|
93
|
-
- -
|
114
|
+
- - '>='
|
94
115
|
- !ruby/object:Gem::Version
|
95
116
|
version: '0'
|
96
117
|
segments:
|
97
118
|
- 0
|
98
|
-
hash:
|
119
|
+
hash: -290175364099614496
|
99
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
121
|
none: false
|
101
122
|
requirements:
|
102
|
-
- -
|
123
|
+
- - '>='
|
103
124
|
- !ruby/object:Gem::Version
|
104
125
|
version: '0'
|
105
126
|
segments:
|
106
127
|
- 0
|
107
|
-
hash:
|
128
|
+
hash: -290175364099614496
|
108
129
|
requirements: []
|
109
130
|
rubyforge_project:
|
110
|
-
rubygems_version: 1.8.
|
131
|
+
rubygems_version: 1.8.25
|
111
132
|
signing_key:
|
112
133
|
specification_version: 3
|
113
134
|
summary: Shared mustache templates for rails 3
|