Skip to content
Myr

Merge branch 'view-index'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parents 0935932, a54e596 · Browse files · 13 files+62 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

13 files+62 added−14 removed

  • tests:+1 added−1 removed
  • other:+61 added−13 removed

13 files+62 added−14 removed

deleted:examples/ejs/views/user/_user.ejs-1 removed
1<li><%= user.name %> &lt;<%= user.email %>&gt;</li>
deleted:examples/ejs/views/user/list.ejs-3 removed
1<ul id="users">2 <%- partial('user', users) %>3</ul>
added:examples/ejs/views/users/_user.ejs+1 added
1<li><%= user.name %> &lt;<%= user.email %>&gt;</li>
added:examples/ejs/views/users/index.ejs+3 added
1<ul id="users">2 <%- partial('user', users) %>3</ul>
modified:examples/ejs/app.js+1 added-1 removed
deleted:examples/jade/views/user/_user.jade-3 removed
1.user2 h2= user.name3 .email= user.email
deleted:examples/jade/views/user/list.jade-3 removed
1- if (users.length)2 h1 Users3 #users!= partial('user', users)
added:examples/jade/views/users/_user.jade+3 added
1.user2 h2= user.name3 .email= user.email
added:examples/jade/views/users/index.jade+3 added
1- if (users.length)2 h1 Users3 #users!= partial('user', users)
modified:examples/jade/app.js+1 added-1 removed
35 unmodified lines
36 , { name: 'aaron', email: 'aaron.heckmann+github@gmail.com' }37];3839app.get('/', function(req, res){40 res.render('user/list', { users: users });40 res.render('users', { users: users });41});4243app.listen(3000);44console.log('Express app started on port 3000');
modified:lib/express/view/view.js+42 added-1 removed
11 unmodified lines
12var utils = require('../utils')13 , extname = utils.extname14 , dirname = utils.dirname15 , basename = utils.basename16 , fs = require('fs');16 , fs = require('fs')17 , stat = fs.statSync;1819/**20 * Memory cache.21 */2223var cache = {};2425/**26 * Existance cache.27 */2829var exists = {};3031/**32 * Initialize a new `View` with the given `view` path and `options`.33 *34 * @param {String} view35 * @param {Object} options
15 unmodified lines
51 this.dirname = dirname(this.path);52};5354/**55 * Check if the view path exists.56 *57 * @return {Boolean}58 * @api public59 */6061View.prototype.__defineGetter__('exists', function(){62 var path = this.path;63 if (null != exists[path]) {64 return exists[path];65 } else {66 try {67 stat(path);68 return exists[path] = true;69 } catch (err) {70 return exists[path] = false;71 }72 }73});7475/**76 * Resolve view engine.77 *78 * @return {String}79 * @api private
54 unmodified lines
134 return cache[ext] || (cache[ext] = require(this.engine));135});136137/**138 * Return index path alternative.139 *140 * @return {String}141 * @api public142 */143144View.prototype.__defineGetter__('indexPath', function(){145 return this.dirname146 + '/' + this.basename.replace(this.extension, '')147 + '/index' + this.extension;148});149150/**151 * Register the given template engine `exports`152 * as `ext`. For example we may wish to map ".html"153 * files to jade:154 *
27 unmodified lines
modified:lib/express/view.js+7 added
196 unmodified lines
197 view = partial198 ? new Partial(view, options)199 : new View(view, options);200201 // Ensure view exists, otherwise try index202 if (!view.exists) {203 view = partial204 ? new Partial(view.indexPath, options)205 : new View(view.indexPath, options);206 }207208 // Dynamic helper support209 if (false !== options.dynamicHelpers) {210 // cache211 if (!this.__dynamicHelpers) {
55 unmodified lines
modified:test/view.test.js+1 added-1 removed
269 unmodified lines
270 assert.response(app,271 { url: '/nope' },272 function(res){273 assert.ok(res.body.indexOf('Error: ENOENT') >= 0);274 assert.ok(res.body.indexOf('nope.jade') >= 0);274 assert.ok(res.body.indexOf('nope/index.jade') >= 0);275 });276277 beforeExit(function(){278 assert.ok(called, 'Layout callback never called');
492 unmodified lines