Add support for let blocks#697
Conversation
493051e to
dfb5add
Compare
|
I tried to simplify the implementation a bit by shadowing |
|
Oh nice! I'll try to take a look this evening. |
|
It's not only the whitespace handling from what I can see. For example: #[derive(Template)]
#[template(source = r#"aa {%- set navigation -%}
{{b}}: c {%- endset -%}
{{ navigation }}"#, ext = "txt")]
struct Foo {
b: u32,
}
fn main() {
assert_eq!(Foo { b: 0 }.render().unwrap(), "0: c");
}Outputs __askama_writer.write_str("aa")?;
let navigation = {
let mut __askama_writer = askama::helpers::alloc::string::String::new();
let _ = __askama_writer.try_reserve(6usize);
{
let __askama_writer = &mut __askama_writer;
match (
&((&&askama::filters::AutoEscaper::new(
&(self.b),
askama::filters::Text,
))
.askama_auto_escape()?),
) {
(__askama_expr0,) => {
(&&&askama::filters::Writable(__askama_expr0))
.askama_write(__askama_writer, __askama_values)?;
}
}
}
__askama_writer
}There no |
dfb5add to
7e04b5b
Compare
|
Fixed merge conflicts while I was at it. @Kijewski: I'm not sure if it's possible to not have a sub-level (doesn't need to be a full closure like now though). However your proposal is very incomplete for now as it skips big chunks of the let block. Which is good for performance but not if you want the full let block (sorry, I laughed while thinking that so I wrote it 🤣 There is nothing more behind it, I'm curious about your experiment if it can lead to a better generated code that what I produce with this PR). |
Kijewski
left a comment
There was a problem hiding this comment.
For now, the change obviously does what it is supposed to do. 👍
If I find the time, I'll have a look how handle_ws() + write_buf_writable() actually work, because I'm not sure I understand what is going on. Whenever I try to use them, it does not work. But if copy and alter existing code, then it does. Spooky. :)
|
Dark magic. =D Well, merging for now. Can be improved in follow-ups. |
Fixes #511.