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

parser: add optional {% endwhen %} #165

Merged
merged 3 commits into from
Sep 10, 2024

Conversation

Kijewski
Copy link
Collaborator

@Kijewski Kijewski commented Sep 9, 2024

I think we had the same question before in askama, but I cannot find the issue. Even though I don't use djLint or similar linters, I can see how this feature can be useful to people that do.

Resolves #163.

Cc @chrisp60.

Comment on lines 223 to 227
let comment = Comment {
ws: Ws(pws, nws),
content: "",
};
Node::Comment(WithSpan::new(comment, span))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation is kinda lazy, that I add a "virtual" comment node. But I guess it's good enough for the foreseeable future. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment on this code so future us won't wonder why there is a comment generated here. 😆

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe, yeah, makes sense to write comments in a place where you would actually find them. :D

@@ -619,6 +619,11 @@ You can also match against multiple alternative patterns at once:
{% endmatch %}
```

For better interoperability with linters and auto-formatters like [djLint],
you can also use a optional `{% endwhen %}` node to close a `{% when %}` case.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add an example?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@chrisp60
Copy link
Contributor

Thank you for putting in the work on this @Kijewski! To be honest, I am unfamiliar with nom and it seemed daunting for something that I expected to be straightforward. And thank you @GuillaumeGomez as well for being open to the change!

It is very small and insignificant for most, but every time I need to manually format something I feel it take a chunk of my soul. It is much appreciated

@GuillaumeGomez
Copy link
Contributor

Thanks @Kijewski!

@chrisp60: No problem. It's optional so it doesn't make code longer for people who aren't interested into it and for others, they can use it if they want. So everyone should be happy. :)

@GuillaumeGomez GuillaumeGomez merged commit b6a1595 into rinja-rs:master Sep 10, 2024
34 checks passed
@Kijewski Kijewski deleted the pr-endmatch branch September 10, 2024 13:36
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 this pull request may close these issues.

syntax for closing a {% when ... %} block within a match
3 participants