Added view index resolution support

This commit is contained in:
Tj Holowaychuk 2010-12-05 09:55:11 -08:00
parent 42ea6af1eb
commit a54e59666a
5 changed files with 18 additions and 7 deletions

View File

@ -37,7 +37,7 @@ var users = [
];
app.get('/', function(req, res){
res.render('user/list', { users: users });
res.render('users', { users: users });
});
app.listen(3000);

View File

@ -22,6 +22,12 @@ var utils = require('../utils')
var cache = {};
/**
* Existance cache.
*/
var exists = {};
/**
* Initialize a new `View` with the given `view` path and `options`.
*
@ -53,11 +59,16 @@ var View = exports = module.exports = function View(view, options) {
*/
View.prototype.__defineGetter__('exists', function(){
try {
stat(this.path);
return true;
} catch (err) {
return false;
var path = this.path;
if (null != exists[path]) {
return exists[path];
} else {
try {
stat(path);
return exists[path] = true;
} catch (err) {
return exists[path] = false;
}
}
});

View File

@ -271,7 +271,7 @@ module.exports = {
{ url: '/nope' },
function(res){
assert.ok(res.body.indexOf('Error: ENOENT') >= 0);
assert.ok(res.body.indexOf('nope.jade') >= 0);
assert.ok(res.body.indexOf('nope/index.jade') >= 0);
});
beforeExit(function(){