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 e1da383 point at it.

new ViewTj Holowaychukbefore adoptione1da383

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')

new ViewTj Holowaychukbefore adoptione1da383

line 14why, one step back
14 , fs = require('fs')

added index lookup support backTj Holowaychukbefore adoption041974e

lines 15–16why, one step back
15 , dirname = path.dirname
16 , basename = path.basename

new ViewTj Holowaychukbefore adoptione1da383

line 17why, one step back
17 , extname = path.extname

added index lookup support backTj Holowaychukbefore adoption041974e

line 18why, one step back
18 , exists = path.existsSync

new ViewTj Holowaychukbefore adoptione1da383

lines 19–29why, one step back
19 , 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 back
30 * 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 back
36 * @param {String} name
37 * @param {Object} options

docsTj Holowaychukbefore adoption7369d86

line 38why, one step back
38 * @api private

new ViewTj Holowaychukbefore adoptione1da383

lines 39–43why, one step back
39 */
4041function View(name, options) {42 options = options || {};43 this.name = name;

added index lookup support backTj Holowaychukbefore adoption041974e

line 44why, one step back
44 this.root = options.root;

new ViewTj Holowaychukbefore adoptione1da383

lines 45–46why, one step back
45 var engines = options.engines;
46 this.defaultEngine = options.defaultEngine;

misc refactoringTj Holowaychukbefore adoption705cdb6

line 47why, one step back
47 var ext = this.ext = extname(name);

map register functionTj Holowaychukbefore adoption02f48aa

line 48why, one step back
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);

added index lookup support backTj Holowaychukbefore adoption041974e

line 50why, one step back
50 this.path = this.lookup(name);

new ViewTj Holowaychukbefore adoptione1da383

line 51why, one step back
51}

View#contents()Tj Holowaychukbefore adoption6d47011

lines 52–53why, one step back
52
53/**

docsTj Holowaychukbefore adoption90fc80f

lines 54–61why, one step back
54 * 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 back
62 var ext = this.ext;

more refactoringTj Holowaychukbefore adoption371b381

line 63why, one step back
63

added index lookup support backTj Holowaychukbefore adoption041974e

line 64why, one step back
64 // <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);

added index lookup support backTj Holowaychukbefore adoption041974e

lines 66–68why, one step back
66 if (exists(path)) return path;
6768 // <path>/index.<engine>

more refactoringTj Holowaychukbefore adoption371b381

line 69why, one step back
69 path = join(dirname(path), basename(path, ext), 'index' + ext);

added index lookup support backTj Holowaychukbefore adoption041974e

lines 70–71why, one step back
70 if (exists(path)) return path;
71};

docsTj Holowaychukbefore adoption7369d86

lines 72–79why, one step back
72
73/**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 back
80
81View.prototype.render = function(options, fn){

Merge branch 'view-signature'Tj Holowaychukbefore adoption2d77279

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

new ViewTj Holowaychukbefore adoptione1da383

line 83why, one step back
83};