janet-lang / spork

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

Capturing functions for the temple #186

Open pepe opened 2 months ago

pepe commented 2 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.