Bit of cleanup on the context code.
This commit is contained in:
+21
-20
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user