diff --git a/dist/handlebars.js b/dist/handlebars.js index 9c653ee7..f1e09738 100644 --- a/dist/handlebars.js +++ b/dist/handlebars.js @@ -24,10 +24,7 @@ THE SOFTWARE. // lib/handlebars/base.js -/*jshint eqnull:true*/ -this.Handlebars = {}; - -(function(Handlebars) { +var Handlebars = {}; Handlebars.VERSION = "1.0.0-rc.3"; Handlebars.COMPILER_REVISION = 2; @@ -169,8 +166,6 @@ Handlebars.registerHelper('log', function(context, options) { var level = options.data && options.data.level != null ? parseInt(options.data.level, 10) : 1; Handlebars.log(level, context); }); - -}(this.Handlebars)); ; // lib/handlebars/compiler/parser.js /* Jison generated parser */ @@ -646,6 +641,7 @@ function Parser () { this.yy = {}; }Parser.prototype = parser;parser.Parser = Pa return new Parser; })();; // lib/handlebars/compiler/base.js + Handlebars.Parser = handlebars; Handlebars.parse = function(input) { @@ -699,13 +695,13 @@ Handlebars.print = function(ast) { this.context = context; }; - var verifyMatch = function(open, close) { - if(open.original !== close.original) { - throw new Handlebars.Exception(open.original + " doesn't match " + close.original); - } - }; - Handlebars.AST.BlockNode = function(mustache, program, inverse, close) { + var verifyMatch = function(open, close) { + if(open.original !== close.original) { + throw new Handlebars.Exception(open.original + " doesn't match " + close.original); + } + }; + verifyMatch(mustache.id, close); this.type = "block"; this.mustache = mustache; @@ -851,7 +847,8 @@ Handlebars.SafeString.prototype.toString = function() { } } }; -})();; +})(); +; // lib/handlebars/compiler/compiler.js /*jshint eqnull:true*/ @@ -2114,8 +2111,10 @@ Handlebars.compile = function(input, options) { return compiled.call(this, context, options); }; }; + ; // lib/handlebars/runtime.js + Handlebars.VM = { template: function(templateSpec) { // Just add water diff --git a/lib/handlebars.js b/lib/handlebars.js index 8705269c..7d85c261 100644 --- a/lib/handlebars.js +++ b/lib/handlebars.js @@ -1,14 +1,32 @@ -var Handlebars = require("./handlebars/base"); -module.exports = Handlebars; +var handlebars = require("./handlebars/base"), // Each of these augment the Handlebars object. No need to setup here. // (This is done to easily share code between commonjs and browse envs) -require("./handlebars/utils"); + utils = require("./handlebars/utils"), + compiler = require("./handlebars/compiler"), + runtime = require("./handlebars/runtime"); -require("./handlebars/compiler"); -require("./handlebars/runtime"); +var create = function() { + var hb = handlebars.create(); + + utils.attach(hb); + compiler.attach(hb); + runtime.attach(hb); + + return hb; +}; + +var Handlebars = create(); +Handlebars.create = create; + +module.exports = Handlebars; // instantiate an instance // BEGIN(BROWSER) // END(BROWSER) +// USAGE: +// var handlebars = require('handlebars'); + +// var singleton = handlebars.Handlebars, +// local = handlebars.create(); diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js index 04e9a529..d4057086 100644 --- a/lib/handlebars/base.js +++ b/lib/handlebars/base.js @@ -1,9 +1,8 @@ +module.exports.create = function() { + // BEGIN(BROWSER) -/*jshint eqnull:true*/ -this.Handlebars = {}; - -(function(Handlebars) { +var Handlebars = {}; Handlebars.VERSION = "1.0.0-rc.3"; Handlebars.COMPILER_REVISION = 2; @@ -146,9 +145,10 @@ Handlebars.registerHelper('log', function(context, options) { Handlebars.log(level, context); }); -}(this.Handlebars)); - // END(BROWSER) + +return Handlebars; + +}; -module.exports = this.Handlebars; diff --git a/lib/handlebars/compiler/ast.js b/lib/handlebars/compiler/ast.js index f4485237..1ba1fcf7 100644 --- a/lib/handlebars/compiler/ast.js +++ b/lib/handlebars/compiler/ast.js @@ -1,4 +1,4 @@ -var Handlebars = require('./base'); +exports.attach = function(Handlebars) { // BEGIN(BROWSER) (function() { @@ -39,13 +39,13 @@ var Handlebars = require('./base'); this.context = context; }; - var verifyMatch = function(open, close) { - if(open.original !== close.original) { - throw new Handlebars.Exception(open.original + " doesn't match " + close.original); - } - }; - Handlebars.AST.BlockNode = function(mustache, program, inverse, close) { + var verifyMatch = function(open, close) { + if(open.original !== close.original) { + throw new Handlebars.Exception(open.original + " doesn't match " + close.original); + } + }; + verifyMatch(mustache.id, close); this.type = "block"; this.mustache = mustache; @@ -131,3 +131,6 @@ var Handlebars = require('./base'); })(); // END(BROWSER) +return Handlebars; +}; + diff --git a/lib/handlebars/compiler/base.js b/lib/handlebars/compiler/base.js index df8ced0b..8ff1101d 100644 --- a/lib/handlebars/compiler/base.js +++ b/lib/handlebars/compiler/base.js @@ -1,7 +1,9 @@ var handlebars = require("./parser"); -var Handlebars = require("../base"); + +exports.attach = function(Handlebars) { // BEGIN(BROWSER) + Handlebars.Parser = handlebars; Handlebars.parse = function(input) { @@ -18,4 +20,5 @@ Handlebars.print = function(ast) { }; // END(BROWSER) -module.exports = Handlebars; +return Handlebars; +}; diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js index 4a9a23fd..84008043 100644 --- a/lib/handlebars/compiler/compiler.js +++ b/lib/handlebars/compiler/compiler.js @@ -1,4 +1,8 @@ -var Handlebars = require("./base"); +var compilerbase = require("./base"); + +exports.attach = function(Handlebars) { + +compilerbase.attach(Handlebars); // BEGIN(BROWSER) @@ -1263,5 +1267,11 @@ Handlebars.compile = function(input, options) { }; }; + // END(BROWSER) +return Handlebars; + +}; + + diff --git a/lib/handlebars/compiler/index.js b/lib/handlebars/compiler/index.js index e62c7684..6ed8d219 100644 --- a/lib/handlebars/compiler/index.js +++ b/lib/handlebars/compiler/index.js @@ -1,7 +1,16 @@ // Each of these module will augment the Handlebars object as it loads. No need to perform addition operations -module.exports = require("./base"); -require("./visitor"); -require("./printer"); +module.exports.attach = function(Handlebars) { -require("./ast"); -require("./compiler"); +var visitor = require("./visitor"), + printer = require("./printer"), + ast = require("./ast"), + compiler = require("./compiler"); + +visitor.attach(Handlebars); +printer.attach(Handlebars); +ast.attach(Handlebars); +compiler.attach(Handlebars); + +return Handlebars; + +}; diff --git a/lib/handlebars/compiler/printer.js b/lib/handlebars/compiler/printer.js index 853a4cac..1d96a91f 100644 --- a/lib/handlebars/compiler/printer.js +++ b/lib/handlebars/compiler/printer.js @@ -1,6 +1,7 @@ -var Handlebars = require("./base"); +exports.attach = function(Handlebars) { // BEGIN(BROWSER) + Handlebars.PrintVisitor = function() { this.padding = 0; }; Handlebars.PrintVisitor.prototype = new Handlebars.Visitor(); @@ -128,4 +129,6 @@ Handlebars.PrintVisitor.prototype.comment = function(comment) { }; // END(BROWSER) -exports.PrintVisitor = Handlebars.PrintVisitor; +return Handlebars; +}; + diff --git a/lib/handlebars/compiler/visitor.js b/lib/handlebars/compiler/visitor.js index a557dd3d..5d073140 100644 --- a/lib/handlebars/compiler/visitor.js +++ b/lib/handlebars/compiler/visitor.js @@ -1,4 +1,4 @@ -var Handlebars = require("./base"); +exports.attach = function(Handlebars) { // BEGIN(BROWSER) @@ -9,5 +9,10 @@ Handlebars.Visitor.prototype = { return this[object.type](object); } }; + // END(BROWSER) +return Handlebars; +}; + + diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js index d9bcc6df..805e10fb 100644 --- a/lib/handlebars/runtime.js +++ b/lib/handlebars/runtime.js @@ -1,6 +1,7 @@ -var Handlebars = require("./base"); +exports.attach = function(Handlebars) { // BEGIN(BROWSER) + Handlebars.VM = { template: function(templateSpec) { // Just add water @@ -86,3 +87,6 @@ Handlebars.template = Handlebars.VM.template; // END(BROWSER) +return Handlebars; + +}; diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js index 75390393..2a7861af 100644 --- a/lib/handlebars/utils.js +++ b/lib/handlebars/utils.js @@ -1,4 +1,4 @@ -var Handlebars = require("./base"); +exports.attach = function(Handlebars) { // BEGIN(BROWSER) @@ -63,5 +63,8 @@ Handlebars.SafeString.prototype.toString = function() { } }; })(); + // END(BROWSER) +return Handlebars; +};