diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-05-21 16:26:03 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-05-21 16:26:03 +0200 |
commit | 44ce96e6fc9e0dee17aa5bba169c6d2217f94fb1 (patch) | |
tree | 182829550b5c5e6ffe4d300224f661fff6373cdf /askama_derive/src | |
parent | 460db851543fdbd5777425f1c7aa06bb27e0c6c8 (diff) | |
download | askama-44ce96e6fc9e0dee17aa5bba169c6d2217f94fb1.tar.gz askama-44ce96e6fc9e0dee17aa5bba169c6d2217f94fb1.tar.bz2 askama-44ce96e6fc9e0dee17aa5bba169c6d2217f94fb1.zip |
Warn about blocks that are nested inside something other than blocks
Diffstat (limited to 'askama_derive/src')
-rw-r--r-- | askama_derive/src/generator.rs | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 1fa38b2..1233f36 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -361,6 +361,10 @@ impl<'a> Generator<'a> { self.write_loop(state, ws1, var, iter, body, ws2); }, Node::BlockDef(ref ws1, name, _, ref ws2) => { + if let AstLevel::Nested = level { + panic!("blocks ('{}') are only allowed at the top level of a template \ + or another block", name); + } self.write_block(ws1, name, ws2); }, Node::Include(ref ws, path) => { @@ -405,7 +409,7 @@ impl<'a> Generator<'a> { self.prepare_ws(ws1); self.locals.push(); - self.handle(state, nodes, AstLevel::Nested); + self.handle(state, nodes, AstLevel::Block); self.locals.pop(); self.flush_ws(ws2); @@ -970,6 +974,7 @@ impl<'a, T: 'a> SetChain<'a, T> where T: cmp::Eq + hash::Hash { #[derive(Clone)] enum AstLevel { Top, + Block, Nested, } |