/**
* Module dependencies.
*/
var debug = require('debug')('express:view');
var path = require('path');
var fs = require('fs');
var utils = require('./utils');
/**
* Module variables.
* @private
*/
var dirname = path.dirname;
var basename = path.basename;
var extname = path.extname;
var exists = fs.existsSync || path.existsSync;
var join = path.join;
var resolve = path.resolve;
/**
* Expose `View`.
*/
* @return {String}
* @api private
*/
View.prototype.lookup = function(path){
View.prototype.lookup = function lookup(path) {
var ext = this.ext;
var root = this.root;
debug('lookup "%s"', path);
// resolve the path
path = resolve(root, path);
// <path>.<engine>
if (!utils.isAbsolute(path)) path = join(this.root, path);
if (exists(path)) return path;
// <path>/index.<engine>
path = join(dirname(path), basename(path, ext), 'index' + ext);
* @param {Function} fn
* @api private
*/
View.prototype.render = function(options, fn){
View.prototype.render = function render(options, fn) {
debug('render "%s"', this.path);
this.engine(this.path, options, fn);
};