Skip to content

Commit

Permalink
Fixed _ prefix object resolution on partials (resolveObjectName), add…
Browse files Browse the repository at this point in the history
…ed _ prefix fallback to view file resolution (prefixPath)
  • Loading branch information
Hunter Loftis authored and tj committed Dec 22, 2010
1 parent 5d87133 commit 1c2e9a4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/express/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,20 @@ http.ServerResponse.prototype.render = function(view, options, fn, parent){
? new Partial(view, options)
: new View(view, options);

// Ensure view exists, otherwise try index
// Ensure view exists, otherwise try _ prefix
if (!view.exists) {
view = partial
? new Partial(view.prefixPath, options)
: new View(view.prefixPath, options);
}

// Ensure view _ prefix exists, otherwise try index
if (!view.exists) {
view = partial
? new Partial(view.indexPath, options)
: new View(view.indexPath, options);
}

// Dynamic helper support
if (false !== options.dynamicHelpers) {
// cache
Expand Down
1 change: 1 addition & 0 deletions lib/express/view/partial.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ exports.resolveObjectName = function(view){
.split('/')
.slice(-1)[0]
.split('.')[0]
.replace(/^_/, '')
.replace(/[^a-zA-Z0-9 ]+/g, ' ')
.split(/ +/).map(function(word, i){
return i
Expand Down
11 changes: 11 additions & 0 deletions lib/express/view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ View.prototype.__defineGetter__('indexPath', function(){
+ '/index' + this.extension;
});

/**
* Return _ prefix path alternative
*
* @return {String}
* @api public
*/

View.prototype.__defineGetter__('prefixPath', function(){
return this.dirname + '/_' + this.basename;
});

/**
* Register the given template engine `exports`
* as `ext`. For example we may wish to map ".html"
Expand Down

0 comments on commit 1c2e9a4

Please sign in to comment.