summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/handlebars/base.js32
-rw-r--r--lib/handlebars/compiler/base.js4
-rw-r--r--lib/handlebars/compiler/compiler.js4
-rw-r--r--lib/handlebars/runtime.js4
-rw-r--r--lib/handlebars/utils.js12
5 files changed, 34 insertions, 22 deletions
diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js
index 8640cb8..f5f5996 100644
--- a/lib/handlebars/base.js
+++ b/lib/handlebars/base.js
@@ -43,13 +43,10 @@ Handlebars.registerHelper('blockHelperMissing', function(context, options) {
return inverse(this);
} else if(type === "[object Array]") {
if(context.length > 0) {
- for(var i=0, j=context.length; i<j; i++) {
- ret = ret + fn(context[i]);
- }
+ return Handlebars.helpers.each(context, options);
} else {
- ret = inverse(this);
+ return inverse(this);
}
- return ret;
} else {
return fn(context);
}
@@ -66,20 +63,33 @@ Handlebars.createFrame = Object.create || function(object) {
Handlebars.registerHelper('each', function(context, options) {
var fn = options.fn, inverse = options.inverse;
- var ret = "", data;
+ var i = 0, ret = "", data;
if (options.data) {
data = Handlebars.createFrame(options.data);
}
- if(context && context.length > 0) {
- for(var i=0, j=context.length; i<j; i++) {
- if (data) { data.index = i; }
- ret = ret + fn(context[i], { data: data });
+ if(context && typeof context === 'object') {
+ if(context instanceof Array){
+ for(var j = context.length; i<j; i++) {
+ if (data) { data.index = i; }
+ ret = ret + fn(context[i], { data: data });
+ }
+ } else {
+ for(var key in context) {
+ if(context.hasOwnProperty(key)) {
+ if(data) { data.key = key; }
+ ret = ret + fn(context[key], {data: data});
+ i++;
+ }
+ }
}
- } else {
+ }
+
+ if(i === 0){
ret = inverse(this);
}
+
return ret;
});
diff --git a/lib/handlebars/compiler/base.js b/lib/handlebars/compiler/base.js
index 5319cf9..6f8fdc5 100644
--- a/lib/handlebars/compiler/base.js
+++ b/lib/handlebars/compiler/base.js
@@ -24,7 +24,7 @@ Handlebars.logger = {
Handlebars.log = function(level, str) { Handlebars.logger.log(level, str); };
-return Handlebars;
-
// END(BROWSER)
+
+return Handlebars;
};
diff --git a/lib/handlebars/compiler/compiler.js b/lib/handlebars/compiler/compiler.js
index 97a87f0..6dc43d6 100644
--- a/lib/handlebars/compiler/compiler.js
+++ b/lib/handlebars/compiler/compiler.js
@@ -646,7 +646,7 @@ Handlebars.JavaScriptCompiler = function() {};
this.context.aliases.functionType = '"function"';
this.replaceStack(function(current) {
- return "typeof " + current + " === functionType ? " + current + "() : " + current;
+ return "typeof " + current + " === functionType ? " + current + ".apply(depth0) : " + current;
});
},
@@ -791,7 +791,7 @@ Handlebars.JavaScriptCompiler = function() {};
var nextStack = this.nextStack();
this.source.push('if (foundHelper) { ' + nextStack + ' = foundHelper.call(' + helper.callParams + '); }');
- this.source.push('else { ' + nextStack + ' = ' + nonHelper + '; ' + nextStack + ' = typeof ' + nextStack + ' === functionType ? ' + nextStack + '() : ' + nextStack + '; }');
+ this.source.push('else { ' + nextStack + ' = ' + nonHelper + '; ' + nextStack + ' = typeof ' + nextStack + ' === functionType ? ' + nextStack + '.apply(depth0) : ' + nextStack + '; }');
},
// [invokePartial]
diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js
index 6fd38fd..4537687 100644
--- a/lib/handlebars/runtime.js
+++ b/lib/handlebars/runtime.js
@@ -57,7 +57,7 @@ Handlebars.VM = {
} else if (!Handlebars.compile) {
throw new Handlebars.Exception("The partial " + name + " could not be compiled when running in runtime-only mode");
} else {
- partials[name] = Handlebars.compile(partial);
+ partials[name] = Handlebars.compile(partial, {data: data !== undefined});
return partials[name](context, options);
}
}
@@ -69,4 +69,4 @@ Handlebars.template = Handlebars.VM.template;
return Handlebars;
-}; \ No newline at end of file
+};
diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js
index d467205..cd02e95 100644
--- a/lib/handlebars/utils.js
+++ b/lib/handlebars/utils.js
@@ -2,14 +2,15 @@ exports.attach = function(Handlebars) {
// BEGIN(BROWSER)
+var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack'];
+
Handlebars.Exception = function(message) {
var tmp = Error.prototype.constructor.apply(this, arguments);
- for (var p in tmp) {
- if (tmp.hasOwnProperty(p)) { this[p] = tmp[p]; }
+ // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
+ for (var idx = 0; idx < errorProps.length; idx++) {
+ this[errorProps[idx]] = tmp[errorProps[idx]];
}
-
- this.message = tmp.message;
};
Handlebars.Exception.prototype = new Error();
@@ -23,6 +24,7 @@ Handlebars.SafeString.prototype.toString = function() {
(function() {
var escape = {
+ "&": "&amp;",
"<": "&lt;",
">": "&gt;",
'"': "&quot;",
@@ -30,7 +32,7 @@ Handlebars.SafeString.prototype.toString = function() {
"`": "&#x60;"
};
- var badChars = /&(?!\w+;)|[<>"'`]/g;
+ var badChars = /[&<>"'`]/g;
var possible = /[&<>"'`]/;
var escapeChar = function(chr) {