Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options for Engines #3114

Open
wants to merge 2 commits into
base: 5.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
* Added options object to engines
* Added option to skip filesystem checks
  • Loading branch information
Maya committed Oct 27, 2016
commit 6c22283e097adebd9f37fffb93ec9c87000ac681
2 changes: 1 addition & 1 deletion examples/view-constructor/github-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = GithubView;
function GithubView(name, options){
this.name = name;
options = options || {};
this.engine = options.engines[extname(name)];
this.engine = options.engines[extname(name)].callback;
// "root" is the app.set('views') setting, however
// in your own implementation you could ignore this
this.path = '/' + options.root + '/master/' + name;
Expand Down
8 changes: 6 additions & 2 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ app.route = function route(path) {
* @public
*/

app.engine = function engine(ext, fn) {
app.engine = function engine(ext, fn, options) {
if (typeof fn !== 'function') {
throw new Error('callback function required');
}
Expand All @@ -296,7 +296,10 @@ app.engine = function engine(ext, fn) {
: ext;

// store engine
this.engines[extension] = fn;
this.engines[extension] = {
callback: fn,
options: options || this.get('view engine options') || {}
};

return this;
};
Expand Down Expand Up @@ -554,6 +557,7 @@ app.render = function render(name, options, callback) {

view = new View(name, {
defaultEngine: this.get('view engine'),
defaultEngineOptions: this.get('view engine options') || {},
root: this.get('views'),
engines: engines
});
Expand Down
11 changes: 8 additions & 3 deletions lib/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function View(name, options) {
var opts = options || {};

this.defaultEngine = opts.defaultEngine;
this.defaultEngineOptions = opts.defaultEngineOptions;
this.ext = extname(name);
this.name = name;
this.root = opts.root;
Expand All @@ -75,14 +76,18 @@ function View(name, options) {

if (!opts.engines[this.ext]) {
// load engine
opts.engines[this.ext] = require(this.ext.substr(1)).__express;
opts.engines[this.ext] = {
callback: require(this.ext.substr(1)).__express,
options: this.defaultEngineOptions
};
}

// store loaded engine
this.engine = opts.engines[this.ext];
var engine = opts.engines[this.ext];
this.engine = engine.callback;

// lookup path
this.path = this.lookup(fileName);
this.path = engine.options.noFileSystem ? name : this.lookup(fileName);
}

/**
Expand Down