summaryrefslogtreecommitdiffstats
path: root/lib/handlebars/compiler/compiler.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/handlebars/compiler/compiler.js')
-rw-r--r--lib/handlebars/compiler/compiler.js35
1 files changed, 24 insertions, 11 deletions
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index c7d051e..039a34e 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -104,7 +104,8 @@ Handlebars.JavaScriptCompiler = function() {};
'each': true,
'if': true,
'unless': true,
- 'with': true
+ 'with': true,
+ 'log': true
};
if (knownHelpers) {
for (var name in knownHelpers) {
@@ -335,6 +336,8 @@ Handlebars.JavaScriptCompiler = function() {};
initializeBuffer: function() {
return this.quotedString("");
},
+
+ namespace: "Handlebars",
// END PUBLIC API
compile: function(environment, options, context, asObject) {
@@ -405,8 +408,9 @@ Handlebars.JavaScriptCompiler = function() {};
var out = [];
if (!this.isChild) {
- var copies = "helpers = helpers || Handlebars.helpers;";
- if(this.environment.usePartial) { copies = copies + " partials = partials || Handlebars.partials;"; }
+ var namespace = this.namespace;
+ var copies = "helpers = helpers || " + namespace + ".helpers;";
+ if(this.environment.usePartial) { copies = copies + " partials = partials || " + namespace + ".partials;"; }
out.push(copies);
} else {
out.push('');
@@ -461,8 +465,6 @@ Handlebars.JavaScriptCompiler = function() {};
params.push("depth" + this.environment.depths.list[i]);
}
- if(params.length === 4 && !this.environment.usePartial) { params.pop(); }
-
if (asObject) {
params.push(this.source.join("\n "));
@@ -522,7 +524,7 @@ Handlebars.JavaScriptCompiler = function() {};
+ " || "
+ this.nameLookup('depth' + this.lastContext, name, 'context');
}
-
+
toPush += ';';
this.source.push(toPush);
} else {
@@ -727,7 +729,7 @@ Handlebars.JavaScriptCompiler = function() {};
};
var reservedWords = ("break case catch continue default delete do else finally " +
- "for function if in instanceof new return switch this throw " +
+ "for function if in instanceof new return switch this throw " +
"try typeof var void while with null true false").split(" ");
var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {};
@@ -756,10 +758,21 @@ Handlebars.precompile = function(string, options) {
Handlebars.compile = function(string, options) {
options = options || {};
- var ast = Handlebars.parse(string);
- var environment = new Handlebars.Compiler().compile(ast, options);
- var templateSpec = new Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true);
- return Handlebars.template(templateSpec);
+ var compiled;
+ function compile() {
+ var ast = Handlebars.parse(string);
+ var environment = new Handlebars.Compiler().compile(ast, options);
+ var templateSpec = new Handlebars.JavaScriptCompiler().compile(environment, options, undefined, true);
+ return Handlebars.template(templateSpec);
+ }
+
+ // Template is only compiled on first use and cached after that point.
+ return function(context, options) {
+ if (!compiled) {
+ compiled = compile();
+ }
+ return compiled.call(this, context, options);
+ };
};
// END(BROWSER)