diff --git a/lib/panels/template/index.js b/lib/panels/template/index.js index a963a7a..f255fdf 100644 --- a/lib/panels/template/index.js +++ b/lib/panels/template/index.js @@ -2,14 +2,27 @@ var path = require('path'), fs = require('fs'); -var isAbsolute = function (path) { +var isAbsolute = function(path) { return ('/' === path[0]) || (':' === path[1] && '\\' === path[2]); }; // handle 'view engine' express directive -var getPath = function (view, root, default_engine) { - if (!isAbsolute(view)) { - view = path.join(root, view); +var getPath = function(view, root, default_engine) { + if (Array.isArray(root)) { + // iterate over array and fs stat the view + for (var i = 0; i < root.length; i++) { + var maybeView = path.join(root[i], view) + if (!path.isAbsolute(maybeView)) { + maybeView = path.join(root, maybeView) + } + try { + var stat = fs.statSync(maybeView) + view = maybeView; + break; + } catch (e) { + // empty on purpose + } + } } var ext = path.extname(view); @@ -46,4 +59,4 @@ module.exports = { } }; } -}; \ No newline at end of file +};