diff --git a/lib/engine.js b/lib/engine.js index 0048cd1..cb53372 100644 --- a/lib/engine.js +++ b/lib/engine.js @@ -73,17 +73,35 @@ exports.create = function (type, config) { if (path.extname(name) !== options.ext) { f += options.ext; } - // Fixme: handle multiple directories. - var candidate = path.resolve(options.views, f); - fs.stat(candidate, function (err, stat) { - if (err) { - return cb(err); - } - read(err, candidate, name); + locate(options.views, function(err, candidate, name) { + if (err) { + return cb(err); + } + + read(err, candidate, name); }); } + // Look in all view directories + function locate(views, callback) { + if(!Array.isArray(views)) { + views = [views]; + } + var candidate = path.resolve(views[0], f); + fs.stat(candidate, function (err, stat) { + if (err) { + if (views.length > 0) { + return locate(views.slice(1), callback); + } else { + return callback(err); + } + } + + return callback(err, candidate, name); + }); + } + function read(err, file, name) { if (err) { return cb(err);