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

Conversation

CanisLupusXenonis
Copy link

This is inspired by #2982. It adds an option object to engines, and adds an option for bypassing the filesystem mapping and checks done in view.js.

Alternatively, this option could be used to bypass the if (!view.path) { check in application.js:565, or even to assign view.path = name somewhere around there.

Either way, I think it'd be a good idea to have options for engines.
Put into the 5.0 branch because it's a breaking change.

* Added option to skip filesystem checks
@dougwilson
Copy link
Contributor

Can you have different view engine options for different view engines? Or do all engines ends up with the same options?

@CanisLupusXenonis
Copy link
Author

Well, if no engine options are given, it uses app.get('view engine options') or {} as a fallback.

But I've added a parameter to app.engine which lets you pass options for a specific engine.

@dougwilson
Copy link
Contributor

Ah. Can you describe this feature a bit more so I can understand it? We will also need to understand it in order to write up the documentation. Is there a use case for having many view engines use the same options?

@CanisLupusXenonis
Copy link
Author

CanisLupusXenonis commented Oct 27, 2016

Basically, this PR changes the following:

  • Store engines in objects instead of just storing the function. Might be handy in case any other data ever needs to be stored with it.
  • Add an options parameter to app.option that allows specifying options for the engine.
  • Add 'view engine options' setting for default engine parameter options.
  • Add the option "noFileSystem" to allow bypassing checks and calcs intended only for usage with filesystem engines.
  • Tests

In short, all this really does right now is add the functionality to bypass the filesystem-specific logic associated with engines, so non-filesystem engines (like ones using databases as described in the linked issue) are possible.
This is stored in a general "options" object now associated with engine instances, which can be set when using app.engine or the 'view engine options' setting. More options can thus be added trivially.
The refactoring from storing just the callback to storing an object is just to store the options object with it right now, but it might come in handy at some other point.
The default value setting probably won't see much use while 'noFileSystem' is the only option, but it'll likely be very useful once there's other options. I mainly added it for consistency and maintainability reasons - I can remove it if you prefer though.

@chances
Copy link

chances commented Mar 29, 2018

@dougwilson What's the status of this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants