diff options
Diffstat (limited to '')
-rw-r--r-- | askama_derive/src/generator.rs | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index c6507d4..fb529a0 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -13,10 +13,11 @@ use syn; pub fn generate(input: &TemplateInput, nodes: &[Node]) -> String { + let mut sources = HashMap::new(); + let mut parsed = HashMap::new(); let mut base = None; let mut blocks = Vec::new(); let mut imported = Vec::new(); - let mut parsed = Vec::new(); let mut macros = HashMap::new(); for n in nodes { @@ -35,13 +36,15 @@ pub fn generate(input: &TemplateInput, nodes: &[Node]) -> String { }, Node::Import(_, import_path, scope) => { let path = path::find_template_from_path(import_path, Some(&input.path)); - let src = path::get_template_source(&path); - imported.push((*scope, src)); + sources.insert(path.clone(), path::get_template_source(&path)); + imported.push((*scope, path)); } _ => {}, } } - parsed.extend(imported.iter().map(|(scope, src)| (*scope, parser::parse(&src)))); + for (path, src) in &sources { + parsed.insert(path, parser::parse(&src)); + } let mut check_nested = 0; let mut nested_blocks = Vec::new(); @@ -59,8 +62,8 @@ pub fn generate(input: &TemplateInput, nodes: &[Node]) -> String { check_nested += 1; } - for (scope, ast) in &parsed { - for n in ast { + for (scope, path) in &imported { + for n in &parsed[path] { match n { Node::Macro(name, m) => macros.insert((Some(*scope), name), &m), _ => None, |