diff options
author | bott <mhpoin@gmail.com> | 2018-09-02 18:46:45 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-09-02 19:02:22 +0200 |
commit | dfb7cea03794ead892527e19f883dc8a3e784bc7 (patch) | |
tree | 0e36679782e5ac02be167a78b67d8a90ce65644b | |
parent | 6aa485ec0892125e9b67085afb400bc9e27e6a8d (diff) | |
download | askama-dfb7cea03794ead892527e19f883dc8a3e784bc7.tar.gz askama-dfb7cea03794ead892527e19f883dc8a3e784bc7.tar.bz2 askama-dfb7cea03794ead892527e19f883dc8a3e784bc7.zip |
Fix multiple nesting in macro calls into different scopes
Diffstat (limited to '')
-rw-r--r-- | askama_derive/src/generator.rs | 8 | ||||
-rw-r--r-- | testing/templates/nested-macro.html | 8 |
2 files changed, 11 insertions, 5 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index b771234..81c0e27 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -427,13 +427,15 @@ impl<'a> Generator<'a> { return; } - let def = if let Some(s) = match scope { + let own_scope = match scope { None => match level { AstLevel::Nested(s) => s, _ => None, }, s => s, - } { + }; + + let def = if let Some(s) = own_scope { let path = ctx .imports .get(s) @@ -464,7 +466,7 @@ impl<'a> Generator<'a> { buf.writeln(&format!("let {} = &{};", arg, expr_code)); self.locals.insert(arg); } - self.handle(ctx, &def.nodes, buf, AstLevel::Nested(scope)); + self.handle(ctx, &def.nodes, buf, AstLevel::Nested(own_scope)); self.flush_ws(buf, def.ws2); buf.writeln("}"); diff --git a/testing/templates/nested-macro.html b/testing/templates/nested-macro.html index 4a40cd9..5030d59 100644 --- a/testing/templates/nested-macro.html +++ b/testing/templates/nested-macro.html @@ -1,7 +1,11 @@ -{%- macro child() -%} +{%- macro child0() -%} foo {%- endmacro -%} +{%- macro child1() -%} + {% call child0() %} +{%- endmacro -%} + {%- macro parent() -%} - {% call child() %} + {% call child1() %} {%- endmacro -%} |