diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-06-15 22:23:26 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-06-15 22:23:26 +0200 |
commit | 305ce1dd38692285e79eeacacbc9514d1df4055b (patch) | |
tree | 64531b0feba75d551fb695f267c6baeb47594b8b /askama_derive/src/generator.rs | |
parent | 79c187870c41f3a20ac940873730451f293f3aec (diff) | |
download | askama-305ce1dd38692285e79eeacacbc9514d1df4055b.tar.gz askama-305ce1dd38692285e79eeacacbc9514d1df4055b.tar.bz2 askama-305ce1dd38692285e79eeacacbc9514d1df4055b.zip |
Explicitly keep track of sources and ASTs
Diffstat (limited to 'askama_derive/src/generator.rs')
-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, |