diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2020-06-02 23:25:30 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2020-06-03 20:56:47 +0200 |
commit | 7da4ad54ebbb529c9b43ed545f0f1de8341bca50 (patch) | |
tree | 22bdbe2f60c073e6572364ff291dc1a3226ba811 | |
parent | 66dc91b1683a0da3215388239d2f2809e332624a (diff) | |
download | askama-7da4ad54ebbb529c9b43ed545f0f1de8341bca50.tar.gz askama-7da4ad54ebbb529c9b43ed545f0f1de8341bca50.tar.bz2 askama-7da4ad54ebbb529c9b43ed545f0f1de8341bca50.zip |
Allow block definitions in if/for/match blocks (fixes #335)
-rw-r--r-- | askama_shared/src/generator.rs | 10 | ||||
-rw-r--r-- | askama_shared/src/heritage.rs | 13 |
2 files changed, 14 insertions, 9 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index fe02b8a..36ac55e 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -363,15 +363,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { self.write_loop(ctx, buf, ws1, var, iter, body, ws2); } Node::BlockDef(ws1, name, _, ws2) => { - if AstLevel::Nested == level { - panic!( - "blocks ('{}') are only allowed at the top level of a template \ - or another block", - name - ); - } - let outer = WS(ws1.0, ws2.1); - self.write_block(buf, Some(name), outer); + self.write_block(buf, Some(name), WS(ws1.0, ws2.1)); } Node::Include(ws, path) => { size_hint += self.handle_include(ctx, buf, ws, path); diff --git a/askama_shared/src/heritage.rs b/askama_shared/src/heritage.rs index 86c7932..a747fcf 100644 --- a/askama_shared/src/heritage.rs +++ b/askama_shared/src/heritage.rs @@ -75,6 +75,19 @@ impl<'a> Context<'a> { nested.push(nodes); } } + Node::Cond(branches, _) => { + for (_, _, nodes) in branches { + nested.push(nodes); + } + } + Node::Loop(_, _, _, nodes, _) => { + nested.push(nodes); + } + Node::Match(_, _, _, arms, _) => { + for (_, _, _, arm) in arms { + nested.push(arm); + } + } _ => {} } } |