diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-06-22 16:32:57 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-06-22 16:32:57 +0200 |
commit | 845a33d4327a2a4b59edc4af115a80ef4ca3d09c (patch) | |
tree | 5a1dd47822b0e768c7ef17da7659abc35b7fb38f /askama_derive/src/generator.rs | |
parent | 457ecee0756bd95ac1277dbe29663b2fd6d221a1 (diff) | |
download | askama-845a33d4327a2a4b59edc4af115a80ef4ca3d09c.tar.gz askama-845a33d4327a2a4b59edc4af115a80ef4ca3d09c.tar.bz2 askama-845a33d4327a2a4b59edc4af115a80ef4ca3d09c.zip |
Keep track of ancestor blocks in Heritage
Diffstat (limited to '')
-rw-r--r-- | askama_derive/src/generator.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 1a7e69f..4854c56 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -91,7 +91,8 @@ impl<'a> Generator<'a> { self.writeln("}"); self.write_header(&trait_name, None); - for (ctx, def) in heritage.blocks.values() { + for blocks in heritage.blocks.values() { + let (ctx, def) = blocks[0]; if let Node::BlockDef(ws1, name, nodes, ws2) = def { self.writeln("#[allow(unused_variables)]"); self.writeln(&format!( @@ -888,7 +889,7 @@ where struct Heritage<'a> { root: &'a Context<'a>, - blocks: HashMap<&'a str, (&'a Context<'a>, &'a Node<'a>)>, + blocks: BlockAncestry<'a>, } impl<'a> Heritage<'a> { @@ -896,17 +897,15 @@ impl<'a> Heritage<'a> { mut ctx: &'n Context<'n>, contexts: &'n HashMap<&'n PathBuf, Context<'n>>, ) -> Heritage<'n> { - let mut blocks: HashMap<_, (_, _)> = ctx.blocks + let mut blocks: BlockAncestry<'n> = ctx.blocks .iter() - .map(|(name, def)| (*name, (ctx, *def))) + .map(|(name, def)| (*name, vec![(ctx, *def)])) .collect(); while let Some(ref path) = ctx.extends { ctx = &contexts[&path]; for (name, def) in &ctx.blocks { - if !blocks.contains_key(name) { - blocks.insert(name, (ctx, def)); - } + blocks.entry(name).or_insert(vec![]).push((ctx, def)); } } @@ -930,3 +929,5 @@ enum DisplayWrap { } impl Copy for DisplayWrap {} + +type BlockAncestry<'a> = HashMap<&'a str, Vec<(&'a Context<'a>, &'a Node<'a>)>>; |