Skip to content

Instantly share code, notes, and snippets.

@rorcraft
Created January 31, 2014 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rorcraft/8745618 to your computer and use it in GitHub Desktop.
Save rorcraft/8745618 to your computer and use it in GitHub Desktop.
var assert = require('assert');
var helpers = {
view: function() {
return "viewing: " + this.msg;
}
}
// jade
// "h1= view()"
// compiled jade
var templates = {
home: function(locals) {
var view = locals.view;
return "<h1>" + view() + "</h1>";
}
}
function templateFinder(templateName) {
var template = templates[templateName];
return function extendedTemplate(locals) {
for(fn in helpers) {
locals[fn] = helpers[fn].bind(locals);
}
return template.call(locals, locals);
}
}
var locals = { msg: 'hello world' };
var html = templateFinder("home")(locals);
console.log(html);
// => <h1>viewing: hello world</h1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment