Skip to content
Myr

added exports.lookup(view, options) to view.js

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

private for now

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 0477a53 · Browse files · 1 file+40 added−26 removed
This commit

State

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

Diff stats

1 file+40 added−26 removed

  • other:+40 added−26 removed

1 file+40 added−26 removed

modified:lib/view.js+40 added-26 removed
32 unmodified lines
3334exports.register = View.register;3536/**37 * Lookup `view`, returning an instanceof `View`.38 *39 * @param {String} view40 * @param {Object} options41 * @return {View}42 * @api private43 */4445exports.lookup = function(view, options){46 var orig = view = new View(view, options);4748 // Try _ prefix ex: ./views/_<name>.jade49 if (partial) {50 view = new View(orig.prefixPath, options);51 if (!view.exists) view = orig;52 }5354 // Try index ex: ./views/user/index.jade55 if (!view.exists) view = new View(orig.indexPath, options);5657 // Try ../<name>/index ex: ../user/index.jade58 // when calling partial('user') within the same dir59 if (!view.exists && !options.isLayout) view = new View(orig.upIndexPath, options);6061 // Try root ex: <root>/user.jade62 if (!view.exists) view = new View(orig.rootPath, options);6364 // Try root _ prefix ex: <root>/_user.jade65 if (!view.exists && partial) view = new View(view.prefixPath, options);6667 view.original = orig;68 return view;69};7071/**72 * Partial render helper.73 *74 * @api private75 */
292 unmodified lines
368 view = app.cache[cid];369 options.filename = view.path;370 // resolve view371 } else {337 var orig = view = new View(view, options);372 view = exports.lookup(view, options);373339 // Try _ prefix ex: ./views/_<name>.jade340 if (partial) {341 view = new View(orig.prefixPath, options);342 if (!view.exists) view = orig;343 }344 345 // Try index ex: ./views/user/index.jade346 if (!view.exists) view = new View(orig.indexPath, options);347348 // Try ../<name>/index ex: ../user/index.jade349 // when calling partial('user') within the same dir350 if (!view.exists && !options.isLayout) view = new View(orig.upIndexPath, options);351352 // Try root ex: <root>/user.jade353 if (!view.exists) view = new View(orig.rootPath, options);354355 // Try root _ prefix ex: <root>/_user.jade356 if (!view.exists && partial) view = new View(view.prefixPath, options);357358 // Does not exist374 if (!view.exists) {360 if (app.enabled('hints')) hintAtViewPaths(orig, options);361 var err = new Error('failed to locate view "' + orig.view + '"');362 err.view = orig;375 if (app.enabled('hints')) hintAtViewPaths(view.original, options);376 var err = new Error('failed to locate view "' + view.original.view + '"');377 err.view = view.original;378 throw err;379 } 380381 options.filename = view.path;367 var engine = view.templateEngine;368 view.fn = engine.compile(view.contents, options)382 view.fn = view.templateEngine.compile(view.contents, options);383 if (cacheViews) app.cache[cid] = view;384 }385386 // layout helper
41 unmodified lines