Created
January 31, 2014 23:46
-
-
Save rorcraft/8745618 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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