From 855eae37d0eeb74f673b4f97484ed2a1fee1c1fc Mon Sep 17 00:00:00 2001 From: kpdecker Date: Wed, 9 Oct 2013 02:38:04 -0700 Subject: [PATCH] Create runtime specific module --- lib/handlebars.js | 32 +++++--------------------------- lib/handlebars.runtime.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 27 deletions(-) create mode 100644 lib/handlebars.runtime.js diff --git a/lib/handlebars.js b/lib/handlebars.js index cf538a8b..4abdd4a1 100644 --- a/lib/handlebars.js +++ b/lib/handlebars.js @@ -1,11 +1,4 @@ -module base from "./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) -import SafeString from "./handlebars/safe-string"; -import Exception from "./handlebars/exception"; -module Utils from "./handlebars/utils"; -module runtime from "./handlebars/runtime"; +import Handlebars from "./handlebars.runtime"; // Compiler imports module AST from "./handlebars/compiler/ast"; @@ -13,27 +6,12 @@ import { parser as Parser, parse } from "./handlebars/compiler/base"; import { Compiler, compile, precompile } from "./handlebars/compiler/compiler"; import JavaScriptCompiler from "./handlebars/compiler/javascript-compiler"; -// For compatibility and usage outside of module systems, make the Handlebars object a namespace +var _create = Handlebars.create; var create = function() { - var hb = {}, - env = new base.HandlebarsEnvironment(); - - // support new environments in global namespace mode - hb.registerHelper = env.registerHelper.bind(env); - hb.registerPartial = env.registerPartial.bind(env); - - Utils.extend(hb, base); - hb.SafeString = SafeString; - hb.Exception = Exception; - hb.Utils = Utils; - - hb.VM = runtime; - hb.template = runtime.template; + var hb = _create(); hb.compile = function(input, options) { - options = options || {}; - options.env = options.env || env; - return compile(input, options); + return compile(input, options, hb); }; hb.precompile = precompile; @@ -46,7 +24,7 @@ var create = function() { return hb; }; -var Handlebars = create(); +Handlebars = create(); Handlebars.create = create; export default Handlebars; diff --git a/lib/handlebars.runtime.js b/lib/handlebars.runtime.js new file mode 100644 index 00000000..a5910191 --- /dev/null +++ b/lib/handlebars.runtime.js @@ -0,0 +1,30 @@ +module base from "./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) +import SafeString from "./handlebars/safe-string"; +import Exception from "./handlebars/exception"; +module Utils from "./handlebars/utils"; +module runtime from "./handlebars/runtime"; + +// For compatibility and usage outside of module systems, make the Handlebars object a namespace +var create = function() { + var hb = new base.HandlebarsEnvironment(); + + Utils.extend(hb, base); + hb.SafeString = SafeString; + hb.Exception = Exception; + hb.Utils = Utils; + + hb.VM = runtime; + hb.template = function(spec) { + return runtime.template(spec, hb); + }; + + return hb; +}; + +var Handlebars = create(); +Handlebars.create = create; + +export default Handlebars;