Skip to content

Instantly share code, notes, and snippets.

@kates
Created September 9, 2011 10:49
Show Gist options
  • Save kates/1205935 to your computer and use it in GitHub Desktop.
Save kates/1205935 to your computer and use it in GitHub Desktop.
faster resig micro template
(function(window){
window.tmpl = function(str, c) {
var c = c || "it";
return new Function(c,
"var p=[];p.push('" +
str.replace(/[\r\t\n]/g, " ")
.replace(/'(?=[^<]*%>)/g,"\t")
.replace(/'/g, "\\'")
.replace(/\t/g, "'")
.replace(/<%=(.+?)%>/g, "',$1,'")
.replace(/<%/g, "');")
.replace(/%>/g, "p.push('") +
"');return p.join('');"
);
};
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment