Skip to content
Myr

view.js

This file

Path

lib/view.js

83 lines · 1.7 KiB · JavaScript

Last changed by

Merge branch 'view-signature'Tj Holowaychukbefore adoption2d77279

History of this file

Take it

The walk stopped after 200 commits: lines older than b8a589d point at it.

first new testTj Holowaychukbefore adoptionb8a589d

lines 1–12why, one step back
1
2/*!3 * Express - View4 * Copyright(c) 2010 TJ Holowaychuk <tj@vision-media.ca>5 * MIT Licensed6 */78/**9 * Module dependencies.10 */1112var path = require('path')

Fixed app.render() absolute path supportTj Holowaychukbefore adoptionb9dee73

line 13why, one step back
13 , utils = require('./utils')

first new testTj Holowaychukbefore adoptionb8a589d

lines 14–48why, one step back
14 , fs = require('fs')
15 , dirname = path.dirname16 , basename = path.basename17 , extname = path.extname18 , exists = path.existsSync19 , join = path.join;2021/**22 * Expose `View`.23 */2425module.exports = View;2627/**28 * Initialize a new `View` with the given `name`.29 *30 * Options:31 *32 * - `defaultEngine` the default template engine name 33 * - `engines` template engine require() cache 34 * - `root` root path for view lookup 35 *36 * @param {String} name37 * @param {Object} options38 * @api private39 */4041function View(name, options) {42 options = options || {};43 this.name = name;44 this.root = options.root;45 var engines = options.engines;46 this.defaultEngine = options.defaultEngine;47 var ext = this.ext = extname(name);48 if (!ext) name += (ext = this.ext = '.' + this.defaultEngine);

Merge branch 'view-signature'Tj Holowaychukbefore adoption2d77279

line 49why, one step back
49 this.engine = engines[ext] || (engines[ext] = require(ext.slice(1)).__express);

first new testTj Holowaychukbefore adoptionb8a589d

lines 50–64why, one step back
50 this.path = this.lookup(name);
51}5253/**54 * Lookup view by the given `path`55 *56 * @param {String} path57 * @return {String}58 * @api private59 */6061View.prototype.lookup = function(path){62 var ext = this.ext;6364 // <path>.<engine>

Fixed app.render() absolute path supportTj Holowaychukbefore adoptionb9dee73

line 65why, one step back
65 if (!utils.isAbsolute(path)) path = join(this.root, path);

first new testTj Holowaychukbefore adoptionb8a589d

lines 66–81why, one step back
66 if (exists(path)) return path;
6768 // <path>/index.<engine>69 path = join(dirname(path), basename(path, ext), 'index' + ext);70 if (exists(path)) return path;71};7273/**74 * Render with the given `options` and callback `fn(err, str)`.75 *76 * @param {Object} options77 * @param {Function} fn78 * @api private79 */8081View.prototype.render = function(options, fn){

Merge branch 'view-signature'Tj Holowaychukbefore adoption2d77279

line 82why, one step back
82 this.engine(this.path, options, fn);

first new testTj Holowaychukbefore adoptionb8a589d

line 83why, one step back
83};