gokart 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/assets/config/config-debug.json +22 -0
- data/assets/config/config-release.json +22 -0
- data/assets/config.rb +1 -1
- data/assets/src/server/config/config.go +46 -0
- data/assets/src/server/controller/home.go +43 -0
- data/assets/src/server/controller/static_assets.go +57 -0
- data/assets/src/server/main.go +59 -17
- data/assets/src/server/view/home.go +28 -0
- data/assets/src/www/app/erb_helpers/erb_helper.rb +4 -2
- data/assets/src/www/app/scripts/application.js.coffee +9 -4
- data/assets/src/www/app/scripts/pages/home.js +6 -0
- data/assets/src/www/app/scripts/vendor_wrapper.js +11 -0
- data/assets/src/www/app/templates/application.gotmpl +5 -2
- data/assets/src/www/app/templates/base.gotmpl.erb +1 -1
- data/assets/src/www/app/templates/{home.gotmpl → pages/home.gotmpl} +12 -7
- data/assets/src/www/app/templates/partials/test.gotmpl +3 -0
- data/assets/src/www/app/templates/partials/test2.gotmpl +5 -0
- data/assets/src/www/app/templates/partials_end.gotmpl +1 -0
- data/assets/src/www/app/templates/partials_start.gotmpl +1 -0
- data/assets/src/www/spec/all-spec.js +1 -1
- data/assets/src/www/spec/helpers/mocks.coffee +1 -1
- data/assets/src/www/vendor/js/backbone.js +1478 -0
- data/assets/src/www/vendor/js/mustache.js +625 -0
- data/assets/src/www/vendor/js/underscore-min.js +5 -0
- data/assets/src/www/vendor/js/underscore.js +1204 -0
- data/assets/tasks/server.rake +9 -9
- data/assets/tasks/www.rake +2 -18
- data/bin/gokart +7 -0
- data/lib/gokart/base.rb +1 -1
- data/lib/gokart/environment.rb +27 -1
- data/lib/gokart/version.rb +1 -1
- metadata +49 -38
- data/assets/src/server/http_handler.go +0 -139
- data/assets/src/server/my_test.go +0 -13
- data/assets/src/server/templates.go +0 -42
- data/assets/src/www/app/partials/index.html +0 -92
- data/assets/src/www/app/scripts/main.js.coffee +0 -9
@@ -0,0 +1,625 @@
|
|
1
|
+
/*!
|
2
|
+
* mustache.js - Logic-less {{mustache}} templates with JavaScript
|
3
|
+
* http://github.com/janl/mustache.js
|
4
|
+
*/
|
5
|
+
|
6
|
+
/*global define: false*/
|
7
|
+
|
8
|
+
var Mustache;
|
9
|
+
|
10
|
+
(function (exports) {
|
11
|
+
if (typeof module !== "undefined" && module.exports) {
|
12
|
+
module.exports = exports; // CommonJS
|
13
|
+
} else if (typeof define === "function") {
|
14
|
+
define(exports.name, [], function() { return exports; }); // AMD
|
15
|
+
} else {
|
16
|
+
Mustache = exports; // <script>
|
17
|
+
}
|
18
|
+
}((function () {
|
19
|
+
|
20
|
+
var exports = {};
|
21
|
+
|
22
|
+
exports.name = "mustache";
|
23
|
+
exports.version = "0.7.0";
|
24
|
+
exports.tags = ["{{", "}}"];
|
25
|
+
|
26
|
+
exports.Scanner = Scanner;
|
27
|
+
exports.Context = Context;
|
28
|
+
exports.Writer = Writer;
|
29
|
+
|
30
|
+
var whiteRe = /\s*/;
|
31
|
+
var spaceRe = /\s+/;
|
32
|
+
var nonSpaceRe = /\S/;
|
33
|
+
var eqRe = /\s*=/;
|
34
|
+
var curlyRe = /\s*\}/;
|
35
|
+
var tagRe = /#|\^|\/|>|\{|&|=|!/;
|
36
|
+
|
37
|
+
// Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
|
38
|
+
// See https://github.com/janl/mustache.js/issues/189
|
39
|
+
function testRe(re, string) {
|
40
|
+
return RegExp.prototype.test.call(re, string);
|
41
|
+
}
|
42
|
+
|
43
|
+
function isWhitespace(string) {
|
44
|
+
return !testRe(nonSpaceRe, string);
|
45
|
+
}
|
46
|
+
|
47
|
+
var isArray = Array.isArray || function (obj) {
|
48
|
+
return Object.prototype.toString.call(obj) === "[object Array]";
|
49
|
+
};
|
50
|
+
|
51
|
+
function escapeRe(string) {
|
52
|
+
return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
|
53
|
+
}
|
54
|
+
|
55
|
+
var entityMap = {
|
56
|
+
"&": "&",
|
57
|
+
"<": "<",
|
58
|
+
">": ">",
|
59
|
+
'"': '"',
|
60
|
+
"'": ''',
|
61
|
+
"/": '/'
|
62
|
+
};
|
63
|
+
|
64
|
+
function escapeHtml(string) {
|
65
|
+
return String(string).replace(/[&<>"'\/]/g, function (s) {
|
66
|
+
return entityMap[s];
|
67
|
+
});
|
68
|
+
}
|
69
|
+
|
70
|
+
// Export the escaping function so that the user may override it.
|
71
|
+
// See https://github.com/janl/mustache.js/issues/244
|
72
|
+
exports.escape = escapeHtml;
|
73
|
+
|
74
|
+
function Scanner(string) {
|
75
|
+
this.string = string;
|
76
|
+
this.tail = string;
|
77
|
+
this.pos = 0;
|
78
|
+
}
|
79
|
+
|
80
|
+
/**
|
81
|
+
* Returns `true` if the tail is empty (end of string).
|
82
|
+
*/
|
83
|
+
Scanner.prototype.eos = function () {
|
84
|
+
return this.tail === "";
|
85
|
+
};
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Tries to match the given regular expression at the current position.
|
89
|
+
* Returns the matched text if it can match, the empty string otherwise.
|
90
|
+
*/
|
91
|
+
Scanner.prototype.scan = function (re) {
|
92
|
+
var match = this.tail.match(re);
|
93
|
+
|
94
|
+
if (match && match.index === 0) {
|
95
|
+
this.tail = this.tail.substring(match[0].length);
|
96
|
+
this.pos += match[0].length;
|
97
|
+
return match[0];
|
98
|
+
}
|
99
|
+
|
100
|
+
return "";
|
101
|
+
};
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Skips all text until the given regular expression can be matched. Returns
|
105
|
+
* the skipped string, which is the entire tail if no match can be made.
|
106
|
+
*/
|
107
|
+
Scanner.prototype.scanUntil = function (re) {
|
108
|
+
var match, pos = this.tail.search(re);
|
109
|
+
|
110
|
+
switch (pos) {
|
111
|
+
case -1:
|
112
|
+
match = this.tail;
|
113
|
+
this.pos += this.tail.length;
|
114
|
+
this.tail = "";
|
115
|
+
break;
|
116
|
+
case 0:
|
117
|
+
match = "";
|
118
|
+
break;
|
119
|
+
default:
|
120
|
+
match = this.tail.substring(0, pos);
|
121
|
+
this.tail = this.tail.substring(pos);
|
122
|
+
this.pos += pos;
|
123
|
+
}
|
124
|
+
|
125
|
+
return match;
|
126
|
+
};
|
127
|
+
|
128
|
+
function Context(view, parent) {
|
129
|
+
this.view = view;
|
130
|
+
this.parent = parent;
|
131
|
+
this.clearCache();
|
132
|
+
}
|
133
|
+
|
134
|
+
Context.make = function (view) {
|
135
|
+
return (view instanceof Context) ? view : new Context(view);
|
136
|
+
};
|
137
|
+
|
138
|
+
Context.prototype.clearCache = function () {
|
139
|
+
this._cache = {};
|
140
|
+
};
|
141
|
+
|
142
|
+
Context.prototype.push = function (view) {
|
143
|
+
return new Context(view, this);
|
144
|
+
};
|
145
|
+
|
146
|
+
Context.prototype.lookup = function (name) {
|
147
|
+
var value = this._cache[name];
|
148
|
+
|
149
|
+
if (!value) {
|
150
|
+
if (name === ".") {
|
151
|
+
value = this.view;
|
152
|
+
} else {
|
153
|
+
var context = this;
|
154
|
+
|
155
|
+
while (context) {
|
156
|
+
if (name.indexOf(".") > 0) {
|
157
|
+
var names = name.split("."), i = 0;
|
158
|
+
|
159
|
+
value = context.view;
|
160
|
+
|
161
|
+
while (value && i < names.length) {
|
162
|
+
value = value[names[i++]];
|
163
|
+
}
|
164
|
+
} else {
|
165
|
+
value = context.view[name];
|
166
|
+
}
|
167
|
+
|
168
|
+
if (value != null) {
|
169
|
+
break;
|
170
|
+
}
|
171
|
+
|
172
|
+
context = context.parent;
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
this._cache[name] = value;
|
177
|
+
}
|
178
|
+
|
179
|
+
if (typeof value === "function") {
|
180
|
+
value = value.call(this.view);
|
181
|
+
}
|
182
|
+
|
183
|
+
return value;
|
184
|
+
};
|
185
|
+
|
186
|
+
function Writer() {
|
187
|
+
this.clearCache();
|
188
|
+
}
|
189
|
+
|
190
|
+
Writer.prototype.clearCache = function () {
|
191
|
+
this._cache = {};
|
192
|
+
this._partialCache = {};
|
193
|
+
};
|
194
|
+
|
195
|
+
Writer.prototype.compile = function (template, tags) {
|
196
|
+
var fn = this._cache[template];
|
197
|
+
|
198
|
+
if (!fn) {
|
199
|
+
var tokens = exports.parse(template, tags);
|
200
|
+
fn = this._cache[template] = this.compileTokens(tokens, template);
|
201
|
+
}
|
202
|
+
|
203
|
+
return fn;
|
204
|
+
};
|
205
|
+
|
206
|
+
Writer.prototype.compilePartial = function (name, template, tags) {
|
207
|
+
var fn = this.compile(template, tags);
|
208
|
+
this._partialCache[name] = fn;
|
209
|
+
return fn;
|
210
|
+
};
|
211
|
+
|
212
|
+
Writer.prototype.compileTokens = function (tokens, template) {
|
213
|
+
var fn = compileTokens(tokens);
|
214
|
+
var self = this;
|
215
|
+
|
216
|
+
return function (view, partials) {
|
217
|
+
if (partials) {
|
218
|
+
if (typeof partials === "function") {
|
219
|
+
self._loadPartial = partials;
|
220
|
+
} else {
|
221
|
+
for (var name in partials) {
|
222
|
+
self.compilePartial(name, partials[name]);
|
223
|
+
}
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
return fn(self, Context.make(view), template);
|
228
|
+
};
|
229
|
+
};
|
230
|
+
|
231
|
+
Writer.prototype.render = function (template, view, partials) {
|
232
|
+
return this.compile(template)(view, partials);
|
233
|
+
};
|
234
|
+
|
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
|
+
var result = value.call(context.view, text, scopedRender);
|
258
|
+
return result != null ? result : "";
|
259
|
+
default:
|
260
|
+
if (value) {
|
261
|
+
return callback(this, context);
|
262
|
+
}
|
263
|
+
}
|
264
|
+
|
265
|
+
return "";
|
266
|
+
};
|
267
|
+
|
268
|
+
Writer.prototype._inverted = function (name, context, callback) {
|
269
|
+
var value = context.lookup(name);
|
270
|
+
|
271
|
+
// Use JavaScript's definition of falsy. Include empty arrays.
|
272
|
+
// See https://github.com/janl/mustache.js/issues/186
|
273
|
+
if (!value || (isArray(value) && value.length === 0)) {
|
274
|
+
return callback(this, context);
|
275
|
+
}
|
276
|
+
|
277
|
+
return "";
|
278
|
+
};
|
279
|
+
|
280
|
+
Writer.prototype._partial = function (name, context) {
|
281
|
+
if (!(name in this._partialCache) && this._loadPartial) {
|
282
|
+
this.compilePartial(name, this._loadPartial(name));
|
283
|
+
}
|
284
|
+
|
285
|
+
var fn = this._partialCache[name];
|
286
|
+
|
287
|
+
return fn ? fn(context) : "";
|
288
|
+
};
|
289
|
+
|
290
|
+
Writer.prototype._name = function (name, context) {
|
291
|
+
var value = context.lookup(name);
|
292
|
+
|
293
|
+
if (typeof value === "function") {
|
294
|
+
value = value.call(context.view);
|
295
|
+
}
|
296
|
+
|
297
|
+
return (value == null) ? "" : String(value);
|
298
|
+
};
|
299
|
+
|
300
|
+
Writer.prototype._escaped = function (name, context) {
|
301
|
+
return exports.escape(this._name(name, context));
|
302
|
+
};
|
303
|
+
|
304
|
+
/**
|
305
|
+
* Calculates the bounds of the section represented by the given `token` in
|
306
|
+
* the original template by drilling down into nested sections to find the
|
307
|
+
* last token that is part of that section. Returns an array of [start, end].
|
308
|
+
*/
|
309
|
+
function sectionBounds(token) {
|
310
|
+
var start = token[3];
|
311
|
+
var end = start;
|
312
|
+
|
313
|
+
var tokens;
|
314
|
+
while ((tokens = token[4]) && tokens.length) {
|
315
|
+
token = tokens[tokens.length - 1];
|
316
|
+
end = token[3];
|
317
|
+
}
|
318
|
+
|
319
|
+
return [start, end];
|
320
|
+
}
|
321
|
+
|
322
|
+
/**
|
323
|
+
* Low-level function that compiles the given `tokens` into a function
|
324
|
+
* that accepts three arguments: a Writer, a Context, and the template.
|
325
|
+
*/
|
326
|
+
function compileTokens(tokens) {
|
327
|
+
var subRenders = {};
|
328
|
+
|
329
|
+
function subRender(i, tokens, template) {
|
330
|
+
if (!subRenders[i]) {
|
331
|
+
var fn = compileTokens(tokens);
|
332
|
+
subRenders[i] = function (writer, context) {
|
333
|
+
return fn(writer, context, template);
|
334
|
+
};
|
335
|
+
}
|
336
|
+
|
337
|
+
return subRenders[i];
|
338
|
+
}
|
339
|
+
|
340
|
+
return function (writer, context, template) {
|
341
|
+
var buffer = "";
|
342
|
+
var token, sectionText;
|
343
|
+
|
344
|
+
for (var i = 0, len = tokens.length; i < len; ++i) {
|
345
|
+
token = tokens[i];
|
346
|
+
|
347
|
+
switch (token[0]) {
|
348
|
+
case "#":
|
349
|
+
sectionText = template.slice.apply(template, sectionBounds(token));
|
350
|
+
buffer += writer._section(token[1], context, sectionText, subRender(i, token[4], template));
|
351
|
+
break;
|
352
|
+
case "^":
|
353
|
+
buffer += writer._inverted(token[1], context, subRender(i, token[4], template));
|
354
|
+
break;
|
355
|
+
case ">":
|
356
|
+
buffer += writer._partial(token[1], context);
|
357
|
+
break;
|
358
|
+
case "&":
|
359
|
+
buffer += writer._name(token[1], context);
|
360
|
+
break;
|
361
|
+
case "name":
|
362
|
+
buffer += writer._escaped(token[1], context);
|
363
|
+
break;
|
364
|
+
case "text":
|
365
|
+
buffer += token[1];
|
366
|
+
break;
|
367
|
+
}
|
368
|
+
}
|
369
|
+
|
370
|
+
return buffer;
|
371
|
+
};
|
372
|
+
}
|
373
|
+
|
374
|
+
/**
|
375
|
+
* Forms the given array of `tokens` into a nested tree structure where
|
376
|
+
* tokens that represent a section have a fifth item: an array that contains
|
377
|
+
* all tokens in that section.
|
378
|
+
*/
|
379
|
+
function nestTokens(tokens) {
|
380
|
+
var tree = [];
|
381
|
+
var collector = tree;
|
382
|
+
var sections = [];
|
383
|
+
var token, section;
|
384
|
+
|
385
|
+
for (var i = 0; i < tokens.length; ++i) {
|
386
|
+
token = tokens[i];
|
387
|
+
|
388
|
+
switch (token[0]) {
|
389
|
+
case "#":
|
390
|
+
case "^":
|
391
|
+
token[4] = [];
|
392
|
+
sections.push(token);
|
393
|
+
collector.push(token);
|
394
|
+
collector = token[4];
|
395
|
+
break;
|
396
|
+
case "/":
|
397
|
+
if (sections.length === 0) {
|
398
|
+
throw new Error("Unopened section: " + token[1]);
|
399
|
+
}
|
400
|
+
|
401
|
+
section = sections.pop();
|
402
|
+
|
403
|
+
if (section[1] !== token[1]) {
|
404
|
+
throw new Error("Unclosed section: " + section[1]);
|
405
|
+
}
|
406
|
+
|
407
|
+
if (sections.length > 0) {
|
408
|
+
collector = sections[sections.length - 1][4];
|
409
|
+
} else {
|
410
|
+
collector = tree;
|
411
|
+
}
|
412
|
+
break;
|
413
|
+
default:
|
414
|
+
collector.push(token);
|
415
|
+
}
|
416
|
+
}
|
417
|
+
|
418
|
+
// Make sure there were no open sections when we're done.
|
419
|
+
section = sections.pop();
|
420
|
+
|
421
|
+
if (section) {
|
422
|
+
throw new Error("Unclosed section: " + section[1]);
|
423
|
+
}
|
424
|
+
|
425
|
+
return tree;
|
426
|
+
}
|
427
|
+
|
428
|
+
/**
|
429
|
+
* Combines the values of consecutive text tokens in the given `tokens` array
|
430
|
+
* to a single token.
|
431
|
+
*/
|
432
|
+
function squashTokens(tokens) {
|
433
|
+
var token, lastToken, squashedTokens = [];
|
434
|
+
|
435
|
+
for (var i = 0; i < tokens.length; ++i) {
|
436
|
+
token = tokens[i];
|
437
|
+
|
438
|
+
if (lastToken && lastToken[0] === "text" && token[0] === "text") {
|
439
|
+
lastToken[1] += token[1];
|
440
|
+
lastToken[3] = token[3];
|
441
|
+
} else {
|
442
|
+
lastToken = token;
|
443
|
+
squashedTokens.push(token);
|
444
|
+
}
|
445
|
+
}
|
446
|
+
|
447
|
+
return squashedTokens;
|
448
|
+
}
|
449
|
+
|
450
|
+
function escapeTags(tags) {
|
451
|
+
if (tags.length !== 2) {
|
452
|
+
throw new Error("Invalid tags: " + tags.join(" "));
|
453
|
+
}
|
454
|
+
|
455
|
+
return [
|
456
|
+
new RegExp(escapeRe(tags[0]) + "\\s*"),
|
457
|
+
new RegExp("\\s*" + escapeRe(tags[1]))
|
458
|
+
];
|
459
|
+
}
|
460
|
+
|
461
|
+
/**
|
462
|
+
* Breaks up the given `template` string into a tree of token objects. If
|
463
|
+
* `tags` is given here it must be an array with two string values: the
|
464
|
+
* opening and closing tags used in the template (e.g. ["<%", "%>"]). Of
|
465
|
+
* course, the default is to use mustaches (i.e. Mustache.tags).
|
466
|
+
*/
|
467
|
+
exports.parse = function (template, tags) {
|
468
|
+
tags = tags || exports.tags;
|
469
|
+
|
470
|
+
var tagRes = escapeTags(tags);
|
471
|
+
var scanner = new Scanner(template);
|
472
|
+
|
473
|
+
var tokens = [], // Buffer to hold the tokens
|
474
|
+
spaces = [], // Indices of whitespace tokens on the current line
|
475
|
+
hasTag = false, // Is there a {{tag}} on the current line?
|
476
|
+
nonSpace = false; // Is there a non-space char on the current line?
|
477
|
+
|
478
|
+
// Strips all whitespace tokens array for the current line
|
479
|
+
// if there was a {{#tag}} on it and otherwise only space.
|
480
|
+
function stripSpace() {
|
481
|
+
if (hasTag && !nonSpace) {
|
482
|
+
while (spaces.length) {
|
483
|
+
tokens.splice(spaces.pop(), 1);
|
484
|
+
}
|
485
|
+
} else {
|
486
|
+
spaces = [];
|
487
|
+
}
|
488
|
+
|
489
|
+
hasTag = false;
|
490
|
+
nonSpace = false;
|
491
|
+
}
|
492
|
+
|
493
|
+
var start, type, value, chr;
|
494
|
+
|
495
|
+
while (!scanner.eos()) {
|
496
|
+
start = scanner.pos;
|
497
|
+
value = scanner.scanUntil(tagRes[0]);
|
498
|
+
|
499
|
+
if (value) {
|
500
|
+
for (var i = 0, len = value.length; i < len; ++i) {
|
501
|
+
chr = value.charAt(i);
|
502
|
+
|
503
|
+
if (isWhitespace(chr)) {
|
504
|
+
spaces.push(tokens.length);
|
505
|
+
} else {
|
506
|
+
nonSpace = true;
|
507
|
+
}
|
508
|
+
|
509
|
+
tokens.push(["text", chr, start, start + 1]);
|
510
|
+
start += 1;
|
511
|
+
|
512
|
+
if (chr === "\n") {
|
513
|
+
stripSpace(); // Check for whitespace on the current line.
|
514
|
+
}
|
515
|
+
}
|
516
|
+
}
|
517
|
+
|
518
|
+
start = scanner.pos;
|
519
|
+
|
520
|
+
// Match the opening tag.
|
521
|
+
if (!scanner.scan(tagRes[0])) {
|
522
|
+
break;
|
523
|
+
}
|
524
|
+
|
525
|
+
hasTag = true;
|
526
|
+
type = scanner.scan(tagRe) || "name";
|
527
|
+
|
528
|
+
// Skip any whitespace between tag and value.
|
529
|
+
scanner.scan(whiteRe);
|
530
|
+
|
531
|
+
// Extract the tag value.
|
532
|
+
if (type === "=") {
|
533
|
+
value = scanner.scanUntil(eqRe);
|
534
|
+
scanner.scan(eqRe);
|
535
|
+
scanner.scanUntil(tagRes[1]);
|
536
|
+
} else if (type === "{") {
|
537
|
+
var closeRe = new RegExp("\\s*" + escapeRe("}" + tags[1]));
|
538
|
+
value = scanner.scanUntil(closeRe);
|
539
|
+
scanner.scan(curlyRe);
|
540
|
+
scanner.scanUntil(tagRes[1]);
|
541
|
+
type = "&";
|
542
|
+
} else {
|
543
|
+
value = scanner.scanUntil(tagRes[1]);
|
544
|
+
}
|
545
|
+
|
546
|
+
// Match the closing tag.
|
547
|
+
if (!scanner.scan(tagRes[1])) {
|
548
|
+
throw new Error("Unclosed tag at " + scanner.pos);
|
549
|
+
}
|
550
|
+
|
551
|
+
tokens.push([type, value, start, scanner.pos]);
|
552
|
+
|
553
|
+
if (type === "name" || type === "{" || type === "&") {
|
554
|
+
nonSpace = true;
|
555
|
+
}
|
556
|
+
|
557
|
+
// Set the tags for the next time around.
|
558
|
+
if (type === "=") {
|
559
|
+
tags = value.split(spaceRe);
|
560
|
+
tagRes = escapeTags(tags);
|
561
|
+
}
|
562
|
+
}
|
563
|
+
|
564
|
+
tokens = squashTokens(tokens);
|
565
|
+
|
566
|
+
return nestTokens(tokens);
|
567
|
+
};
|
568
|
+
|
569
|
+
// The high-level clearCache, compile, compilePartial, and render functions
|
570
|
+
// use this default writer.
|
571
|
+
var _writer = new Writer();
|
572
|
+
|
573
|
+
/**
|
574
|
+
* Clears all cached templates and partials in the default writer.
|
575
|
+
*/
|
576
|
+
exports.clearCache = function () {
|
577
|
+
return _writer.clearCache();
|
578
|
+
};
|
579
|
+
|
580
|
+
/**
|
581
|
+
* Compiles the given `template` to a reusable function using the default
|
582
|
+
* writer.
|
583
|
+
*/
|
584
|
+
exports.compile = function (template, tags) {
|
585
|
+
return _writer.compile(template, tags);
|
586
|
+
};
|
587
|
+
|
588
|
+
/**
|
589
|
+
* Compiles the partial with the given `name` and `template` to a reusable
|
590
|
+
* function using the default writer.
|
591
|
+
*/
|
592
|
+
exports.compilePartial = function (name, template, tags) {
|
593
|
+
return _writer.compilePartial(name, template, tags);
|
594
|
+
};
|
595
|
+
|
596
|
+
/**
|
597
|
+
* Compiles the given array of tokens (the output of a parse) to a reusable
|
598
|
+
* function using the default writer.
|
599
|
+
*/
|
600
|
+
exports.compileTokens = function (tokens, template) {
|
601
|
+
return _writer.compileTokens(tokens, template);
|
602
|
+
};
|
603
|
+
|
604
|
+
/**
|
605
|
+
* Renders the `template` with the given `view` and `partials` using the
|
606
|
+
* default writer.
|
607
|
+
*/
|
608
|
+
exports.render = function (template, view, partials) {
|
609
|
+
return _writer.render(template, view, partials);
|
610
|
+
};
|
611
|
+
|
612
|
+
// This is here for backwards compatibility with 0.4.x.
|
613
|
+
exports.to_html = function (template, view, partials, send) {
|
614
|
+
var result = exports.render(template, view, partials);
|
615
|
+
|
616
|
+
if (typeof send === "function") {
|
617
|
+
send(result);
|
618
|
+
} else {
|
619
|
+
return result;
|
620
|
+
}
|
621
|
+
};
|
622
|
+
|
623
|
+
return exports;
|
624
|
+
|
625
|
+
}())));
|
@@ -0,0 +1,5 @@
|
|
1
|
+
// Underscore.js 1.4.2
|
2
|
+
// http://underscorejs.org
|
3
|
+
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
|
4
|
+
// Underscore may be freely distributed under the MIT license.
|
5
|
+
(function(){var e=this,t=e._,n={},r=Array.prototype,i=Object.prototype,s=Function.prototype,o=r.push,u=r.slice,a=r.concat,f=r.unshift,l=i.toString,c=i.hasOwnProperty,h=r.forEach,p=r.map,d=r.reduce,v=r.reduceRight,m=r.filter,g=r.every,y=r.some,b=r.indexOf,w=r.lastIndexOf,E=Array.isArray,S=Object.keys,x=s.bind,T=function(e){if(e instanceof T)return e;if(!(this instanceof T))return new T(e);this._wrapped=e};typeof exports!="undefined"?(typeof module!="undefined"&&module.exports&&(exports=module.exports=T),exports._=T):e._=T,T.VERSION="1.4.2";var N=T.each=T.forEach=function(e,t,r){if(e==null)return;if(h&&e.forEach===h)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,s=e.length;i<s;i++)if(t.call(r,e[i],i,e)===n)return}else for(var o in e)if(T.has(e,o)&&t.call(r,e[o],o,e)===n)return};T.map=T.collect=function(e,t,n){var r=[];return e==null?r:p&&e.map===p?e.map(t,n):(N(e,function(e,i,s){r[r.length]=t.call(n,e,i,s)}),r)},T.reduce=T.foldl=T.inject=function(e,t,n,r){var i=arguments.length>2;e==null&&(e=[]);if(d&&e.reduce===d)return r&&(t=T.bind(t,r)),i?e.reduce(t,n):e.reduce(t);N(e,function(e,s,o){i?n=t.call(r,n,e,s,o):(n=e,i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.reduceRight=T.foldr=function(e,t,n,r){var i=arguments.length>2;e==null&&(e=[]);if(v&&e.reduceRight===v)return r&&(t=T.bind(t,r)),arguments.length>2?e.reduceRight(t,n):e.reduceRight(t);var s=e.length;if(s!==+s){var o=T.keys(e);s=o.length}N(e,function(u,a,f){a=o?o[--s]:--s,i?n=t.call(r,n,e[a],a,f):(n=e[a],i=!0)});if(!i)throw new TypeError("Reduce of empty array with no initial value");return n},T.find=T.detect=function(e,t,n){var r;return C(e,function(e,i,s){if(t.call(n,e,i,s))return r=e,!0}),r},T.filter=T.select=function(e,t,n){var r=[];return e==null?r:m&&e.filter===m?e.filter(t,n):(N(e,function(e,i,s){t.call(n,e,i,s)&&(r[r.length]=e)}),r)},T.reject=function(e,t,n){var r=[];return e==null?r:(N(e,function(e,i,s){t.call(n,e,i,s)||(r[r.length]=e)}),r)},T.every=T.all=function(e,t,r){t||(t=T.identity);var i=!0;return e==null?i:g&&e.every===g?e.every(t,r):(N(e,function(e,s,o){if(!(i=i&&t.call(r,e,s,o)))return n}),!!i)};var C=T.some=T.any=function(e,t,r){t||(t=T.identity);var i=!1;return e==null?i:y&&e.some===y?e.some(t,r):(N(e,function(e,s,o){if(i||(i=t.call(r,e,s,o)))return n}),!!i)};T.contains=T.include=function(e,t){var n=!1;return e==null?n:b&&e.indexOf===b?e.indexOf(t)!=-1:(n=C(e,function(e){return e===t}),n)},T.invoke=function(e,t){var n=u.call(arguments,2);return T.map(e,function(e){return(T.isFunction(t)?t:e[t]).apply(e,n)})},T.pluck=function(e,t){return T.map(e,function(e){return e[t]})},T.where=function(e,t){return T.isEmpty(t)?[]:T.filter(e,function(e){for(var n in t)if(t[n]!==e[n])return!1;return!0})},T.max=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.max.apply(Math,e);if(!t&&T.isEmpty(e))return-Infinity;var r={computed:-Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o>=r.computed&&(r={value:e,computed:o})}),r.value},T.min=function(e,t,n){if(!t&&T.isArray(e)&&e[0]===+e[0]&&e.length<65535)return Math.min.apply(Math,e);if(!t&&T.isEmpty(e))return Infinity;var r={computed:Infinity};return N(e,function(e,i,s){var o=t?t.call(n,e,i,s):e;o<r.computed&&(r={value:e,computed:o})}),r.value},T.shuffle=function(e){var t,n=0,r=[];return N(e,function(e){t=T.random(n++),r[n-1]=r[t],r[t]=e}),r};var k=function(e){return T.isFunction(e)?e:function(t){return t[e]}};T.sortBy=function(e,t,n){var r=k(t);return T.pluck(T.map(e,function(e,t,i){return{value:e,index:t,criteria:r.call(n,e,t,i)}}).sort(function(e,t){var n=e.criteria,r=t.criteria;if(n!==r){if(n>r||n===void 0)return 1;if(n<r||r===void 0)return-1}return e.index<t.index?-1:1}),"value")};var L=function(e,t,n,r){var i={},s=k(t);return N(e,function(t,o){var u=s.call(n,t,o,e);r(i,u,t)}),i};T.groupBy=function(e,t,n){return L(e,t,n,function(e,t,n){(T.has(e,t)?e[t]:e[t]=[]).push(n)})},T.countBy=function(e,t,n){return L(e,t,n,function(e,t,n){T.has(e,t)||(e[t]=0),e[t]++})},T.sortedIndex=function(e,t,n,r){n=n==null?T.identity:k(n);var i=n.call(r,t),s=0,o=e.length;while(s<o){var u=s+o>>>1;n.call(r,e[u])<i?s=u+1:o=u}return s},T.toArray=function(e){return e?e.length===+e.length?u.call(e):T.values(e):[]},T.size=function(e){return e.length===+e.length?e.length:T.keys(e).length},T.first=T.head=T.take=function(e,t,n){return t!=null&&!n?u.call(e,0,t):e[0]},T.initial=function(e,t,n){return u.call(e,0,e.length-(t==null||n?1:t))},T.last=function(e,t,n){return t!=null&&!n?u.call(e,Math.max(e.length-t,0)):e[e.length-1]},T.rest=T.tail=T.drop=function(e,t,n){return u.call(e,t==null||n?1:t)},T.compact=function(e){return T.filter(e,function(e){return!!e})};var A=function(e,t,n){return N(e,function(e){T.isArray(e)?t?o.apply(n,e):A(e,t,n):n.push(e)}),n};T.flatten=function(e,t){return A(e,t,[])},T.without=function(e){return T.difference(e,u.call(arguments,1))},T.uniq=T.unique=function(e,t,n,r){var i=n?T.map(e,n,r):e,s=[],o=[];return N(i,function(n,r){if(t?!r||o[o.length-1]!==n:!T.contains(o,n))o.push(n),s.push(e[r])}),s},T.union=function(){return T.uniq(a.apply(r,arguments))},T.intersection=function(e){var t=u.call(arguments,1);return T.filter(T.uniq(e),function(e){return T.every(t,function(t){return T.indexOf(t,e)>=0})})},T.difference=function(e){var t=a.apply(r,u.call(arguments,1));return T.filter(e,function(e){return!T.contains(t,e)})},T.zip=function(){var e=u.call(arguments),t=T.max(T.pluck(e,"length")),n=new Array(t);for(var r=0;r<t;r++)n[r]=T.pluck(e,""+r);return n},T.object=function(e,t){var n={};for(var r=0,i=e.length;r<i;r++)t?n[e[r]]=t[r]:n[e[r][0]]=e[r][1];return n},T.indexOf=function(e,t,n){if(e==null)return-1;var r=0,i=e.length;if(n){if(typeof n!="number")return r=T.sortedIndex(e,t),e[r]===t?r:-1;r=n<0?Math.max(0,i+n):n}if(b&&e.indexOf===b)return e.indexOf(t,n);for(;r<i;r++)if(e[r]===t)return r;return-1},T.lastIndexOf=function(e,t,n){if(e==null)return-1;var r=n!=null;if(w&&e.lastIndexOf===w)return r?e.lastIndexOf(t,n):e.lastIndexOf(t);var i=r?n:e.length;while(i--)if(e[i]===t)return i;return-1},T.range=function(e,t,n){arguments.length<=1&&(t=e||0,e=0),n=arguments[2]||1;var r=Math.max(Math.ceil((t-e)/n),0),i=0,s=new Array(r);while(i<r)s[i++]=e,e+=n;return s};var O=function(){};T.bind=function(t,n){var r,i;if(t.bind===x&&x)return x.apply(t,u.call(arguments,1));if(!T.isFunction(t))throw new TypeError;return i=u.call(arguments,2),r=function(){if(this instanceof r){O.prototype=t.prototype;var e=new O,s=t.apply(e,i.concat(u.call(arguments)));return Object(s)===s?s:e}return t.apply(n,i.concat(u.call(arguments)))}},T.bindAll=function(e){var t=u.call(arguments,1);return t.length==0&&(t=T.functions(e)),N(t,function(t){e[t]=T.bind(e[t],e)}),e},T.memoize=function(e,t){var n={};return t||(t=T.identity),function(){var r=t.apply(this,arguments);return T.has(n,r)?n[r]:n[r]=e.apply(this,arguments)}},T.delay=function(e,t){var n=u.call(arguments,2);return setTimeout(function(){return e.apply(null,n)},t)},T.defer=function(e){return T.delay.apply(T,[e,1].concat(u.call(arguments,1)))},T.throttle=function(e,t){var n,r,i,s,o,u,a=T.debounce(function(){o=s=!1},t);return function(){n=this,r=arguments;var f=function(){i=null,o&&(u=e.apply(n,r)),a()};return i||(i=setTimeout(f,t)),s?o=!0:(s=!0,u=e.apply(n,r)),a(),u}},T.debounce=function(e,t,n){var r,i;return function(){var s=this,o=arguments,u=function(){r=null,n||(i=e.apply(s,o))},a=n&&!r;return clearTimeout(r),r=setTimeout(u,t),a&&(i=e.apply(s,o)),i}},T.once=function(e){var t=!1,n;return function(){return t?n:(t=!0,n=e.apply(this,arguments),e=null,n)}},T.wrap=function(e,t){return function(){var n=[e];return o.apply(n,arguments),t.apply(this,n)}},T.compose=function(){var e=arguments;return function(){var t=arguments;for(var n=e.length-1;n>=0;n--)t=[e[n].apply(this,t)];return t[0]}},T.after=function(e,t){return e<=0?t():function(){if(--e<1)return t.apply(this,arguments)}},T.keys=S||function(e){if(e!==Object(e))throw new TypeError("Invalid object");var t=[];for(var n in e)T.has(e,n)&&(t[t.length]=n);return t},T.values=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push(e[n]);return t},T.pairs=function(e){var t=[];for(var n in e)T.has(e,n)&&t.push([n,e[n]]);return t},T.invert=function(e){var t={};for(var n in e)T.has(e,n)&&(t[e[n]]=n);return t},T.functions=T.methods=function(e){var t=[];for(var n in e)T.isFunction(e[n])&&t.push(n);return t.sort()},T.extend=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]=t[n]}),e},T.pick=function(e){var t={},n=a.apply(r,u.call(arguments,1));return N(n,function(n){n in e&&(t[n]=e[n])}),t},T.omit=function(e){var t={},n=a.apply(r,u.call(arguments,1));for(var i in e)T.contains(n,i)||(t[i]=e[i]);return t},T.defaults=function(e){return N(u.call(arguments,1),function(t){for(var n in t)e[n]==null&&(e[n]=t[n])}),e},T.clone=function(e){return T.isObject(e)?T.isArray(e)?e.slice():T.extend({},e):e},T.tap=function(e,t){return t(e),e};var M=function(e,t,n,r){if(e===t)return e!==0||1/e==1/t;if(e==null||t==null)return e===t;e instanceof T&&(e=e._wrapped),t instanceof T&&(t=t._wrapped);var i=l.call(e);if(i!=l.call(t))return!1;switch(i){case"[object String]":return e==String(t);case"[object Number]":return e!=+e?t!=+t:e==0?1/e==1/t:e==+t;case"[object Date]":case"[object Boolean]":return+e==+t;case"[object RegExp]":return e.source==t.source&&e.global==t.global&&e.multiline==t.multiline&&e.ignoreCase==t.ignoreCase}if(typeof e!="object"||typeof t!="object")return!1;var s=n.length;while(s--)if(n[s]==e)return r[s]==t;n.push(e),r.push(t);var o=0,u=!0;if(i=="[object Array]"){o=e.length,u=o==t.length;if(u)while(o--)if(!(u=M(e[o],t[o],n,r)))break}else{var a=e.constructor,f=t.constructor;if(a!==f&&!(T.isFunction(a)&&a instanceof a&&T.isFunction(f)&&f instanceof f))return!1;for(var c in e)if(T.has(e,c)){o++;if(!(u=T.has(t,c)&&M(e[c],t[c],n,r)))break}if(u){for(c in t)if(T.has(t,c)&&!(o--))break;u=!o}}return n.pop(),r.pop(),u};T.isEqual=function(e,t){return M(e,t,[],[])},T.isEmpty=function(e){if(e==null)return!0;if(T.isArray(e)||T.isString(e))return e.length===0;for(var t in e)if(T.has(e,t))return!1;return!0},T.isElement=function(e){return!!e&&e.nodeType===1},T.isArray=E||function(e){return l.call(e)=="[object Array]"},T.isObject=function(e){return e===Object(e)},N(["Arguments","Function","String","Number","Date","RegExp"],function(e){T["is"+e]=function(t){return l.call(t)=="[object "+e+"]"}}),T.isArguments(arguments)||(T.isArguments=function(e){return!!e&&!!T.has(e,"callee")}),typeof /./!="function"&&(T.isFunction=function(e){return typeof e=="function"}),T.isFinite=function(e){return T.isNumber(e)&&isFinite(e)},T.isNaN=function(e){return T.isNumber(e)&&e!=+e},T.isBoolean=function(e){return e===!0||e===!1||l.call(e)=="[object Boolean]"},T.isNull=function(e){return e===null},T.isUndefined=function(e){return e===void 0},T.has=function(e,t){return c.call(e,t)},T.noConflict=function(){return e._=t,this},T.identity=function(e){return e},T.times=function(e,t,n){for(var r=0;r<e;r++)t.call(n,r)},T.random=function(e,t){return t==null&&(t=e,e=0),e+(0|Math.random()*(t-e+1))};var _={escape:{"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"}};_.unescape=T.invert(_.escape);var D={escape:new RegExp("["+T.keys(_.escape).join("")+"]","g"),unescape:new RegExp("("+T.keys(_.unescape).join("|")+")","g")};T.each(["escape","unescape"],function(e){T[e]=function(t){return t==null?"":(""+t).replace(D[e],function(t){return _[e][t]})}}),T.result=function(e,t){if(e==null)return null;var n=e[t];return T.isFunction(n)?n.call(e):n},T.mixin=function(e){N(T.functions(e),function(t){var n=T[t]=e[t];T.prototype[t]=function(){var e=[this._wrapped];return o.apply(e,arguments),F.call(this,n.apply(T,e))}})};var P=0;T.uniqueId=function(e){var t=P++;return e?e+t:t},T.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var H=/(.)^/,B={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},j=/\\|'|\r|\n|\t|\u2028|\u2029/g;T.template=function(e,t,n){n=T.defaults({},n,T.templateSettings);var r=new RegExp([(n.escape||H).source,(n.interpolate||H).source,(n.evaluate||H).source].join("|")+"|$","g"),i=0,s="__p+='";e.replace(r,function(t,n,r,o,u){s+=e.slice(i,u).replace(j,function(e){return"\\"+B[e]}),s+=n?"'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":r?"'+\n((__t=("+r+"))==null?'':__t)+\n'":o?"';\n"+o+"\n__p+='":"",i=u+t.length}),s+="';\n",n.variable||(s="with(obj||{}){\n"+s+"}\n"),s="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+s+"return __p;\n";try{var o=new Function(n.variable||"obj","_",s)}catch(u){throw u.source=s,u}if(t)return o(t,T);var a=function(e){return o.call(this,e,T)};return a.source="function("+(n.variable||"obj")+"){\n"+s+"}",a},T.chain=function(e){return T(e).chain()};var F=function(e){return this._chain?T(e).chain():e};T.mixin(T),N(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=r[e];T.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),(e=="shift"||e=="splice")&&n.length===0&&delete n[0],F.call(this,n)}}),N(["concat","join","slice"],function(e){var t=r[e];T.prototype[e]=function(){return F.call(this,t.apply(this._wrapped,arguments))}}),T.extend(T.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this);
|