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

Fix filter block #71

Merged
merged 2 commits into from
Jul 13, 2024
Merged

Conversation

GuillaumeGomez
Copy link
Contributor

It's the last issue I encountered blocking the docs.rs migration.

So in short: we were writing all "sub instructions" (like include) in writer as usual. Except that the filter block is supposed to be applied to anything that was output inside it. To go around this problem, I simpler shadow the writer variable in a sub-block (the filter block) and then call the filters on it.

Copy link
Collaborator

@Kijewski Kijewski left a comment

Choose a reason for hiding this comment

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

First small nit-picking review. :)

@@ -39,6 39,8 @@ pub(crate) struct Generator<'a> {
buf_writable: WritableBuffer<'a>,
// Counter for write! hash named arguments
named: usize,
// Used in blocks to check if we are inside a filter block.
is_in_filter_block: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use is_in_filter_block: u32, and use = 1 and -= 1 so you don't need the prev variable.

@@ -92,6 96,7 @@ impl<'a> Generator<'a> {
-> {CRATE}::Result<()> {{",
));
buf.writeln(format_args!("use {CRATE}::filters::AutoEscape as _;"));
buf.writeln(format_args!("use std::fmt::Write;"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use use ::core::fmt::Write as _;. We already use ::core for everything that is in core. The as _ is useful not to shadow any other Writer name the user want's to use, e.g. std::io::Writer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@GuillaumeGomez
Copy link
Contributor Author

Fixed the nits.

@GuillaumeGomez GuillaumeGomez merged commit 7a78d9e into rinja-rs:master Jul 13, 2024
17 checks passed
@GuillaumeGomez GuillaumeGomez deleted the fix-filter-block branch July 13, 2024 08: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.

2 participants