Skip to content
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
20 changes: 19 additions & 1 deletion lib/express-handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ ExpressHandlebars.prototype.renderView = function (viewPath, options, callback)
var view;
var viewsPath = options.settings && options.settings.views;
if (viewsPath) {
view = this._getTemplateName(path.relative(viewsPath, viewPath));
view = this._getView(viewsPath, viewPath);
}

// Merge render-level and instance-level helpers together.
Expand Down Expand Up @@ -327,6 +327,24 @@ ExpressHandlebars.prototype._getTemplateName = function (filePath, namespace) {
return name;
};

ExpressHandlebars.prototype._getView = function(viewsPath, viewPath) {
if (!Array.isArray(viewsPath)) {
return this._getTemplateName(path.relative(viewsPath, viewPath));
}

var self = this;
var stripFilename = /[\/\\][^\/\\]+?$/;

// Stripping filename (rather than indexOf) in case there are
// multiple views folders in the same parent directory
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is why we need a criteria for determine the best match. Should we go with, the file must exist in the dir, and have the shortest length to be the winner?


viewsPath.forEach(function(viewDir) {
if (viewDir === path.normalize(viewPath).replace(stripFilename, '')) {
return self._getTemplateName(path.relative(viewDir, viewPath));
}
});
}

ExpressHandlebars.prototype._resolveLayoutPath = function (layoutPath) {
if (!layoutPath) {
return null;
Expand Down