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

Control over indentation with the |json filter #192

Closed
antifuchs opened this issue Jan 7, 2019 · 6 comments
Closed

Control over indentation with the |json filter #192

antifuchs opened this issue Jan 7, 2019 · 6 comments

Comments

@antifuchs
Copy link

antifuchs commented Jan 7, 2019

Hi there, I use askama to great effect with the cargo-template-ci crate (to create yaml for various CI services), and have run into a little weirdness - it's not a blocker, but my aesthetics still feel like this could be better.

When I use the something|json filter, the output is indented JSON - that works OK in yaml for me, but it looks really weird - I'd much prefer if the JSON output was just a single line, rather than (legally but weirdly) outdented yaml.

Can the filter function be configured to do that?

@djc
Copy link
Collaborator

djc commented Jan 7, 2019

It cannot, but you can define user-defined filters, which sounds like a good fit for your particular issue?

There's a little bit of documentation about the feature here:

https://docs.rs/askama/0.7.2/askama/#filters

@antifuchs
Copy link
Author

That sounds good - I just reviewed the json filter, and it looks like I could relatively easily make a non-pretty JSON filter (or a YAML filter, but I guess I'd need indentation info from the caller of the filter) (:

@djc
Copy link
Collaborator

djc commented Jan 7, 2019

To answer your question more directly: no, you cannot, but based on this single request I don't think I want to change stuff built-in to Askama if the user-defined filter provides good (possibly better? -- you can do an actual YAML filter) cover for your needs.

Also I'd be okay with having an optional yaml filter included, BTW.

@djc
Copy link
Collaborator

djc commented Jan 17, 2019

Closing this for now, since it looks like your problem has been solved!

@djc
Copy link
Collaborator

djc commented Jan 17, 2019

(Just to make it better, the next release will feature an optional yaml filter, see #201.)

@asf-stripe
Copy link

Thanks, this is great!

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

No branches or pull requests

3 participants