Skip to content

Commit a20cf00

Browse files
committed
Consistent spacing
1 parent f44254c commit a20cf00

File tree

1 file changed

+55
-56
lines changed

1 file changed

+55
-56
lines changed

mustache.js

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
See http://mustache.github.com/ for more info.
55
*/
66

7-
var Mustache = function() {
7+
var Mustache = function () {
88
var _toString = Object.prototype.toString;
99

1010
Array.isArray = Array.isArray || function (obj) {
@@ -48,16 +48,16 @@ var Mustache = function() {
4848
},
4949
context: {},
5050

51-
render: function(template, context, partials, in_recursion) {
51+
render: function (template, context, partials, in_recursion) {
5252
// reset buffer & set context
53-
if(!in_recursion) {
53+
if (!in_recursion) {
5454
this.context = context;
5555
this.buffer = []; // TODO: make this non-lazy
5656
}
5757

5858
// fail fast
59-
if(!this.includes("", template)) {
60-
if(in_recursion) {
59+
if (!this.includes("", template)) {
60+
if (in_recursion) {
6161
return template;
6262
} else {
6363
this.send(template);
@@ -86,13 +86,13 @@ var Mustache = function() {
8686
/*
8787
Sends parsed lines
8888
*/
89-
send: function(line) {
90-
if(line !== "") {
89+
send: function (line) {
90+
if (line !== "") {
9191
this.buffer.push(line);
9292
}
9393
},
9494

95-
sendLines: function(text) {
95+
sendLines: function (text) {
9696
if (text) {
9797
var lines = text.split("\n");
9898
for (var i = 0; i < lines.length; i++) {
@@ -104,25 +104,25 @@ var Mustache = function() {
104104
/*
105105
Looks for %PRAGMAS
106106
*/
107-
render_pragmas: function(template) {
107+
render_pragmas: function (template) {
108108
// no pragmas
109-
if(!this.includes("%", template)) {
109+
if (!this.includes("%", template)) {
110110
return template;
111111
}
112112

113113
var that = this;
114-
var regex = this.getCachedRegex("render_pragmas", function(otag, ctag) {
114+
var regex = this.getCachedRegex("render_pragmas", function (otag, ctag) {
115115
return new RegExp(otag + "%([\\w-]+) ?([\\w]+=[\\w]+)?" + ctag, "g");
116116
});
117117

118-
return template.replace(regex, function(match, pragma, options) {
119-
if(!that.pragmas_implemented[pragma]) {
118+
return template.replace(regex, function (match, pragma, options) {
119+
if (!that.pragmas_implemented[pragma]) {
120120
throw({message:
121121
"This implementation of mustache doesn't understand the '" +
122122
pragma + "' pragma"});
123123
}
124124
that.pragmas[pragma] = {};
125-
if(options) {
125+
if (options) {
126126
var opts = options.split("=");
127127
that.pragmas[pragma][opts[0]] = opts[1];
128128
}
@@ -134,12 +134,12 @@ var Mustache = function() {
134134
/*
135135
Tries to find a partial in the curent scope and render it
136136
*/
137-
render_partial: function(name, context, partials) {
137+
render_partial: function (name, context, partials) {
138138
name = trim(name);
139-
if(!partials || partials[name] === undefined) {
139+
if (!partials || partials[name] === undefined) {
140140
throw({message: "unknown_partial '" + name + "'"});
141141
}
142-
if(typeof(context[name]) != "object") {
142+
if (typeof(context[name]) != "object") {
143143
return this.render(partials[name], context, partials, true);
144144
}
145145
return this.render(partials[name], context[name], partials, true);
@@ -148,15 +148,15 @@ var Mustache = function() {
148148
/*
149149
Renders inverted (^) and normal (#) sections
150150
*/
151-
render_section: function(template, context, partials) {
152-
if(!this.includes("#", template) && !this.includes("^", template)) {
151+
render_section: function (template, context, partials) {
152+
if (!this.includes("#", template) && !this.includes("^", template)) {
153153
// did not render anything, there were no sections
154154
return false;
155155
}
156156

157157
var that = this;
158158

159-
var regex = this.getCachedRegex("render_section", function(otag, ctag) {
159+
var regex = this.getCachedRegex("render_section", function (otag, ctag) {
160160
// This regex matches _the first_ section ({{#foo}}{{/foo}}), and captures the remainder
161161
return new RegExp(
162162
"^([\\s\\S]*?)" + // all the crap at the beginning that is not {{*}} ($1)
@@ -178,7 +178,7 @@ var Mustache = function() {
178178

179179

180180
// for each {{#foo}}{{/foo}} section do...
181-
return template.replace(regex, function(match, before, type, name, content, after) {
181+
return template.replace(regex, function (match, before, type, name, content, after) {
182182
// before contains only tags, no sections
183183
var renderedBefore = before ? that.render_tags(before, context, partials, true) : "",
184184

@@ -199,15 +199,15 @@ var Mustache = function() {
199199
}
200200
} else if (type === "#") { // normal section
201201
if (Array.isArray(value)) { // Enumerable, Let's loop!
202-
renderedContent = that.map(value, function(row) {
202+
renderedContent = that.map(value, function (row) {
203203
return that.render(content, that.create_context(row), partials, true);
204204
}).join("");
205205
} else if (that.is_object(value)) { // Object, Use it as subcontext!
206206
renderedContent = that.render(content, that.create_context(value),
207207
partials, true);
208208
} else if (typeof value === "function") {
209209
// higher order section
210-
renderedContent = value.call(context, content, function(text) {
210+
renderedContent = value.call(context, content, function (text) {
211211
return that.render(text, context, partials, true);
212212
});
213213
} else if (value) { // boolean section
@@ -224,20 +224,20 @@ var Mustache = function() {
224224
/*
225225
Replace {{foo}} and friends with values from our view
226226
*/
227-
render_tags: function(template, context, partials, in_recursion) {
227+
render_tags: function (template, context, partials, in_recursion) {
228228
// tit for tat
229229
var that = this;
230230

231231

232232

233-
var new_regex = function() {
234-
return that.getCachedRegex("render_tags", function(otag, ctag) {
233+
var new_regex = function () {
234+
return that.getCachedRegex("render_tags", function (otag, ctag) {
235235
return new RegExp(otag + "(=|!|>|\\{|%)?([^\\/#\\^]+?)\\1?" + ctag + "+", "g");
236236
});
237237
};
238238

239239
var regex = new_regex();
240-
var tag_replace_callback = function(match, operator, name) {
240+
var tag_replace_callback = function (match, operator, name) {
241241
switch(operator) {
242242
case "!": // ignore comments
243243
return "";
@@ -256,25 +256,25 @@ var Mustache = function() {
256256
var lines = template.split("\n");
257257
for(var i = 0; i < lines.length; i++) {
258258
lines[i] = lines[i].replace(regex, tag_replace_callback, this);
259-
if(!in_recursion) {
259+
if (!in_recursion) {
260260
this.send(lines[i]);
261261
}
262262
}
263263

264-
if(in_recursion) {
264+
if (in_recursion) {
265265
return lines.join("\n");
266266
}
267267
},
268268

269-
set_delimiters: function(delimiters) {
269+
set_delimiters: function (delimiters) {
270270
var dels = delimiters.split(" ");
271271
this.otag = this.escape_regex(dels[0]);
272272
this.ctag = this.escape_regex(dels[1]);
273273
},
274274

275-
escape_regex: function(text) {
275+
escape_regex: function (text) {
276276
// thank you Simon Willison
277-
if(!arguments.callee.sRE) {
277+
if (!arguments.callee.sRE) {
278278
var specials = [
279279
'/', '.', '*', '+', '?', '|',
280280
'(', ')', '[', ']', '{', '}', '\\'
@@ -290,7 +290,7 @@ var Mustache = function() {
290290
find `name` in current `context`. That is find me a value
291291
from the view object
292292
*/
293-
find: function(name, context) {
293+
find: function (name, context) {
294294
name = trim(name);
295295

296296
// Checks whether a value is thruthy or false or 0
@@ -301,41 +301,40 @@ var Mustache = function() {
301301
var value;
302302

303303
// check for dot notation eg. foo.bar
304-
if(name.match(/([a-z_]+)\./ig)){
304+
if (name.match(/([a-z_]+)\./ig)) {
305305
var childValue = this.walk_context(name, context);
306-
if(is_kinda_truthy(childValue)) {
306+
if (is_kinda_truthy(childValue)) {
307307
value = childValue;
308308
}
309-
}
310-
else{
311-
if(is_kinda_truthy(context[name])) {
309+
} else {
310+
if (is_kinda_truthy(context[name])) {
312311
value = context[name];
313-
} else if(is_kinda_truthy(this.context[name])) {
312+
} else if (is_kinda_truthy(this.context[name])) {
314313
value = this.context[name];
315314
}
316315
}
317316

318-
if(typeof value === "function") {
317+
if (typeof value === "function") {
319318
return value.apply(context);
320319
}
321-
if(value !== undefined) {
320+
if (value !== undefined) {
322321
return value;
323322
}
324323
// silently ignore unkown variables
325324
return "";
326325
},
327326

328-
walk_context: function(name, context){
327+
walk_context: function (name, context) {
329328
var path = name.split('.');
330329
// if the var doesn't exist in current context, check the top level context
331330
var value_context = (context[path[0]] != undefined) ? context : this.context;
332331
var value = value_context[path.shift()];
333-
while(value != undefined && path.length > 0){
332+
while (value != undefined && path.length > 0) {
334333
value_context = value;
335334
value = value[path.shift()];
336335
}
337336
// if the value is a function, call it, binding the correct context
338-
if(typeof value === "function") {
337+
if (typeof value === "function") {
339338
return value.apply(value_context);
340339
}
341340
return value;
@@ -344,16 +343,16 @@ var Mustache = function() {
344343
// Utility methods
345344

346345
/* includes tag */
347-
includes: function(needle, haystack) {
346+
includes: function (needle, haystack) {
348347
return haystack.indexOf(this.otag + needle) != -1;
349348
},
350349

351350
/*
352351
Does away with nasty characters
353352
*/
354-
escape: function(s) {
353+
escape: function (s) {
355354
s = String(s === null ? "" : s);
356-
return s.replace(/&(?!\w+;)|["'<>\\]/g, function(s) {
355+
return s.replace(/&(?!\w+;)|["'<>\\]/g, function (s) {
357356
switch(s) {
358357
case "&": return "&amp;";
359358
case '"': return '&quot;';
@@ -366,12 +365,12 @@ var Mustache = function() {
366365
},
367366

368367
// by @langalex, support for arrays of strings
369-
create_context: function(_context) {
370-
if(this.is_object(_context)) {
368+
create_context: function (_context) {
369+
if (this.is_object(_context)) {
371370
return _context;
372371
} else {
373372
var iterator = ".";
374-
if(this.pragmas["IMPLICIT-ITERATOR"]) {
373+
if (this.pragmas["IMPLICIT-ITERATOR"]) {
375374
iterator = this.pragmas["IMPLICIT-ITERATOR"].iterator;
376375
}
377376
var ctx = {};
@@ -380,14 +379,14 @@ var Mustache = function() {
380379
}
381380
},
382381

383-
is_object: function(a) {
382+
is_object: function (a) {
384383
return a && typeof a == "object";
385384
},
386385

387386
/*
388387
Why, why, why? Because IE. Cry, cry cry.
389388
*/
390-
map: function(array, fn) {
389+
map: function (array, fn) {
391390
if (typeof array.map == "function") {
392391
return array.map(fn);
393392
} else {
@@ -400,7 +399,7 @@ var Mustache = function() {
400399
}
401400
},
402401

403-
getCachedRegex: function(name, generator) {
402+
getCachedRegex: function (name, generator) {
404403
var byOtag = regexCache[this.otag];
405404
if (!byOtag) {
406405
byOtag = regexCache[this.otag] = {};
@@ -427,13 +426,13 @@ var Mustache = function() {
427426
/*
428427
Turns a template and view into HTML
429428
*/
430-
to_html: function(template, view, partials, send_fun) {
429+
to_html: function (template, view, partials, send_fun) {
431430
var renderer = new Renderer();
432-
if(send_fun) {
431+
if (send_fun) {
433432
renderer.send = send_fun;
434433
}
435434
renderer.render(template, view || {}, partials);
436-
if(!send_fun) {
435+
if (!send_fun) {
437436
return renderer.buffer.join("\n");
438437
}
439438
}

0 commit comments

Comments
 (0)