mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
Storing these in Git seems kind of weird, but seems to be [1] the done thing. I have to say, it's a lot more appealing than getting 3 packages from npm installed globally on every prod and dev machine -- we already have too much of that with 'pip install'. We can upgrade these in the future by running 'npm update' in the repo root directory. [1] http://www.futurealoof.com/posts/nodemodules-in-git.html (imported from commit 60a9d6a7cafe742442d87e9f3abc25750e179780)
71 lines
1.7 KiB
JavaScript
71 lines
1.7 KiB
JavaScript
exports.attach = function(Handlebars) {
|
|
|
|
// BEGIN(BROWSER)
|
|
|
|
var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
|
|
|
|
Handlebars.Exception = function(message) {
|
|
var tmp = Error.prototype.constructor.apply(this, arguments);
|
|
|
|
// Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
|
|
for (var idx = 0; idx < errorProps.length; idx++) {
|
|
this[errorProps[idx]] = tmp[errorProps[idx]];
|
|
}
|
|
};
|
|
Handlebars.Exception.prototype = new Error();
|
|
|
|
// Build out our basic SafeString type
|
|
Handlebars.SafeString = function(string) {
|
|
this.string = string;
|
|
};
|
|
Handlebars.SafeString.prototype.toString = function() {
|
|
return this.string.toString();
|
|
};
|
|
|
|
(function() {
|
|
var escape = {
|
|
"&": "&",
|
|
"<": "<",
|
|
">": ">",
|
|
'"': """,
|
|
"'": "'",
|
|
"`": "`"
|
|
};
|
|
|
|
var badChars = /[&<>"'`]/g;
|
|
var possible = /[&<>"'`]/;
|
|
|
|
var escapeChar = function(chr) {
|
|
return escape[chr] || "&";
|
|
};
|
|
|
|
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 === false) {
|
|
return "";
|
|
}
|
|
|
|
if(!possible.test(string)) { return string; }
|
|
return string.replace(badChars, escapeChar);
|
|
},
|
|
|
|
isEmpty: function(value) {
|
|
if (!value && value !== 0) {
|
|
return true;
|
|
} else if(Object.prototype.toString.call(value) === "[object Array]" && value.length === 0) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
};
|
|
})();
|
|
|
|
// END(BROWSER)
|
|
|
|
return Handlebars;
|
|
};
|