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

Accept a function as options.name

Open wiggisser opened this issue 5 years ago • 5 comments

Accept a function as options.name to be able to specify the templates name based on the name of the input file

wiggisser avatar May 09 '19 11:05 wiggisser

The type definitions should also be updated, but you no longer can directly extend Pug's options because on the pug side, name must be a string. You can leave it to me if you are not familiar with Typescript, I'll fix it before merging.

demurgos avatar May 09 '19 12:05 demurgos

fixes #192

wiggisser avatar May 09 '19 15:05 wiggisser

The current code should work fine. My main issue was with the variable name, you now check its type so it's less confusing. I was expecting to avoid the temporary variable or possibly undefined options with:

if (typeof opts.name === "function") {
  const name = opts.name(...);
  compiled = pug.compileClient(contents, Object.assign({}, opts, {name}));
} else {
  compiled = pug.compileClient(contents, opts);
} 

Thanks for the PR and tests. I'll add a changelog entry, update the type definitions, documentation and rebase on top of #201. It will be published to npm soon (probably with #200).

demurgos avatar May 09 '19 15:05 demurgos

+1

Any chance this will be released/published soon?

lcavadas avatar Oct 15 '19 16:10 lcavadas

@wiggisser @lcavadas if either of you want to rebase this PR on the latest changes and update the type definitions, I'm happy to get it released.

phated avatar Jun 09 '21 04:06 phated