Created
December 24, 2011 19:52
-
-
Save sayrer/1518202 to your computer and use it in GitHub Desktop.
Hogan precompiled
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 Hogan = require('./lib/hogan'); | |
var templates = { | |
test: 'Hello {{name}}!', | |
test2: 'Lorem ipsum dolor sit amet, {{foo}}consectetur adipisicing elit, sed do eiusmod tempor {{bar}}.', | |
test3: '<html><body>incididunt ut labore et dolore magna aliqua.{{baz}} Ut enim ad minim veniam, quis nostrud.</body></html>' | |
}; | |
var compiled = []; | |
console.log('var templates = {') | |
Object.keys(templates).forEach(function(k) { | |
compiled.push(JSON.stringify(k) + ' : ' + Hogan.compile(templates[k], {asString: true})); | |
}); | |
console.log(compiled.join(',')); | |
console.log('}'); | |
console.log('var template = new HoganTemplate();'); | |
console.log('template.r = templates.test2;'); | |
/* outputs | |
var templates = { | |
"test" : function(cx,p){var c = [cx];var b = "";var _ = this;b += "Hello ";b += (_.v(_.f("name",c,p,0)));b += "!";return b;;},"test2" : function(cx,p){var c = [cx];var b = "";var _ = this;b += "Lorem ipsum dolor sit amet, ";b += (_.v(_.f("foo",c,p,0)));b += "consectetur adipisicing elit, sed do eiusmod tempor ";b += (_.v(_.f("bar",c,p,0)));b += ".";return b;;},"test3" : function(cx,p){var c = [cx];var b = "";var _ = this;b += "<html><body>incididunt ut labore et dolore magna aliqua.";b += (_.v(_.f("baz",c,p,0)));b += " Ut enim ad minim veniam, quis nostrud.</body></html>";return b;;} | |
} | |
var template = new HoganTemplate(); | |
template.r = templates.test2; | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment