Skip to content

Commit

Permalink
Add code comment to explain discard condition
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed May 23, 2024
1 parent 8b98e66 commit 252afe7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions askama_derive/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,16 @@ impl<'a> Generator<'a> {
if block_fragment_write {
self.buf_writable.discard = true;
}
// If previous discard value (ie, from the parent node) is different than the current one,
// then it can be only because we are only rendering a given block and the parent was not
// this block.
//
// It can only be this case because if we enter the block we want to render, its children
// will be rendered as well, meaning that this condition will never be false.
//
// Now why not call `self.write_buf_writable`? It's because of the recursion: the parent
// nodes will be stored but may not have been written into the buffer yet. So if we write
// everything right away, the rendering will be reverted: children will be generated first.
if buf.discard != prev_buf_discard {
self.write_buf_writable(buf)?;
}
Expand Down

0 comments on commit 252afe7

Please sign in to comment.