view.js
This file
The walk stopped after 200 commits: lines older than 9f4968a point at it.
3.15.1Douglas Christopher Wilsonbefore adoption9f4968a
lines 1–77why, one step back1/**2 * Module dependencies.3 */45var path = require('path')6 , fs = require('fs')7 , utils = require('./utils')8 , dirname = path.dirname9 , basename = path.basename10 , extname = path.extname11 , exists = fs.existsSync || path.existsSync12 , join = path.join;1314/**15 * Expose `View`.16 */1718module.exports = View;1920/**21 * Initialize a new `View` with the given `name`.22 *23 * Options:24 *25 * - `defaultEngine` the default template engine name26 * - `engines` template engine require() cache27 * - `root` root path for view lookup28 *29 * @param {String} name30 * @param {Object} options31 * @api private32 */3334function View(name, options) {35 options = options || {};36 this.name = name;37 this.root = options.root;38 var engines = options.engines;39 this.defaultEngine = options.defaultEngine;40 var ext = this.ext = extname(name);41 if (!ext && !this.defaultEngine) throw new Error('No default engine was specified and no extension was provided.');42 if (!ext) name += (ext = this.ext = ('.' != this.defaultEngine[0] ? '.' : '') + this.defaultEngine);43 this.engine = engines[ext] || (engines[ext] = require(ext.slice(1)).__express);44 this.path = this.lookup(name);45}4647/**48 * Lookup view by the given `path`49 *50 * @param {String} path51 * @return {String}52 * @api private53 */5455View.prototype.lookup = function(path){56 var ext = this.ext;5758 // <path>.<engine>59 if (!utils.isAbsolute(path)) path = join(this.root, path);60 if (exists(path)) return path;6162 // <path>/index.<engine>63 path = join(dirname(path), basename(path, ext), 'index' + ext);64 if (exists(path)) return path;65};6667/**68 * Render with the given `options` and callback `fn(err, str)`.69 *70 * @param {Object} options71 * @param {Function} fn72 * @api private73 */7475View.prototype.render = function(options, fn){76 this.engine(this.path, options, fn);77};