Skip to content

Instantly share code, notes, and snippets.

@kyo-ago
Created June 30, 2010 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyo-ago/458453 to your computer and use it in GitHub Desktop.
Save kyo-ago/458453 to your computer and use it in GitHub Desktop.
String.prototype.template
(function () {
String.prototype.template = function (param) {
function esc (c) { return '&#'+c.charCodeAt(0)+';'; };
var reg = new RegExp('[&"<>\']', 'g');
return this.replace(/\[%(.+?)%\]/g, function (arg1, key) {
return ((param[key] || '')+'').replace(reg, esc);
});
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment