|
|
@@ -14,6 +14,7 @@ var Mustache = function() { |
|
|
Renderer.prototype = { |
|
|
Renderer.prototype = { |
|
|
otag: "{{", |
|
|
otag: "{{", |
|
|
ctag: "}}", |
|
|
ctag: "}}", |
|
|
|
|
|
pragmas: {}, |
|
|
|
|
|
|
|
|
render: function(template, context, partials) { |
|
|
render: function(template, context, partials) { |
|
|
// fail fast |
|
|
// fail fast |
|
|
@@ -21,10 +22,29 @@ var Mustache = function() { |
|
|
return template; |
|
|
return template; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template = this.render_pragmas(template); |
|
|
var html = this.render_section(template, context, partials); |
|
|
var html = this.render_section(template, context, partials); |
|
|
return this.render_tags(html, context, partials); |
|
|
return this.render_tags(html, context, partials); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
Looks for %PRAGMAS |
|
|
|
|
|
*/ |
|
|
|
|
|
render_pragmas: function(template) { |
|
|
|
|
|
// no pragmas |
|
|
|
|
|
if(template.indexOf(this.otag + "%") == -1) { |
|
|
|
|
|
return template; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var that = this; |
|
|
|
|
|
var regex = new RegExp(this.otag + "%(.+)" + this.ctag); |
|
|
|
|
|
return template.replace(regex, function(match, pragma) { |
|
|
|
|
|
that.pragmas[pragma] = true; |
|
|
|
|
|
return ""; |
|
|
|
|
|
// ignore unknown pragmas silently |
|
|
|
|
|
}); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
Tries to find a partial in the global scope and render it |
|
|
Tries to find a partial in the global scope and render it |
|
|
*/ |
|
|
*/ |
|
|
@@ -73,7 +93,7 @@ var Mustache = function() { |
|
|
var lines = template.split("\n"); |
|
|
var lines = template.split("\n"); |
|
|
|
|
|
|
|
|
var new_regex = function() { |
|
|
var new_regex = function() { |
|
|
return new RegExp(that.otag + "(=|!|>|\\{)?([^\/#]+?)\\1?" + |
|
|
|
|
|
|
|
|
return new RegExp(that.otag + "(=|!|>|\\{|%)?([^\/#]+?)\\1?" + |
|
|
that.ctag + "+", "g"); |
|
|
that.ctag + "+", "g"); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
@@ -97,6 +117,7 @@ var Mustache = function() { |
|
|
return that.render_partial(name, context, partials); |
|
|
return that.render_partial(name, context, partials); |
|
|
case "{": // the triple mustache is unescaped |
|
|
case "{": // the triple mustache is unescaped |
|
|
return that.find(name, context); |
|
|
return that.find(name, context); |
|
|
|
|
|
return ""; |
|
|
default: // escape the value |
|
|
default: // escape the value |
|
|
return that.escape(that.find(name, context)); |
|
|
return that.escape(that.find(name, context)); |
|
|
} |
|
|
} |
|
|
@@ -177,10 +198,11 @@ var Mustache = function() { |
|
|
return _new; |
|
|
return _new; |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// by @langalex, support for arrays of strings |
|
|
create_context: function(_context) { |
|
|
create_context: function(_context) { |
|
|
if(this.is_object(_context)) { |
|
|
if(this.is_object(_context)) { |
|
|
return _context; |
|
|
return _context; |
|
|
} else { |
|
|
|
|
|
|
|
|
} else if(this.pragmas["ENABLE-STRING-ARRAYS"]) { |
|
|
return {'.': _context}; |
|
|
return {'.': _context}; |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|