rotundasoftware / nunjucksify

Everything you expect from a module named nunjucksify and more.
34 stars 10 forks source link

Adds nunjucksify.extensions to configure template file extension. #7

Closed honi closed 9 years ago

honi commented 9 years ago

I personally dislike the .nunj extension and prefer to simply use .html for the template files. When using browserify's JS API (for example in a Gulp task), you can now configure the extension with: nunjucksify.extensions = ['.html']

Added test, but no docs, since it was not clear where to add it, and not sure how you would configure this in another setup other than Gulp.

Salute!

w0rm commented 9 years ago

Hi @honi. Why not simply read extensions setting from opts? You can pass it with:

bundle.transform(nunjucksify, {env: customNunjucksEnv, extensions: ['.html']})
honi commented 9 years ago

Cool. And how do I create customNunjucksEnv? I mean, why do I need to create a custom nunjucks env if the extensions array is passed to bundle.transform?

w0rm commented 9 years ago

@honi its just an example of another setting that is already there, if you need to create custom nunjucks environment (e.g. for your custom tags), you have to use nunjucks:

var nunjucks = require( "nunjucks" );
var customNunjucksEnv = new nunjucks.Environment();

But you also will need to implement this on the front-end.

honi commented 9 years ago

That looks nice. Though this line doesn't allow it.

w0rm commented 9 years ago

Of course it doesn't, because that's how it is implemented at the moment. I only suggested to pass extensions in opts.

honi commented 9 years ago

Just checking, wasn't sure if your suggestion wasn't working for me because of that or because I did something wrong in my testing.

Your approach does look better though. Are you interested in this feature? I can update the PR to use opts.extensions instead of nunjucksify.extensions.

dgbeck commented 9 years ago

Hi @honi ! Yes please do that. I don't think it needs to be an array though. I can't see people usding more than one extension at once. Let's just add extension to the options hash (a string that defaults to .nunj).

Thanks very much for this idea and for the PR!

honi commented 9 years ago

Ups, just read your comment about extension instead of extensions. I though the same thing, but since browserify uses an array, I figured I'd follow the same style.

honi commented 9 years ago

Hi, any interest in merging this so that we can install directly from npm?

w0rm commented 9 years ago

@honi I guess its not merged because @dgbeck wants a single extension in options.

honi commented 9 years ago

Ready. I've enabled setting extension to a string or array, works both ways.

dgbeck commented 9 years ago

Done and done, and published in v0.2.0. Thanks, @honi !