CommonJS compatibility.

This commit is contained in:
Alan Johnson
2010-09-11 18:24:50 -04:00
parent b4bac7f4f9
commit 7ff015fd5d
3 changed files with 16 additions and 5 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
require('./handlebars');
var handlebars = require('./handlebars');
var fs = require('fs');
if (process.argv.length < 3) {
@@ -14,6 +14,6 @@ process.argv.slice(2).forEach(function(val, index, array) {
var tmpl = fs.readFileSync(parts[1], 'utf8');
console.log(parts[0] + " = " + Handlebars.compileToString(tmpl).toString());
console.log(parts[0] + " = " + handlebars.compileToString(tmpl).toString());
});
+8 -3
View File
@@ -1,7 +1,8 @@
Handlebars = {
var Handlebars = {
compile: function(string) {
var fnBody = Handlebars.compileFunctionBody(string);
return new Function("context", "fallback", fnBody);
var fn = new Function("context", "fallback", "Handlebars", fnBody);
return function(context, fallback) { return fn(context, fallback, Handlebars); };
},
compileToString: function(string) {
@@ -412,4 +413,8 @@ Handlebars.Compiler.prototype = {
}
}
}
}
};
// CommonJS Exports
exports['compile'] = Handlebars.compile;
exports['compileToString'] = Handlebars.compileToString;
+6
View File
@@ -0,0 +1,6 @@
This is the story of guys who work on a project
called {{project}}. Their names were {{#people}}{{firstName}} and {{/people}}
they both enjoyed working on {{project}}.
{{#people}}
{{>personPet}}
{{/people}}