diff --git a/lib/compiler.js b/lib/compiler.js index b7ea5bf7..61a94797 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -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()); }); diff --git a/lib/handlebars.js b/lib/handlebars.js index 9d6c1645..e27eca9b 100644 --- a/lib/handlebars.js +++ b/lib/handlebars.js @@ -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; diff --git a/test/compat.hbs b/test/compat.hbs new file mode 100644 index 00000000..6d24e9ed --- /dev/null +++ b/test/compat.hbs @@ -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}}