Skip to content

Instantly share code, notes, and snippets.

@typehorror
Forked from mkalas/LICENSE.txt
Last active December 14, 2015 09:59
Show Gist options
  • Save typehorror/5068808 to your computer and use it in GitHub Desktop.
Save typehorror/5068808 to your computer and use it in GitHub Desktop.
function(
a, // the string source from which the template is compiled
b // the default `with` context of the template (optional)
){
return function(
c, // the object called as `this` in the template
d // the `with` context of this template call (optional)
){
return a.replace(
/{{(([^}]|}[^}])*)}}/g, // a regexp that finds the interpolated code: "{{<code>}}" and allow object definition
function(
a, // not used, only positional
e // the code matched by the interpolation
){
return Function(
"x",
"with(x)return " + e // the result of the interpolated code
).call(
c, // pass the data object as `this`, with
d // the most
|| b // specific
|| {} // context.
)
}
)
}
}
function(a,b){return function(c,d){return a.replace(/{{(([^}]|}[^}])*)}}/g,function(a,e){return Function("x","with(x)return "+e).call(c,d||b||{})})}}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "template",
"keywords": ["template", "HTML", "render"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment