Merge branch 'refactor/views'
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 8636dee, 56ae55f · Browse files · 2 files·+44 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+44 added−20 removed
- other:+44 added−20 removed
Provenance
- Commit
09b384e- Tree
2df3616- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent 1
8636dee- Parent 2
56ae55f
2 files changed+44 added−20 removed
modified:lib/view/view.js+4 added-1 removed
47 unmodified lines48 this.extension = '.' + this.engine;49 this.name = this.basename.replace(this.extension, '');50 this.path = this.resolvePath();51 this.dirname = dirname(this.path);52- if (options.attempts) options.attempts.push(this.path);52+ if (options.attempts) {53+ if (!~options.attempts.indexOf(this.path))54+ options.attempts.push(this.path);55+ }56 };57 58 /**59 * Check if the view path exists.150 unmodified linesmodified:lib/view.js+40 added-19 removed
32 unmodified lines33 34 exports.register = View.register;35 36 /**37+ * Lookup and compile `view` with cache support by supplying38+ * both the `cache` object and `cid` string,39+ * followed by `options` passed to `exports.lookup()`.40+ *41+ * @param {String} view42+ * @param {Object} cache43+ * @param {Object} cid44+ * @param {Object} options45+ * @return {View}46+ * @api private47+ */48+49+exports.compile = function(view, cache, cid, options){50+ if (cache && cid && cache[cid]) return cache[cid];51+52+ // lookup53+ view = exports.lookup(view, options);54+55+ // hints56+ if (!view.exists) {57+ if (options.hint) hintAtViewPaths(view.original, options);58+ var err = new Error('failed to locate view "' + view.original.view + '"');59+ err.view = view.original;60+ throw err;61+ } 62+63+ // compile64+ view.fn = view.templateEngine.compile(view.contents, options);65+ cache[cid] = view;66+ 67+ return view;68+};69+70+/**71 * Lookup `view`, returning an instanceof `View`.72 *73 * Options:74 *75 * - `root` root directory path76 * - `defaultEngine` default template engine77 * - `parentView` parent `View` object78+ * - `cache` cache object79+ * - `cacheid` optional cache id80 *81 * @param {String} view82 * @param {Object} options83 * @return {View}320 unmodified lines404 options.partial = function(path, opts){405 return renderPartial(self, path, opts, options, view);406 };407 372- // cached view373- if (app.cache[cid]) {374- view = app.cache[cid];375- options.filename = view.path;376- // resolve view377- } else {378- view = exports.lookup(view, options);408+ // View lookup409+ options.hint = app.enabled('hints');410+ view = exports.compile(view, app.cache, cid, options);411+ options.filename = view.path;412 380- if (!view.exists) {381- if (app.enabled('hints')) hintAtViewPaths(view.original, options);382- var err = new Error('failed to locate view "' + view.original.view + '"');383- err.view = view.original;384- throw err;385- } 386-387- options.filename = view.path;388- view.fn = view.templateEngine.compile(view.contents, options);389- if (cacheViews) app.cache[cid] = view;390- }391-413 // layout helper414 options.layout = function(path){415 layout = path;416 };38 unmodified lines