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
Provenance
- Commit
3043672- Tree
51da10c- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
0477a53
1 file changed+40 added−26 removed
modified:lib/view.js+40 added-26 removed
32 unmodified lines33 34 exports.register = View.register;35 36 /**37+ * Lookup `view`, returning an instanceof `View`.38+ *39+ * @param {String} view40+ * @param {Object} options41+ * @return {View}42+ * @api private43+ */44+45+exports.lookup = function(view, options){46+ var orig = view = new View(view, options);47+48+ // Try _ prefix ex: ./views/_<name>.jade49+ if (partial) {50+ view = new View(orig.prefixPath, options);51+ if (!view.exists) view = orig;52+ }53+54+ // Try index ex: ./views/user/index.jade55+ if (!view.exists) view = new View(orig.indexPath, options);56+57+ // 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);60+61+ // Try root ex: <root>/user.jade62+ if (!view.exists) view = new View(orig.rootPath, options);63+64+ // Try root _ prefix ex: <root>/_user.jade65+ if (!view.exists && partial) view = new View(view.prefixPath, options);66+67+ view.original = orig;68+ return view;69+};70+71+/**72 * Partial render helper.73 *74 * @api private75 */292 unmodified lines368 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);373 339- // 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);347-348- // 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);351-352- // Try root ex: <root>/user.jade353- if (!view.exists) view = new View(orig.rootPath, options);354-355- // Try root _ prefix ex: <root>/_user.jade356- if (!view.exists && partial) view = new View(view.prefixPath, options);357-358- // 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 } 380 381 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 }385 386 // layout helper41 unmodified lines