livelist-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/livelist-rails.js +3 -0
- data/app/assets/javascripts/livelist.coffee +199 -0
- data/app/assets/javascripts/livelist.js +274 -0
- data/app/assets/javascripts/livelist.min.js +1 -0
- data/app/assets/javascripts/mustache.js +435 -0
- data/app/assets/javascripts/underscore-min.js +30 -0
- data/app/assets/javascripts/underscore.js +981 -0
- data/lib/livelist-rails.rb +25 -0
- data/lib/livelist-rails/version.rb +8 -0
- data/livelist-rails.gemspec +24 -0
- metadata +60 -0
@@ -0,0 +1 @@
|
|
1
|
+
((function(){var a=function(a,b){return function(){return a.apply(b,arguments)}},b=Object.prototype.hasOwnProperty,c=function(a,c){function e(){this.constructor=a}for(var d in c)b.call(c,d)&&(a[d]=c[d]);return e.prototype=c.prototype,a.prototype=new e,a.__super__=c.prototype,a};window.Utilities=function(){function b(){this.setOptions=a(this.setOptions,this)}return b.prototype.setOptions=function(a,b){var c=this;return b==null&&(b=this),_.each(a,function(a,c){return b[c]=a})},b}(),window.LiveList=function(a){function b(a){this.globalOptions.listSelector=a.list.renderTo,this.globalOptions.eventName="livelist:"+a.global.resourceName,this.globalOptions.urlPrefix="/"+a.global.resourceName,this.setOptions(a.global,this.globalOptions),this.search=new Search(this.globalOptions,a.search),this.filters=new Filters(this.globalOptions,a.filters),this.pagination=new Pagination(this.globalOptions,a.pagination),this.list=new List(this.search,this.filters,this.pagination,this.globalOptions,a.list)}return c(b,a),b.prototype.globalOptions={data:null,resourceName:"items",resourceNameSingular:"item"},b}(Utilities),window.List=function(b){function d(b,c,d,e,f){var g=this;f==null&&(f={}),this.renderIndex=a(this.renderIndex,this),this.removeFetchingIndication=a(this.removeFetchingIndication,this),this.displayFetchingIndication=a(this.displayFetchingIndication,this),this.data=e.data,this.fetchRequest=null,this.search=b,this.filters=c,this.pagination=d,this.setOptions(e),this.listTemplate="{{#"+this.resourceName+"}}{{>"+this.resourceNameSingular+"}}{{/"+this.resourceName+"}}",this.listItemTemplate="<li>{{id}}</li>",this.fetchingIndicationClass="updating",this.setOptions(f),$(this.renderTo).bind(this.eventName,function(a,b){return g.fetch({filterPresets:null,page:b!=null?b.page:void 0})}),this.fetch({filterPresets:this.filters.presets})}return c(d,b),d.prototype.displayFetchingIndication=function(){return $(this.renderTo).addClass(this.fetchingIndicationClass)},d.prototype.removeFetchingIndication=function(){return $(this.renderTo).removeClass(this.fetchingIndicationClass)},d.prototype.renderIndex=function(a,b,c){return this.data=a,this.render(),this.pagination.render(this.data),this.filters.filters=_.pluck(this.data.filters,"filter_slug"),this.filters.render(this.data)},d.prototype.fetch=function(a){var b,c,d,e=this;return this.fetchRequest&&this.fetchRequest.abort(),c=this.search.searchTerm(),b={filters:{}},((d=a.filterPresets)!=null?d.length:void 0)>0?b.filters=a.filterPresets:_.each(this.filters.filters,function(a){return b.filters[a]=e.filters.filterSelections(a)}),c&&(b.q=c),a.page&&(b.page=a.page),this.fetchRequest=$.ajax({url:this.urlPrefix,dataType:"json",data:b,type:this.httpMethod,beforeSend:this.displayFetchingIndication,success:this.renderIndex})},d.prototype.render=function(){var a;return a={},a[this.resourceNameSingular]=this.listItemTemplate,$(this.renderTo).html(Mustache.to_html(this.listTemplate,this.data,a)),this.removeFetchingIndication()},d}(Utilities),window.Filters=function(b){function d(b,c){var d=this;c==null&&(c={}),this.handleAdvancedOptionsClick=a(this.handleAdvancedOptionsClick,this),this.setOptions(b),this.filters=c.presets?_.keys(c.presets):[],this.setOptions(c),$("input.filter_option",this.renderTo).live("change",function(){return $(d.listSelector).trigger(d.eventName)}),$(this.advancedOptionsToggleSelector).click(this.handleAdvancedOptionsClick)}return c(d,b),d.prototype.filtersTemplate="{{#filters}}\n<div class='filter'>\n <h3>\n {{name}}\n </h3>\n <ul id='{{filter_slug}}_filter_options'>\n {{#options}}\n <label>\n <li>\n <input {{#selected}}checked='checked'{{/selected}}\n class='left filter_option'\n id='filter_{{slug}}'\n name='filters[]'\n type='checkbox'\n value='{{value}}' />\n <div class='left filter_name'>{{name}}</div>\n <div class='right filter_count'>{{count}}</div>\n <div class='clear'></div>\n </li>\n </label>\n {{/options}}\n </ul>\n</div>\n{{/filters}}",d.prototype.filterValues=function(a){return _.pluck($("."+a+"_filter_input"),"value")},d.prototype.filterSelections=function(a){return _.pluck($("#"+a+"_filter_options input.filter_option:checked"),"value")},d.prototype.render=function(a){return $(this.renderTo).html(Mustache.to_html(this.filtersTemplate,a))},d.prototype.handleAdvancedOptionsClick=function(a){return a.preventDefault(),$(this.renderTo).slideToggle()},d}(Utilities),window.Pagination=function(b){function d(b,c){c==null&&(c={}),this.handlePaginationLinkClick=a(this.handlePaginationLinkClick,this),this.pagination=null,this.maxPages=30,this.setOptions(b),this.emptyListMessage="<p>No "+this.resourceName+" matched your filter criteria</p>",this.setOptions(c),$(""+this.renderTo+" a").live("click",this.handlePaginationLinkClick)}return c(d,b),d.prototype.paginationTemplate="{{#isEmpty}}\n {{{emptyListMessage}}}\n{{/isEmpty}}\n{{^isEmpty}}\n{{#previousPage}}\n <a href='{{urlPrefix}}?page={{previousPage}}' data-page='{{previousPage}}'>← Previous</a>\n{{/previousPage}}\n{{^previousPage}}\n <span>← Previous</span>\n{{/previousPage}}\n{{#pages}}\n {{#currentPage}}\n <span>{{page}}</span>\n {{/currentPage}}\n {{^currentPage}}\n <a href='{{urlPrefix}}?page={{page}}' data-page='{{page}}'>{{page}}</a>\n {{/currentPage}}\n{{/pages}}\n{{#nextPage}}\n <a href='{{urlPrefix}}?page={{nextPage}}' data-page='{{nextPage}}'>Next →</a>\n{{/nextPage}}\n{{^nextPage}}\n <span>Next →</span>\n{{/nextPage}}\n{{/isEmpty}}",d.prototype.pagesJSON=function(a,b){var c,d,e,f,g,h;return d=this.maxPages/2,c=a<d?1:a-d,f=c+d*2-1,e=f>=b?b:f,_.map(function(){h=[];for(var a=c;c<=e?a<=e:a>=e;c<=e?a++:a--)h.push(a);return h}.apply(this),function(b){return{page:b,currentPage:function(){return a===b}}})},d.prototype.paginationJSON=function(a){return{isEmpty:a.total_pages===0,emptyListMessage:this.emptyListMessage,currentPage:a.current_page,nextPage:a.next_page,previousPage:a.previous_page,urlPrefix:this.urlPrefix,pages:this.pagesJSON(a.current_page,a.total_pages)}},d.prototype.render=function(a){return this.pagination=this.paginationJSON(a.pagination),$(this.renderTo).html(Mustache.to_html(this.paginationTemplate,this.pagination))},d.prototype.handlePaginationLinkClick=function(a){return a.preventDefault(),$(this.listSelector).trigger(this.eventName,{page:$(a.target).data("page")})},d}(Utilities),window.Search=function(b){function d(b,c){var d=this;c==null&&(c={}),this.handleSearchFormSubmit=a(this.handleSearchFormSubmit,this),this.setOptions(b),this.setOptions(c),$(this.formSelector).submit(function(a){return d.handleSearchFormSubmit(a)})}return c(d,b),d.prototype.searchTerm=function(){var a;return a=$(this.searchTextInputSelector).val(),!a||a===""?null:a},d.prototype.handleSearchFormSubmit=function(a){return a.preventDefault(),$(this.listSelector).trigger(this.eventName)},d}(Utilities)})).call(this);
|
@@ -0,0 +1,435 @@
|
|
1
|
+
/*
|
2
|
+
mustache.js — Logic-less templates in JavaScript
|
3
|
+
|
4
|
+
See http://mustache.github.com/ for more info.
|
5
|
+
*/
|
6
|
+
|
7
|
+
var Mustache = function () {
|
8
|
+
var _toString = Object.prototype.toString;
|
9
|
+
|
10
|
+
Array.isArray = Array.isArray || function (obj) {
|
11
|
+
return _toString.call(obj) == "[object Array]";
|
12
|
+
}
|
13
|
+
|
14
|
+
var _trim = String.prototype.trim, trim;
|
15
|
+
|
16
|
+
if (_trim) {
|
17
|
+
trim = function (text) {
|
18
|
+
return text == null ? "" : _trim.call(text);
|
19
|
+
}
|
20
|
+
} else {
|
21
|
+
var trimLeft, trimRight;
|
22
|
+
|
23
|
+
// IE doesn't match non-breaking spaces with \s.
|
24
|
+
if ((/\S/).test("\xA0")) {
|
25
|
+
trimLeft = /^[\s\xA0]+/;
|
26
|
+
trimRight = /[\s\xA0]+$/;
|
27
|
+
} else {
|
28
|
+
trimLeft = /^\s+/;
|
29
|
+
trimRight = /\s+$/;
|
30
|
+
}
|
31
|
+
|
32
|
+
trim = function (text) {
|
33
|
+
return text == null ? "" :
|
34
|
+
text.toString().replace(trimLeft, "").replace(trimRight, "");
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
var escapeMap = {
|
39
|
+
"&": "&",
|
40
|
+
"<": "<",
|
41
|
+
">": ">",
|
42
|
+
'"': '"',
|
43
|
+
"'": '''
|
44
|
+
};
|
45
|
+
|
46
|
+
function escapeHTML(string) {
|
47
|
+
return String(string).replace(/&(?!\w+;)|[<>"']/g, function (s) {
|
48
|
+
return escapeMap[s] || s;
|
49
|
+
});
|
50
|
+
}
|
51
|
+
|
52
|
+
var regexCache = {};
|
53
|
+
var Renderer = function () {};
|
54
|
+
|
55
|
+
Renderer.prototype = {
|
56
|
+
otag: "{{",
|
57
|
+
ctag: "}}",
|
58
|
+
pragmas: {},
|
59
|
+
buffer: [],
|
60
|
+
pragmas_implemented: {
|
61
|
+
"IMPLICIT-ITERATOR": true
|
62
|
+
},
|
63
|
+
context: {},
|
64
|
+
|
65
|
+
render: function (template, context, partials, in_recursion) {
|
66
|
+
// reset buffer & set context
|
67
|
+
if (!in_recursion) {
|
68
|
+
this.context = context;
|
69
|
+
this.buffer = []; // TODO: make this non-lazy
|
70
|
+
}
|
71
|
+
|
72
|
+
// fail fast
|
73
|
+
if (!this.includes("", template)) {
|
74
|
+
if (in_recursion) {
|
75
|
+
return template;
|
76
|
+
} else {
|
77
|
+
this.send(template);
|
78
|
+
return;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
// get the pragmas together
|
83
|
+
template = this.render_pragmas(template);
|
84
|
+
|
85
|
+
// render the template
|
86
|
+
var html = this.render_section(template, context, partials);
|
87
|
+
|
88
|
+
// render_section did not find any sections, we still need to render the tags
|
89
|
+
if (html === false) {
|
90
|
+
html = this.render_tags(template, context, partials, in_recursion);
|
91
|
+
}
|
92
|
+
|
93
|
+
if (in_recursion) {
|
94
|
+
return html;
|
95
|
+
} else {
|
96
|
+
this.sendLines(html);
|
97
|
+
}
|
98
|
+
},
|
99
|
+
|
100
|
+
/*
|
101
|
+
Sends parsed lines
|
102
|
+
*/
|
103
|
+
send: function (line) {
|
104
|
+
if (line !== "") {
|
105
|
+
this.buffer.push(line);
|
106
|
+
}
|
107
|
+
},
|
108
|
+
|
109
|
+
sendLines: function (text) {
|
110
|
+
if (text) {
|
111
|
+
var lines = text.split("\n");
|
112
|
+
for (var i = 0; i < lines.length; i++) {
|
113
|
+
this.send(lines[i]);
|
114
|
+
}
|
115
|
+
}
|
116
|
+
},
|
117
|
+
|
118
|
+
/*
|
119
|
+
Looks for %PRAGMAS
|
120
|
+
*/
|
121
|
+
render_pragmas: function (template) {
|
122
|
+
// no pragmas
|
123
|
+
if (!this.includes("%", template)) {
|
124
|
+
return template;
|
125
|
+
}
|
126
|
+
|
127
|
+
var that = this;
|
128
|
+
var regex = this.getCachedRegex("render_pragmas", function (otag, ctag) {
|
129
|
+
return new RegExp(otag + "%([\\w-]+) ?([\\w]+=[\\w]+)?" + ctag, "g");
|
130
|
+
});
|
131
|
+
|
132
|
+
return template.replace(regex, function (match, pragma, options) {
|
133
|
+
if (!that.pragmas_implemented[pragma]) {
|
134
|
+
throw({message:
|
135
|
+
"This implementation of mustache doesn't understand the '" +
|
136
|
+
pragma + "' pragma"});
|
137
|
+
}
|
138
|
+
that.pragmas[pragma] = {};
|
139
|
+
if (options) {
|
140
|
+
var opts = options.split("=");
|
141
|
+
that.pragmas[pragma][opts[0]] = opts[1];
|
142
|
+
}
|
143
|
+
return "";
|
144
|
+
// ignore unknown pragmas silently
|
145
|
+
});
|
146
|
+
},
|
147
|
+
|
148
|
+
/*
|
149
|
+
Tries to find a partial in the curent scope and render it
|
150
|
+
*/
|
151
|
+
render_partial: function (name, context, partials) {
|
152
|
+
name = trim(name);
|
153
|
+
if (!partials || partials[name] === undefined) {
|
154
|
+
throw({message: "unknown_partial '" + name + "'"});
|
155
|
+
}
|
156
|
+
if (!context || typeof context[name] != "object") {
|
157
|
+
return this.render(partials[name], context, partials, true);
|
158
|
+
}
|
159
|
+
return this.render(partials[name], context[name], partials, true);
|
160
|
+
},
|
161
|
+
|
162
|
+
/*
|
163
|
+
Renders inverted (^) and normal (#) sections
|
164
|
+
*/
|
165
|
+
render_section: function (template, context, partials) {
|
166
|
+
if (!this.includes("#", template) && !this.includes("^", template)) {
|
167
|
+
// did not render anything, there were no sections
|
168
|
+
return false;
|
169
|
+
}
|
170
|
+
|
171
|
+
var that = this;
|
172
|
+
|
173
|
+
var regex = this.getCachedRegex("render_section", function (otag, ctag) {
|
174
|
+
// This regex matches _the first_ section ({{#foo}}{{/foo}}), and captures the remainder
|
175
|
+
return new RegExp(
|
176
|
+
"^([\\s\\S]*?)" + // all the crap at the beginning that is not {{*}} ($1)
|
177
|
+
|
178
|
+
otag + // {{
|
179
|
+
"(\\^|\\#)\\s*(.+)\\s*" + // #foo (# == $2, foo == $3)
|
180
|
+
ctag + // }}
|
181
|
+
|
182
|
+
"\n*([\\s\\S]*?)" + // between the tag ($2). leading newlines are dropped
|
183
|
+
|
184
|
+
otag + // {{
|
185
|
+
"\\/\\s*\\3\\s*" + // /foo (backreference to the opening tag).
|
186
|
+
ctag + // }}
|
187
|
+
|
188
|
+
"\\s*([\\s\\S]*)$", // everything else in the string ($4). leading whitespace is dropped.
|
189
|
+
|
190
|
+
"g");
|
191
|
+
});
|
192
|
+
|
193
|
+
|
194
|
+
// for each {{#foo}}{{/foo}} section do...
|
195
|
+
return template.replace(regex, function (match, before, type, name, content, after) {
|
196
|
+
// before contains only tags, no sections
|
197
|
+
var renderedBefore = before ? that.render_tags(before, context, partials, true) : "",
|
198
|
+
|
199
|
+
// after may contain both sections and tags, so use full rendering function
|
200
|
+
renderedAfter = after ? that.render(after, context, partials, true) : "",
|
201
|
+
|
202
|
+
// will be computed below
|
203
|
+
renderedContent,
|
204
|
+
|
205
|
+
value = that.find(name, context);
|
206
|
+
|
207
|
+
if (type === "^") { // inverted section
|
208
|
+
if (!value || Array.isArray(value) && value.length === 0) {
|
209
|
+
// false or empty list, render it
|
210
|
+
renderedContent = that.render(content, context, partials, true);
|
211
|
+
} else {
|
212
|
+
renderedContent = "";
|
213
|
+
}
|
214
|
+
} else if (type === "#") { // normal section
|
215
|
+
if (Array.isArray(value)) { // Enumerable, Let's loop!
|
216
|
+
renderedContent = that.map(value, function (row) {
|
217
|
+
return that.render(content, that.create_context(row), partials, true);
|
218
|
+
}).join("");
|
219
|
+
} else if (that.is_object(value)) { // Object, Use it as subcontext!
|
220
|
+
renderedContent = that.render(content, that.create_context(value),
|
221
|
+
partials, true);
|
222
|
+
} else if (typeof value == "function") {
|
223
|
+
// higher order section
|
224
|
+
renderedContent = value.call(context, content, function (text) {
|
225
|
+
return that.render(text, context, partials, true);
|
226
|
+
});
|
227
|
+
} else if (value) { // boolean section
|
228
|
+
renderedContent = that.render(content, context, partials, true);
|
229
|
+
} else {
|
230
|
+
renderedContent = "";
|
231
|
+
}
|
232
|
+
}
|
233
|
+
|
234
|
+
return renderedBefore + renderedContent + renderedAfter;
|
235
|
+
});
|
236
|
+
},
|
237
|
+
|
238
|
+
/*
|
239
|
+
Replace {{foo}} and friends with values from our view
|
240
|
+
*/
|
241
|
+
render_tags: function (template, context, partials, in_recursion) {
|
242
|
+
// tit for tat
|
243
|
+
var that = this;
|
244
|
+
|
245
|
+
var new_regex = function () {
|
246
|
+
return that.getCachedRegex("render_tags", function (otag, ctag) {
|
247
|
+
return new RegExp(otag + "(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?" + ctag + "+", "g");
|
248
|
+
});
|
249
|
+
};
|
250
|
+
|
251
|
+
var regex = new_regex();
|
252
|
+
var tag_replace_callback = function (match, operator, name) {
|
253
|
+
switch(operator) {
|
254
|
+
case "!": // ignore comments
|
255
|
+
return "";
|
256
|
+
case "=": // set new delimiters, rebuild the replace regexp
|
257
|
+
that.set_delimiters(name);
|
258
|
+
regex = new_regex();
|
259
|
+
return "";
|
260
|
+
case ">": // render partial
|
261
|
+
return that.render_partial(name, context, partials);
|
262
|
+
case "{": // the triple mustache is unescaped
|
263
|
+
return that.find(name, context);
|
264
|
+
default: // escape the value
|
265
|
+
return escapeHTML(that.find(name, context));
|
266
|
+
}
|
267
|
+
};
|
268
|
+
var lines = template.split("\n");
|
269
|
+
for(var i = 0; i < lines.length; i++) {
|
270
|
+
lines[i] = lines[i].replace(regex, tag_replace_callback, this);
|
271
|
+
if (!in_recursion) {
|
272
|
+
this.send(lines[i]);
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
if (in_recursion) {
|
277
|
+
return lines.join("\n");
|
278
|
+
}
|
279
|
+
},
|
280
|
+
|
281
|
+
set_delimiters: function (delimiters) {
|
282
|
+
var dels = delimiters.split(" ");
|
283
|
+
this.otag = this.escape_regex(dels[0]);
|
284
|
+
this.ctag = this.escape_regex(dels[1]);
|
285
|
+
},
|
286
|
+
|
287
|
+
escape_regex: function (text) {
|
288
|
+
// thank you Simon Willison
|
289
|
+
if (!arguments.callee.sRE) {
|
290
|
+
var specials = [
|
291
|
+
'/', '.', '*', '+', '?', '|',
|
292
|
+
'(', ')', '[', ']', '{', '}', '\\'
|
293
|
+
];
|
294
|
+
arguments.callee.sRE = new RegExp(
|
295
|
+
'(\\' + specials.join('|\\') + ')', 'g'
|
296
|
+
);
|
297
|
+
}
|
298
|
+
return text.replace(arguments.callee.sRE, '\\$1');
|
299
|
+
},
|
300
|
+
|
301
|
+
/*
|
302
|
+
find `name` in current `context`. That is find me a value
|
303
|
+
from the view object
|
304
|
+
*/
|
305
|
+
find: function (name, context) {
|
306
|
+
name = trim(name);
|
307
|
+
|
308
|
+
// Checks whether a value is thruthy or false or 0
|
309
|
+
function is_kinda_truthy(bool) {
|
310
|
+
return bool === false || bool === 0 || bool;
|
311
|
+
}
|
312
|
+
|
313
|
+
var value;
|
314
|
+
|
315
|
+
// check for dot notation eg. foo.bar
|
316
|
+
if (name.match(/([a-z_]+)\./ig)) {
|
317
|
+
var childValue = this.walk_context(name, context);
|
318
|
+
if (is_kinda_truthy(childValue)) {
|
319
|
+
value = childValue;
|
320
|
+
}
|
321
|
+
} else {
|
322
|
+
if (is_kinda_truthy(context[name])) {
|
323
|
+
value = context[name];
|
324
|
+
} else if (is_kinda_truthy(this.context[name])) {
|
325
|
+
value = this.context[name];
|
326
|
+
}
|
327
|
+
}
|
328
|
+
|
329
|
+
if (typeof value == "function") {
|
330
|
+
return value.apply(context);
|
331
|
+
}
|
332
|
+
if (value !== undefined) {
|
333
|
+
return value;
|
334
|
+
}
|
335
|
+
// silently ignore unkown variables
|
336
|
+
return "";
|
337
|
+
},
|
338
|
+
|
339
|
+
walk_context: function (name, context) {
|
340
|
+
var path = name.split('.');
|
341
|
+
// if the var doesn't exist in current context, check the top level context
|
342
|
+
var value_context = (context[path[0]] != undefined) ? context : this.context;
|
343
|
+
var value = value_context[path.shift()];
|
344
|
+
while (value != undefined && path.length > 0) {
|
345
|
+
value_context = value;
|
346
|
+
value = value[path.shift()];
|
347
|
+
}
|
348
|
+
// if the value is a function, call it, binding the correct context
|
349
|
+
if (typeof value == "function") {
|
350
|
+
return value.apply(value_context);
|
351
|
+
}
|
352
|
+
return value;
|
353
|
+
},
|
354
|
+
|
355
|
+
// Utility methods
|
356
|
+
|
357
|
+
/* includes tag */
|
358
|
+
includes: function (needle, haystack) {
|
359
|
+
return haystack.indexOf(this.otag + needle) != -1;
|
360
|
+
},
|
361
|
+
|
362
|
+
// by @langalex, support for arrays of strings
|
363
|
+
create_context: function (_context) {
|
364
|
+
if (this.is_object(_context)) {
|
365
|
+
return _context;
|
366
|
+
} else {
|
367
|
+
var iterator = ".";
|
368
|
+
if (this.pragmas["IMPLICIT-ITERATOR"]) {
|
369
|
+
iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator;
|
370
|
+
}
|
371
|
+
var ctx = {};
|
372
|
+
ctx[iterator] = _context;
|
373
|
+
return ctx;
|
374
|
+
}
|
375
|
+
},
|
376
|
+
|
377
|
+
is_object: function (a) {
|
378
|
+
return a && typeof a == "object";
|
379
|
+
},
|
380
|
+
|
381
|
+
/*
|
382
|
+
Why, why, why? Because IE. Cry, cry cry.
|
383
|
+
*/
|
384
|
+
map: function (array, fn) {
|
385
|
+
if (typeof array.map == "function") {
|
386
|
+
return array.map(fn);
|
387
|
+
} else {
|
388
|
+
var r = [];
|
389
|
+
var l = array.length;
|
390
|
+
for(var i = 0; i < l; i++) {
|
391
|
+
r.push(fn(array[i]));
|
392
|
+
}
|
393
|
+
return r;
|
394
|
+
}
|
395
|
+
},
|
396
|
+
|
397
|
+
getCachedRegex: function (name, generator) {
|
398
|
+
var byOtag = regexCache[this.otag];
|
399
|
+
if (!byOtag) {
|
400
|
+
byOtag = regexCache[this.otag] = {};
|
401
|
+
}
|
402
|
+
|
403
|
+
var byCtag = byOtag[this.ctag];
|
404
|
+
if (!byCtag) {
|
405
|
+
byCtag = byOtag[this.ctag] = {};
|
406
|
+
}
|
407
|
+
|
408
|
+
var regex = byCtag[name];
|
409
|
+
if (!regex) {
|
410
|
+
regex = byCtag[name] = generator(this.otag, this.ctag);
|
411
|
+
}
|
412
|
+
|
413
|
+
return regex;
|
414
|
+
}
|
415
|
+
};
|
416
|
+
|
417
|
+
return({
|
418
|
+
name: "mustache.js",
|
419
|
+
version: "0.4.0-dev",
|
420
|
+
|
421
|
+
/*
|
422
|
+
Turns a template and view into HTML
|
423
|
+
*/
|
424
|
+
to_html: function (template, view, partials, send_fun) {
|
425
|
+
var renderer = new Renderer();
|
426
|
+
if (send_fun) {
|
427
|
+
renderer.send = send_fun;
|
428
|
+
}
|
429
|
+
renderer.render(template, view || {}, partials);
|
430
|
+
if (!send_fun) {
|
431
|
+
return renderer.buffer.join("\n");
|
432
|
+
}
|
433
|
+
}
|
434
|
+
});
|
435
|
+
}();
|
@@ -0,0 +1,30 @@
|
|
1
|
+
// Underscore.js 1.2.3
|
2
|
+
// (c) 2009-2011 Jeremy Ashkenas, DocumentCloud Inc.
|
3
|
+
// Underscore is freely distributable under the MIT license.
|
4
|
+
// Portions of Underscore are inspired or borrowed from Prototype,
|
5
|
+
// Oliver Steele's Functional, and John Resig's Micro-Templating.
|
6
|
+
// For all details and documentation:
|
7
|
+
// http://documentcloud.github.com/underscore
|
8
|
+
(function(){function r(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return false;switch(e){case "[object String]":return a==String(c);case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source==
|
9
|
+
c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){if(f=a.length,g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&r(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(m.call(a,h)&&(f++,!(g=m.call(c,h)&&r(a[h],c[h],d))))break;if(g){for(h in c)if(m.call(c,
|
10
|
+
h)&&!f--)break;g=!f}}d.pop();return g}var s=this,F=s._,o={},k=Array.prototype,p=Object.prototype,i=k.slice,G=k.concat,H=k.unshift,l=p.toString,m=p.hasOwnProperty,v=k.forEach,w=k.map,x=k.reduce,y=k.reduceRight,z=k.filter,A=k.every,B=k.some,q=k.indexOf,C=k.lastIndexOf,p=Array.isArray,I=Object.keys,t=Function.prototype.bind,b=function(a){return new n(a)};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports)exports=module.exports=b;exports._=b}else typeof define==="function"&&
|
11
|
+
define.amd?define("underscore",function(){return b}):s._=b;b.VERSION="1.2.3";var j=b.each=b.forEach=function(a,c,b){if(a!=null)if(v&&a.forEach===v)a.forEach(c,b);else if(a.length===+a.length)for(var e=0,f=a.length;e<f;e++){if(e in a&&c.call(b,a[e],e,a)===o)break}else for(e in a)if(m.call(a,e)&&c.call(b,a[e],e,a)===o)break};b.map=function(a,c,b){var e=[];if(a==null)return e;if(w&&a.map===w)return a.map(c,b);j(a,function(a,g,h){e[e.length]=c.call(b,a,g,h)});return e};b.reduce=b.foldl=b.inject=function(a,
|
12
|
+
c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(x&&a.reduce===x)return e&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(y&&a.reduceRight===y)return e&&(c=b.bind(c,e)),f?a.reduceRight(c,d):a.reduceRight(c);var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,
|
13
|
+
c,d,e):b.reduce(g,c)};b.find=b.detect=function(a,c,b){var e;D(a,function(a,g,h){if(c.call(b,a,g,h))return e=a,true});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(z&&a.filter===z)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(A&&a.every===A)return a.every(c,
|
14
|
+
b);j(a,function(a,g,h){if(!(e=e&&c.call(b,a,g,h)))return o});return e};var D=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(B&&a.some===B)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return o});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;return q&&a.indexOf===q?a.indexOf(c)!=-1:b=D(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(c.call?c||a:a[c]).apply(a,
|
15
|
+
d)})};b.pluck=function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b<e.computed&&(e={value:a,
|
16
|
+
computed:b})});return e.value};b.shuffle=function(a){var c=[],b;j(a,function(a,f){f==0?c[0]=a:(b=Math.floor(Math.random()*(f+1)),c[f]=c[b],c[b]=a)});return c};b.sortBy=function(a,c,d){return b.pluck(b.map(a,function(a,b,g){return{value:a,criteria:c.call(d,a,b,g)}}).sort(function(a,c){var b=a.criteria,d=c.criteria;return b<d?-1:b>d?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=
|
17
|
+
function(a,c,d){d||(d=b.identity);for(var e=0,f=a.length;e<f;){var g=e+f>>1;d(a[g])<d(c)?e=g+1:f=g}return e};b.toArray=function(a){return!a?[]:a.toArray?a.toArray():b.isArray(a)?i.call(a):b.isArguments(a)?i.call(a):b.values(a)};b.size=function(a){return b.toArray(a).length};b.first=b.head=function(a,b,d){return b!=null&&!d?i.call(a,0,b):a[0]};b.initial=function(a,b,d){return i.call(a,0,a.length-(b==null||d?1:b))};b.last=function(a,b,d){return b!=null&&!d?i.call(a,Math.max(a.length-b,0)):a[a.length-
|
18
|
+
1]};b.rest=b.tail=function(a,b,d){return i.call(a,b==null||d?1:b)};b.compact=function(a){return b.filter(a,function(a){return!!a})};b.flatten=function(a,c){return b.reduce(a,function(a,e){if(b.isArray(e))return a.concat(c?e:b.flatten(e));a[a.length]=e;return a},[])};b.without=function(a){return b.difference(a,i.call(arguments,1))};b.uniq=b.unique=function(a,c,d){var d=d?b.map(a,d):a,e=[];b.reduce(d,function(d,g,h){if(0==h||(c===true?b.last(d)!=g:!b.include(d,g)))d[d.length]=g,e[e.length]=a[h];return d},
|
19
|
+
[]);return e};b.union=function(){return b.uniq(b.flatten(arguments,true))};b.intersection=b.intersect=function(a){var c=i.call(arguments,1);return b.filter(b.uniq(a),function(a){return b.every(c,function(c){return b.indexOf(c,a)>=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e<c;e++)d[e]=b.pluck(a,""+e);return d};b.indexOf=function(a,
|
20
|
+
c,d){if(a==null)return-1;var e;if(d)return d=b.sortedIndex(a,c),a[d]===c?d:-1;if(q&&a.indexOf===q)return a.indexOf(c);for(d=0,e=a.length;d<e;d++)if(d in a&&a[d]===c)return d;return-1};b.lastIndexOf=function(a,b){if(a==null)return-1;if(C&&a.lastIndexOf===C)return a.lastIndexOf(b);for(var d=a.length;d--;)if(d in a&&a[d]===b)return d;return-1};b.range=function(a,b,d){arguments.length<=1&&(b=a||0,a=0);for(var d=arguments[2]||1,e=Math.max(Math.ceil((b-a)/d),0),f=0,g=Array(e);f<e;)g[f++]=a,a+=d;return g};
|
21
|
+
var E=function(){};b.bind=function(a,c){var d,e;if(a.bind===t&&t)return t.apply(a,i.call(arguments,1));if(!b.isFunction(a))throw new TypeError;e=i.call(arguments,2);return d=function(){if(!(this instanceof d))return a.apply(c,e.concat(i.call(arguments)));E.prototype=a.prototype;var b=new E,g=a.apply(b,e.concat(i.call(arguments)));return Object(g)===g?g:b}};b.bindAll=function(a){var c=i.call(arguments,1);c.length==0&&(c=b.functions(a));j(c,function(c){a[c]=b.bind(a[c],a)});return a};b.memoize=function(a,
|
22
|
+
c){var d={};c||(c=b.identity);return function(){var b=c.apply(this,arguments);return m.call(d,b)?d[b]:d[b]=a.apply(this,arguments)}};b.delay=function(a,b){var d=i.call(arguments,2);return setTimeout(function(){return a.apply(a,d)},b)};b.defer=function(a){return b.delay.apply(b,[a,1].concat(i.call(arguments,1)))};b.throttle=function(a,c){var d,e,f,g,h,i=b.debounce(function(){h=g=false},c);return function(){d=this;e=arguments;var b;f||(f=setTimeout(function(){f=null;h&&a.apply(d,e);i()},c));g?h=true:
|
23
|
+
a.apply(d,e);i();g=true}};b.debounce=function(a,b){var d;return function(){var e=this,f=arguments;clearTimeout(d);d=setTimeout(function(){d=null;a.apply(e,f)},b)}};b.once=function(a){var b=false,d;return function(){if(b)return d;b=true;return d=a.apply(this,arguments)}};b.wrap=function(a,b){return function(){var d=G.apply([a],arguments);return b.apply(this,d)}};b.compose=function(){var a=arguments;return function(){for(var b=arguments,d=a.length-1;d>=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=
|
24
|
+
function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=I||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var b=[],d;for(d in a)m.call(a,d)&&(b[b.length]=d);return b};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)b[d]!==void 0&&(a[d]=b[d])});return a};b.defaults=function(a){j(i.call(arguments,
|
25
|
+
1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return r(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(m.call(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=p||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===
|
26
|
+
Object(a)};b.isArguments=function(a){return l.call(a)=="[object Arguments]"};if(!b.isArguments(arguments))b.isArguments=function(a){return!(!a||!m.call(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)==
|
27
|
+
"[object Date]"};b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.noConflict=function(){s._=F;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e<a;e++)b.call(d,e)};b.escape=function(a){return(""+a).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.mixin=function(a){j(b.functions(a),function(c){J(c,
|
28
|
+
b[c]=a[c])})};var K=0;b.uniqueId=function(a){var b=K++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape,function(a,b){return"',_.escape("+b.replace(/\\'/g,"'")+"),'"}).replace(d.interpolate,function(a,b){return"',"+b.replace(/\\'/g,
|
29
|
+
"'")+",'"}).replace(d.evaluate||null,function(a,b){return"');"+b.replace(/\\'/g,"'").replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e.call(this,a,b)}};var n=function(a){this._wrapped=a};b.prototype=n.prototype;var u=function(a,c){return c?b(a).chain():a},J=function(a,c){n.prototype[a]=function(){var a=i.call(arguments);H.call(a,this._wrapped);return u(c.apply(b,
|
30
|
+
a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];n.prototype[a]=function(){b.apply(this._wrapped,arguments);return u(this._wrapped,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];n.prototype[a]=function(){return u(b.apply(this._wrapped,arguments),this._chain)}});n.prototype.chain=function(){this._chain=true;return this};n.prototype.value=function(){return this._wrapped}}).call(this);
|