Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: interrogate templates #1

Open
nyarly opened this issue Feb 27, 2019 · 2 comments
Open

Feature request: interrogate templates #1

nyarly opened this issue Feb 27, 2019 · 2 comments

Comments

@nyarly
Copy link

nyarly commented Feb 27, 2019

One of the amazing and often overlooked benefits of a logic-less template is that the templates can be interrogated for the context variables they require, and the structure of the required context can be inferred from that.

As an example use case (in Ruby), see https://github.com/nyarly/diecut

It'd be great if Ramhorns could expose this functionality, ideally in a nicer way even than the Ruby Mustache does. As a glorious aspiration, being able to feed the inference from a template into Serde would be magic.

@maciejhirsz
Copy link
Owner

I think a useful api could be something like:

let result: Result<(), MissingFields> = tpl.check::<YourStruct>();

But a plain "give me all the fields this template requires" should be reasonable too.

@rflaperuta
Copy link

Having access to all context would be interesting in the case you want to call an "expensive" resource to load the values before processing the template.

I have a case for that, where instead of calling an API for each variable, I would be able to call the API passing a list of variables and just assemble the struct with its response...

I also see a use case in checking the MissingFields like a template validation of sorts...

@maciejhirsz maciejhirsz mentioned this issue Mar 9, 2019
2 tasks
@maciejhirsz maciejhirsz mentioned this issue Mar 17, 2020
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants