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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add do tag to allow calling functions/macros and not having output #165

Closed

Conversation

joshuataylor
Copy link
Sponsor Contributor

@joshuataylor joshuataylor commented Jan 6, 2023

Based off this conversation: #83

Happy to discuss if this should be merged. Moreover, happy for this to be tweaked/reworked to make it in the best possible state. 馃殌

I also initially named this DoBlock, but IMHO it's confusing to name that as someone might think they could use it the same way they would the call tag.

What is a do tag?

The do tag does the same thing as a using regular template tags ({{ ... }}); except it doesn't output anything.

This is useful if you have a function or macro that has verbose output or side effects, but you want to avoid displaying output.

Note: Jinja2 puts this into their extensions.

Reasoning

The reasoning for adding this is that this is super handy when working with projects that use jinja2 extensively, like dbt, where it's quite useful.

Example (from dbt-utils readme).

(I know you know most/all of this, but the explanation is for everyone else, and when I forget :D )

The do tag does the same thing as a using regular template tags (`{{ ...
}}`); except it doesn't output anything.
This is useful if you have a function or macro that has verbose output
or side effects, but you don鈥檛 want to display output.
@@ -953,7 +954,6 @@ impl<'a> Parser<'a> {
Ok(ast::FromImport { expr, names })
}

#[cfg(feature = "macros")]
Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

As functions can be called via do, this needed to be removed. Thoughts?

expect_token!(self, Token::BlockEnd(..), "end of block");

// End of block may not exist, for example with do block.
if let Some((Token::BlockEnd(..), _)) = ok!(self.stream.current()) {
Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if this is the best way to check, or would lead to user confusion.

If they are using enddo, it will error anyway.

@mitsuhiko mitsuhiko deleted the branch mitsuhiko:feature/call-block January 6, 2023 09:20
@mitsuhiko mitsuhiko closed this Jan 6, 2023
@mitsuhiko
Copy link
Owner

Ugh not sure what happened here. I did not intend on closing this.

@mitsuhiko
Copy link
Owner

Ah I see. The merge base was my now deleted call block branch so this auto closed this PR as well. Can your rebase this off main? I'm in favor of adding this.

@joshuataylor
Copy link
Sponsor Contributor Author

joshuataylor commented Jan 6, 2023

Yep, seems rebasing should be fine, just doing that now. As you said, I had based this off the other branch, where deleting it closes this. Hopefully, I can rebase and it'll work.

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.

None yet

2 participants