carlitoplatanito / gulp-nunjucks-render

[Gulp](https://github.com/wearefractal/gulp) plugin to render [Nunjucks](http://mozilla.github.io/nunjucks/) templates
149 stars 33 forks source link

Add Custom Filters #36

Closed jtini closed 8 years ago

jtini commented 8 years ago

Hi @carlosl,

Do you have any examples of a custom filters working with your module? I have been trying without much luck. It seems to be something around the nunjucks environment and getting it setup properly with your module. Love some help with the below.

var render       = require('gulp-nunjucks-render')
var env          = new render.nunjucks.Environment()

env.addFilter('log', function(str){
  console.log(str);
  return str;
});

var htmlTask = function() {
  render.nunjucks.configure([path.join(config.root.src, config.tasks.html.src)], { watch: false })

  return gulp.src(paths.src)
    .pipe(data(getData))
    .on('error', handleErrors)
    .pipe(render(null, null, env))
    .on('error', handleErrors)
    .pipe(gulpif(process.env.NODE_ENV == 'production', htmlmin(config.tasks.html.htmlmin)))
    .pipe(gulp.dest(paths.dest))
    .pipe(browserSync.stream())
}

gulp.task('html', htmlTask)

Thanks!

kristijanhusak commented 8 years ago

hi @jtini,

What exactly you want to do with the filters? Do you mean custom filters in nunjucks, or some gulp task stream filtering?

corbanb commented 8 years ago

@kristijanhusak I was working with @jtini on this also. the main goal is to add a custom nunjucks filter.

See: https://mozilla.github.io/nunjucks/api#custom-filters

I believe we should be able to do the able but I am a little unclear on if the new environment is being used for your module when we create it. Thoughts?

Thanks for getting back.

kristijanhusak commented 8 years ago

@corbanb That is not possible at this moment. I have plan for rewriting and adding that functionality, but I am not able to update npm repository until @carlosl gives me access. Will let you know when i manage to set up something.

corbanb commented 8 years ago

sooo what do we gotta do here @carlosl ? :moneybag: ? :hand: ? :facepunch: ? :)

kristijanhusak commented 8 years ago

@corbanb @jtini I done some refactoring on the fork https://github.com/kristijanhusak/gulp-nunjucks-render. It's still not published to npm, but you could give it a try. I added an option to manipulate the environment, and also did some refactoring on path setup. Check the readme and let me know how it works for u.

kamlekar commented 8 years ago

Seems like we have no other option. I hope @carlosl will respond soon. Anyway, :+1:

carlitoplatanito commented 8 years ago

Sorry guys... Feel your pain, @kristijanhusak giving you access to NPM now.

He has been a great help keeping this up-to-date as I've def been too busy to check in on it all the time, especially since I no longer use it for work. Thanks again @kristijanhusak and everybody else who's been contributing.

corbanb commented 8 years ago

@kristijanhusak and @carlosl thanks guys. I did the same thing on my end by forking. I like your implementation better and will test soon. Thanks!

kristijanhusak commented 8 years ago

thanks @carlosl . I'll merge new code from my fork and publish it as 2.0.0, because it has breaking changes.

kamlekar commented 8 years ago

:+1:

kristijanhusak commented 8 years ago

@kamlekar @corbanb I updated it to version 2.0.0. Check the readme and changelog how to update.

carlitoplatanito commented 8 years ago

Thanks @kristijanhusak !