Skip to content
This repository has been archived by the owner on Jan 25, 2020. It is now read-only.

Add support for multiple view folders #110

Open
wants to merge 3 commits into
base: v1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down