sindresorhus / gulp-nunjucks

Precompile Nunjucks templates
MIT License
152 stars 20 forks source link

pass opts to Environment constructor #10

Closed mstllc closed 8 years ago

mstllc commented 8 years ago

Wanted to modify some of the nunjucks Environment opts. Was thinking this was a quick fix instead of needing to create and pass in a new Environment instance as options.env.

sindresorhus commented 8 years ago

What kind of options? Can you link to the docs?

mstllc commented 8 years ago

Sure. There are only a few options you can pass to the constructor, I was most interested in trimBlocks which removes trailing newlines from blocks and tags.

https://mozilla.github.io/nunjucks/api.html#constructor (second paragraph down)

They way you have gulp-nunjucks setup now, I would need to construct a new instance of Nunjucks.Environment, setting those options I want to override, and pass that as options.env.

sindresorhus commented 8 years ago

Alright. Can you document that docs are passed into the environment too and link to the docs (same link as above)?

mstllc commented 8 years ago

This makes the most sense to me, removing options.env all together and just passing the options hash straight to the constructor. I can't find any reason why someone would need to pass an entire custom Nunjucks Environment, other than to modify the default options, which this allows them to do.

Does it make sense to you?

EDIT: let me fix that test quick.

mstllc commented 8 years ago

While updating the test, I realized why you had the option for passing a custom environment object as options.env. This pull request leaves that untouched, but passes the options hash straight through to the environment constructor if there is no options.env supplied. I've update the README to reflect that, and added a test for supplying environment constructor options.

Sorry for that confusion, let me know if this makes sense.