summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/runtime.js
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2013-07-26 16:50:37 +0000
committerYehuda Katz <wycats@gmail.com>2013-07-26 16:50:37 +0000
commit5f664dd78b2c558a8a560b3fd0074109d52daf62 (patch)
tree16a72bc0c85699e95bed94c927a8ab2586617ece /lib/handlebars/runtime.js
parentf5c8484ea0c1ac1aec6994ad3b5928fb67b7aa62 (diff)
downloadhandlebars.js-5f664dd78b2c558a8a560b3fd0074109d52daf62.zip
handlebars.js-5f664dd78b2c558a8a560b3fd0074109d52daf62.tar.gz
handlebars.js-5f664dd78b2c558a8a560b3fd0074109d52daf62.tar.bz2
Make the Handlebars environment into an object
The idea is that the environment wraps up the mutable stuff in Handlebars (like the helpers) and that you could theoretically create a new one at any time and pass it in to Handlebars.template. Every test makes a new environment and uses it in template compilation.
Diffstat (limited to 'lib/handlebars/runtime.js')
-rw-r--r--lib/handlebars/runtime.js16
1 files changed, 7 insertions, 9 deletions
diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js
index 991bdfd..74361e8 100644
--- a/lib/handlebars/runtime.js
+++ b/lib/handlebars/runtime.js
@@ -3,17 +3,14 @@ import { COMPILER_REVISION, REVISION_CHANGES } from "./base";
// TODO: Remove this line and break up compilePartial
-export function template(templateSpec, Hbars) {
- // TODO: Make this less global
- Hbars = Hbars || Handlebars;
-
- if (Hbars.compile) {
+export function template(templateSpec, Hbars, compile) {
+ if (compile) {
var invokePartialWrapper = function(partial, name, context, helpers, partials, data) {
var result = invokePartial.apply(this, arguments);
if (result) { return result; }
var options = { helpers: helpers, partials: partials, data: data };
- partials[name] = Hbars.compile(partial, { data: data !== undefined });
+ partials[name] = compile(partial, { data: data !== undefined });
return partials[name](context, options);
};
} else {
@@ -24,6 +21,10 @@ export function template(templateSpec, Hbars) {
};
}
+ if (!Hbars) {
+ throw new Error("YUNO HANDLEBARS");
+ }
+
// Just add water
var container = {
escapeExpression: escapeExpression,
@@ -56,9 +57,6 @@ export function template(templateSpec, Hbars) {
return function(context, options) {
options = options || {};
- Hbars = Hbars || require("handlebars");
-
- // TODO: Why does templateSpec require a reference to the global Handlebars?
var result = templateSpec.call(container, Hbars, context, options.helpers, options.partials, options.data);
var compilerInfo = container.compilerInfo || [],