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 fileTake it
The walk stopped after 200 commits: lines older than e1da383 point at it.
new ViewTj Holowaychukbefore adoptione1da383
lines 1–12why, one step back12/*!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 back13 , utils = require('./utils')new ViewTj Holowaychukbefore adoptione1da383
line 14why, one step back14 , fs = require('fs')added index lookup support backTj Holowaychukbefore adoption041974e
lines 15–16why, one step back15 , dirname = path.dirname16 , basename = path.basenamenew ViewTj Holowaychukbefore adoptione1da383
line 17why, one step back17 , extname = path.extnameadded index lookup support backTj Holowaychukbefore adoption041974e
line 18why, one step back18 , exists = path.existsSyncnew ViewTj Holowaychukbefore adoptione1da383
lines 19–29why, one step back19 , join = path.join;2021/**22 * Expose `View`.23 */2425module.exports = View;2627/**28 * Initialize a new `View` with the given `name`.29 *docsTj Holowaychukbefore adoption7369d86
lines 30–35why, one step back30 * Options:31 *32 * - `defaultEngine` the default template engine name 33 * - `engines` template engine require() cache 34 * - `root` root path for view lookup 35 *new ViewTj Holowaychukbefore adoptione1da383
lines 36–37why, one step back36 * @param {String} name37 * @param {Object} optionsdocsTj Holowaychukbefore adoption7369d86
line 38why, one step back38 * @api privatenew ViewTj Holowaychukbefore adoptione1da383
lines 39–43why, one step back39 */4041function View(name, options) {42 options = options || {};43 this.name = name;added index lookup support backTj Holowaychukbefore adoption041974e
line 44why, one step back44 this.root = options.root;new ViewTj Holowaychukbefore adoptione1da383
lines 45–46why, one step back45 var engines = options.engines;46 this.defaultEngine = options.defaultEngine;misc refactoringTj Holowaychukbefore adoption705cdb6
line 47why, one step back47 var ext = this.ext = extname(name);map register functionTj Holowaychukbefore adoption02f48aa
line 48why, one step back48 if (!ext) name += (ext = this.ext = '.' + this.defaultEngine);Merge branch 'view-signature'Tj Holowaychukbefore adoption2d77279
line 49why, one step back49 this.engine = engines[ext] || (engines[ext] = require(ext.slice(1)).__express);added index lookup support backTj Holowaychukbefore adoption041974e
line 50why, one step back50 this.path = this.lookup(name);new ViewTj Holowaychukbefore adoptione1da383
line 51why, one step back51}View#contents()Tj Holowaychukbefore adoption6d47011
lines 52–53why, one step back5253/**docsTj Holowaychukbefore adoption90fc80f
lines 54–61why, one step back54 * Lookup view by the given `path`55 *56 * @param {String} path57 * @return {String}58 * @api private59 */6061View.prototype.lookup = function(path){map register functionTj Holowaychukbefore adoption02f48aa
line 62why, one step back62 var ext = this.ext;more refactoringTj Holowaychukbefore adoption371b381
line 63why, one step back63added index lookup support backTj Holowaychukbefore adoption041974e
line 64why, one step back64 // <path>.<engine>Fixed app.render() absolute path supportTj Holowaychukbefore adoptionb9dee73
line 65why, one step back65 if (!utils.isAbsolute(path)) path = join(this.root, path);added index lookup support backTj Holowaychukbefore adoption041974e
lines 66–68why, one step back66 if (exists(path)) return path;6768 // <path>/index.<engine>more refactoringTj Holowaychukbefore adoption371b381
line 69why, one step back69 path = join(dirname(path), basename(path, ext), 'index' + ext);added index lookup support backTj Holowaychukbefore adoption041974e
lines 70–71why, one step back70 if (exists(path)) return path;71};docsTj Holowaychukbefore adoption7369d86
lines 72–79why, one step back7273/**74 * Render with the given `options` and callback `fn(err, str)`.75 *76 * @param {Object} options77 * @param {Function} fn78 * @api private79 */new ViewTj Holowaychukbefore adoptione1da383
lines 80–81why, one step back8081View.prototype.render = function(options, fn){Merge branch 'view-signature'Tj Holowaychukbefore adoption2d77279
line 82why, one step back82 this.engine(this.path, options, fn);new ViewTj Holowaychukbefore adoptione1da383
line 83why, one step back83};