janet-lang / spork

Various Janet utility modules - the official "Contrib" library.
MIT License
124 stars 36 forks source link

Capturing functions for the temple #186

Closed pepe closed 2 months ago

pepe commented 5 months ago

In the time of writing, when one imports temple .template, the returned environment consists of two functions: render and render-dict, which is in line with the language accent on printing to stdout. But when you do not use this approach in rendering (as the httpf module of this very library), you have to litter your code with capout calls. I used macro, which will import the library, render it, and capture the stdout, but it does not play well with flycheck lint and janet-lsp server.

I propose to have two more functions returned in the environment, analogous to the two existing ones, but returning the captured string:

I am aware of the compile function, but I really like the process of importing templates and then calling the functions.

Also, I will volunteer for the PR if the change is deemed useful.

bakpakin commented 2 months ago

Hi @pepe , this fell off my radar but seems to be a useful proposal. I would merge this if you work on this and submit a PR.

pepe commented 2 months ago

Thank you very much. I will look at it later when I get back from work.