Fix for Dust path evaluation when used with Express 2.5.9 #8

Closed
wants to merge 1 commit into
from
View
@@ -40,7 +40,8 @@ dust.optimizers.format = function (context, node) {
// Duckpunch Express's res.render() method to use Dust. This is necessary
// because Express doesn't support async template engines by default.
http.ServerResponse.prototype.render = function (view, options, callback) {
- var res = this;
+ var res = this,
+ locals = null;
// Support callback as second arg.
if (typeof options === 'function') {
@@ -55,8 +56,11 @@ http.ServerResponse.prototype.render = function (view, options, callback) {
options = options ? baseContext.push(options) : baseContext;
- if (res.locals) {
- options = options.push(res.locals);
+ // Support the case when res.locals is implemented as a getter vs.
+ // a direct object reference.
+ locals = (typeof res.locals === "function") ? res._locals : res.locals;
+ if (locals) {
+ options = options.push(locals);
}
// TODO: Figure out a good way to catch parser errors. Currently Dust's