Skip to content

Commit 99cee09

Browse files
author
Syno
committed
Handle multiple views folder for dustjs partials
1 parent cfe53bd commit 99cee09

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lib/consolidate.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,25 @@ exports.dust.render = function(str, options, cb) {
507507

508508
engine.onLoad = function(path, callback) {
509509
if (extname(path) === '') path += '.' + ext;
510-
if (path[0] !== '/') path = views + '/' + path;
511-
read(path, options, callback);
510+
// In case of array given in app.set('views', [])
511+
if(Array.isArray(views)){
512+
var existingPath = [];
513+
for (var i = 0; i < views.length; i++)
514+
if (fs.existsSync(views[i] + '/' + path))
515+
existingPath.push(views[i] + '/' + path);
516+
517+
if(existingPath.length == 0)
518+
throw new Error('Cannot find template: ' + path);
519+
else if(existingPath.length > 1) {
520+
console.warn('Multiple file with the same name:\n' + existingPath.join('\n') + '\nDefault using => ' + existingPath[0]);
521+
read(existingPath[0], options, callback);
522+
} else {
523+
read(existingPath[0], options, callback);
524+
}
525+
} else {
526+
if (path[0] !== '/') path = views + '/' + path;
527+
read(path, options, callback);
528+
}
512529
};
513530

514531
try {

0 commit comments

Comments
 (0)