From 44ce96e6fc9e0dee17aa5bba169c6d2217f94fb1 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 21 May 2018 16:26:03 +0200 Subject: Warn about blocks that are nested inside something other than blocks --- askama_derive/src/generator.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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, } -- cgit