Bit of cleanup on the context code.

This commit is contained in:
Alan Johnson
2010-08-07 16:23:01 -04:00
parent ccbb241ac9
commit e373f08bd1
+21 -20
View File
@@ -24,27 +24,28 @@ Handlebars.ParseError = function(message) {
this.message = message;
};
Handlebars.Context = function(stack) {
this.__stack__ = stack;
this.__get__ = function(path) {
var context = this;
var parsedPath = Handlebars.parsePath(path);
var depth = parsedPath[0];
var parts = parsedPath[1];
if (depth > 0) {
context = this.__stack__[stack.length - depth];
}
for (var i = 0; i < parts.length; i++) {
context = context[parts[i]];
}
return context;
};
};
Handlebars.buildContext = function(context, stack) {
Handlebars.Context.prototype = context;
return new Handlebars.Context(stack);
contextWrapper = function(stack) {
this.__stack__ = stack;
this.__get__ = function(path) {
var context = this;
var parsedPath = Handlebars.parsePath(path);
var depth = parsedPath[0];
var parts = parsedPath[1];
if (depth > 0) {
context = this.__stack__[stack.length - depth];
}
for (var i = 0; i < parts.length; i++) {
context = context[parts[i]];
}
return context;
};
}
contextWrapper.prototype = context;
return new contextWrapper(stack);
};
// Returns a two element array containing the numbers of contexts to back up the stack and