Files
handlebars.js/lib/handlebars/utils.js
T
wycats 762329913d Fix a number of outstanding issues:
* {{}} escape their contents, {{{}}} and {{& }} do not
* Add support in the parser, tokenizer and AST for partials
  with context (support is still not there in the runtime)
* Fix some inconsistencies with the old behavior involving
  the correct printing of null and undefined
* Add Handlebars.Exception
* Fixed an issue involving ./foo and this/foo
* Fleshed out helperMissing in the specs (this will be
  moved out into handlebars proper once registerHelper
  and registerPartial are added)
2010-12-02 01:13:24 -05:00

55 lines
1.1 KiB
JavaScript

if(exports) {
var Handlebars = {};
}
Handlebars.Exception = function(message) {
this.message = message;
};
// Build out our basic SafeString type
Handlebars.SafeString = function(string) {
this.string = string;
}
Handlebars.SafeString.prototype.toString = function() {
return this.string.toString();
}
Handlebars.Utils = {
escapeExpression: function(string) {
// don't escape SafeStrings, since they're already safe
if (string instanceof Handlebars.SafeString) {
return string.toString();
}
else if (string === null) {
string = "";
}
return string.toString().replace(/&(?!\w+;)|["\\<>]/g, function(str) {
switch(str) {
case "&":
return "&amp;";
break;
case '"':
return "\"";
case "\\":
return "\\\\";
break;
case "<":
return "&lt;";
break;
case ">":
return "&gt;";
break;
default:
return str;
}
});
}
}
if(exports) {
exports.Utils = Handlebars.Utils;
exports.SafeString = Handlebars.SafeString;
exports.Exception = Handlebars.Exception;
}