Skip to content
Myr

added views.compile(view, cache, cid, options)

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 8636dee · Browse files · 1 file+40 added−19 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−19 removed

  • other:+40 added−19 removed

1 file+40 added−19 removed

modified:lib/view.js+40 added-19 removed
32 unmodified lines
3334exports.register = View.register;3536/**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 */4849exports.compile = function(view, cache, cid, options){50 if (cache && cid && cache[cid]) return cache[cid];5152 // lookup53 view = exports.lookup(view, options);5455 // 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 } 6263 // compile64 view.fn = view.templateEngine.compile(view.contents, options);65 cache[cid] = view;66 67 return view;68};6970/**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 lines
404 options.partial = function(path, opts){405 return renderPartial(self, path, opts, options, view);406 };407372 // 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;412380 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 } 386387 options.filename = view.path;388 view.fn = view.templateEngine.compile(view.contents, options);389 if (cacheViews) app.cache[cid] = view;390 }391413 // layout helper414 options.layout = function(path){415 layout = path;416 };
38 unmodified lines