Skip to content

Instantly share code, notes, and snippets.

@henriquegogo
Forked from akorchev/micro3.js
Created June 15, 2011 13:56
Show Gist options
  • Save henriquegogo/1027147 to your computer and use it in GitHub Desktop.
Save henriquegogo/1027147 to your computer and use it in GitHub Desktop.
Micro-templating
(function() {
var viewpower = function (str, data){
var fn = new Function("obj",
"var p=[],print=function(){p.push.apply(p,arguments);};" +
"with(obj){p.push('" +
str.replace(/[\r\t\n]/g, " ")
.split("<%").join("\t")
.replace(/((^|%>)[^\t]*)'/g, "$1\r")
.replace(/\t=(.*?)%>/g, "',$1,'")
.split("\t").join("');")
.split("%>").join("p.push('")
.split("\r").join("\\'")
+ "');}return p.join('');");
return fn(data);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment