gulp-pug icon indicating copy to clipboard operation
gulp-pug copied to clipboard

Support per-file `name` option

Open wiggisser opened this issue 5 years ago • 8 comments

when using gulp pug like this

return gulp.src('./client/templates/*.pug')
      .pipe(data(function(file) {
        return {
          name: `__${path.basename(file.path, '.pug')}`
        };
      }))
      .pipe(pug({
        client: true,
        ...
      }))

the options returned from the gulp-data function are not passed through to the pug.compileClient. Especially, in my usecase, the template name is not set to the filename but to template

wiggisser avatar Feb 03 '19 10:02 wiggisser

I am doing some maintenance on the lib currently. I'll handle this issue as part of it.

demurgos avatar May 09 '19 10:05 demurgos

The gulp-data plugin is not designed for passing options through your pipeline. The way that this should probably be solved inside gulp-pug is to make the name option a string or function. If it is a function, call it for each file with the file as the only argument.

phated avatar May 09 '19 10:05 phated

I have misunderstood the issue. My understanding was that gulp-data could be used to pass the Pug locals, not the options themselves.

Agreed that per-file configuration can be achieved by accepting a function.

demurgos avatar May 09 '19 10:05 demurgos

@demurgos I had misunderstood it as well until I dug into pug's options and noticed that @wiggisser was trying to pass the name option.

phated avatar May 09 '19 10:05 phated

So, is there any possibility to derive the template name from the filename then?

wiggisser avatar May 09 '19 11:05 wiggisser

Yes

The way that this should probably be solved inside gulp-pug is to make the name option a string or function. If it is a function, call it for each file with the file as the only argument.

demurgos avatar May 09 '19 11:05 demurgos

OK. I could probably provide a pull request for that ...

wiggisser avatar May 09 '19 11:05 wiggisser

This library already supports receiving Pug locals from gulp-data. I'm renaming the issue to better reflect the actual problem.

demurgos avatar May 09 '19 15:05 demurgos