public
Last active — forked from akorchev/micro3.js

Micro-templating

  • Download Gist
micro3.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
(function() {
this.tmpl3 = function tmpl(str, data) {
var value = "var out = ''; out+=" + "'" +
 
str.replace(/[\r\t\n]/g, " ")
.replace(/'(?=[^%]*%>)/g,"\t")
.split("'").join("\\'")
.split("\t").join("'")
.replace(/<%=(.+?)%>/g, "'; out += $1; out += '")
.split("<%").join("';")
.split("%>").join("out+='")
+ "'; return out;";
return new Function("data", value);
}
})();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.