jstransformers / jstransformer-pug

Pug support for JSTransformers
http://npm.im/jstransformer-pug
MIT License
6 stars 1 forks source link

Pug expects filename to be set for relative extends and includes #5

Closed ismay closed 5 years ago

ismay commented 5 years ago

In metalsmith-in-place I'm using jstransformer's .render to render templates (here). As I understand it, that means that for pug this'll use the compile export. But the exported compile from this lib only accepts a source and options param. Whereas in the .render docs it refers to accepting string, options and locals.

In locals I'm passing an object with a filename property, but since that parameter isn't used, compiling with pug fails. To me it makes sense to pass this in locals though (as it's info related to the file being processing, and not a general engine setting). Would it be possible to address this issue?

See: https://github.com/metalsmith/metalsmith-in-place/issues/158

jmatsushita commented 5 years ago

Also came across this limitation. 👍

ismay commented 5 years ago

@RobLoach I guess it depends on the underlying library where the filename property is expected to be (if the transformer needs it, and some call it path)? As in, either in locals or engineOptions?

Because I could of course manually add it, but since the goal of jstransformers is to standardize the api of all these transforms, maybe it'd be good to come up with something that works similarly across all jstransformers.

ForbesLindesay commented 5 years ago

It should be passed in options not locals. The locals are for variables local to the current render. options are for the current file. A template gets compiled once with a set of options and can then be rendered multiple times with different locals. This is for building dynamic applications, so that the template can be compiled only once.