summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/utils.js
diff options
context:
space:
mode:
authorwycats <wycats@gmail.com>2010-12-02 01:13:24 -0500
committerwycats <wycats@gmail.com>2010-12-02 01:13:24 -0500
commit762329913d447ee6b873d99454715bf5601214f1 (patch)
treee1fd0dc87bfbb22c4789cecc587c43a586d8a5e9 /lib/handlebars/utils.js
parent9846fb8a286a9c8d9d4d90c92be5789ebaba5910 (diff)
downloadhandlebars.js-762329913d447ee6b873d99454715bf5601214f1.zip
handlebars.js-762329913d447ee6b873d99454715bf5601214f1.tar.gz
handlebars.js-762329913d447ee6b873d99454715bf5601214f1.tar.bz2
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)
Diffstat (limited to 'lib/handlebars/utils.js')
-rw-r--r--lib/handlebars/utils.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js
new file mode 100644
index 0000000..a166598
--- /dev/null
+++ b/lib/handlebars/utils.js
@@ -0,0 +1,54 @@
+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;
+}