Skip to content
Myr

Added view resolution hints when in development

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 · parent 71e1bcd · Browse files · 3 files+27 added−5 removed
This commit

State

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

Diff stats

3 files+27 added−5 removed

  • tests:+2 added−1 removed
  • other:+25 added−4 removed

3 files+27 added−5 removed

modified:lib/http.js+5 added
81 unmodified lines
82 this.__usedRouter = true;83 return fn;84 });8586 // default development configuration87 this.configure('development', function(){88 this.enable('hints');89 });9091 // default production configuration92 this.configure('production', function(){93 this.enable('cache views');94 });
359 unmodified lines
modified:lib/view.js+20 added-4 removed
222 unmodified lines
223224 // Populate view225 var orig = view = new View(view, options);226227 // Ensure view exists, otherwise try _ prefix228 if (!view.exists) view = new View(view.prefixPath, options);227 // Try _ prefix ex: ./views/_user.jade228 if (!view.exists) view = new View(orig.prefixPath, options);229 230 // Ensure view _ prefix exists, otherwise try index230 // Try index ex: ./views/user/index.jade231 if (!view.exists) view = new View(orig.indexPath, options);232233 // Ensure view exists, or try ../index233 // Try ../name ../user from within ./user234 if (!view.exists && !options.isLayout) view = new View(orig.upIndexPath, options);235236 // Try layout relative to the "views" dir 237 if (!view.exists && options.isLayout) view = new View(orig.rootPath, options);238239 // Does not exist240 if (!view.exists) {241 var msg = 'failed to locate view "' + orig.view + '"';242 if (app.enabled('hints')) {243 console.error();244 console.error(msg + ', tried:');245 console.error(' - ' + orig.path);246 console.error(' - ' + orig.prefixPath);247 console.error(' - ' + orig.indexPath);248 if (!options.isLayout) console.error(' - ' + orig.upIndexPath);249 if (options.isLayout) console.error(' - ' + orig.rootPath);250 console.error();251 }252 throw new Error(msg);253 }254255 // Dynamic helper support256 if (false !== options.dynamicHelpers) {257 // cache258 if (!this.__dynamicHelpers) {
54 unmodified lines
modified:test/view.test.js+2 added-1 removed
13 unmodified lines
14 * Create a test server with views set to ./fixtures.15 */1617var create = function(){18 process.env.NODE_ENV = 'test';19 var app = express.createServer.apply(express, arguments);20 app.set('views', __dirname + '/fixtures');21 return app;22};
242 unmodified lines
265 { body: '<foo></foo>' });266 assert.response(app,267 { url: '/nope' },268 function(res){268 assert.ok(~res.body.indexOf('Error: E'));269 assert.ok(~res.body.indexOf('Error: failed to locate view'));270 assert.ok(~res.body.indexOf('nope'));271 });272273 beforeExit(function(){
615 unmodified lines