Skip to content

Instantly share code, notes, and snippets.

@xuyang2
Forked from akorchev/micro3.js
Created March 16, 2014 11:07
Show Gist options
  • Save xuyang2/9581581 to your computer and use it in GitHub Desktop.
Save xuyang2/9581581 to your computer and use it in GitHub Desktop.
(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);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment