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

Dump a value into YAML #423

Open
lquerel opened this issue Oct 21, 2024 · 5 comments
Open

Dump a value into YAML #423

lquerel opened this issue Oct 21, 2024 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@lquerel
Copy link
Contributor

lquerel commented Oct 21, 2024

We already have a tojson filter to output a value in JSON format, but we don’t have a filter for YAML output. Some people have expressed this need.

@jsuereth jsuereth added enhancement New feature or request good first issue Good for newcomers labels Nov 25, 2024
@unpervertedkid
Copy link
Contributor

@lquerel , can I pick this up?

@lquerel
Copy link
Contributor Author

lquerel commented Nov 25, 2024

@unpervertedkid Yes. Thank you

@unpervertedkid
Copy link
Contributor

@lquerel , for me to understand how to properly go on with this, kindly help point me on the following:

  1. An example of usage of the current tojson filter or how I can create a simple example usage to get the gist of the current implementation.
  2. I see that there is a filter in weaver_forge/src/filter.rs. Is that the toJson filter we are referring to?

If you have any other pointers in the docs or relevant information to get me started on this would be really appreciated.
Thanks.

@lquerel
Copy link
Contributor Author

lquerel commented Dec 2, 2024

@unpervertedkid You can add the toyaml filter in crates/weaver_forge/src/extensions/util.rs. The signature of the filter should be something like fn to_yaml(value: Value) -> Result<Value, minijinja::Error>. We also have to register this function in the add_filters (same file) with something like env.add_filter("toyaml", to_yaml). In the repo of minijinja there is the implementation of the tojson filter so you can probably adapt the code from there. See https://github.com/mitsuhiko/minijinja/blob/4249fb3f423eb076317db542f08a00a1fcec39c3/minijinja/src/filters.rs#L1059

You also have to add a unit test. Thanks

@unpervertedkid
Copy link
Contributor

@lquerel , is it important to preserve ordering when converting to yaml?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants