diff options
author | Lars Erik Rosengren <larserik.rosengren@gmail.com> | 2017-10-15 13:09:07 +0200 |
---|---|---|
committer | Lars Erik Rosengren <larserik.rosengren@gmail.com> | 2017-10-15 14:04:52 +0200 |
commit | a32532d5ae339cf3dcde1bd0b684e7bd7f8c51fc (patch) | |
tree | 3f60765d9a7d84d687e95ae100c00eb0a0a5ae84 /askama_shared/src/lib.rs | |
parent | 5333a52ca2da1a18bb856be8ef27a23c1c1543ad (diff) | |
download | askama-a32532d5ae339cf3dcde1bd0b684e7bd7f8c51fc.tar.gz askama-a32532d5ae339cf3dcde1bd0b684e7bd7f8c51fc.tar.bz2 askama-a32532d5ae339cf3dcde1bd0b684e7bd7f8c51fc.zip |
Add scope when importing macros
Diffstat (limited to 'askama_shared/src/lib.rs')
-rw-r--r-- | askama_shared/src/lib.rs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/askama_shared/src/lib.rs b/askama_shared/src/lib.rs index 4e57a82..88439dc 100644 --- a/askama_shared/src/lib.rs +++ b/askama_shared/src/lib.rs @@ -50,17 +50,17 @@ pub fn build_template(ast: &syn::DeriveInput) -> String { pub struct Imports<'a> { - pub sources: Vec<Cow<'a, str>> + pub sources: HashMap<&'a str, Cow<'a, str>> } impl <'a> Imports<'a> { pub fn new(parent_nodes: &'a [Node], parent_path: &'a Path) -> Imports<'a> { let sources = parent_nodes.iter().filter_map(|n| { match *n { - Node::Import(_, ref import_path) => { + Node::Import(_, ref import_path, scope) => { let path = path::find_template_from_path(import_path, Some(parent_path)); let src = path::get_template_source(&path); - Some(Cow::Owned(src)) + Some((scope, Cow::Owned(src))) }, _ => None, } @@ -68,15 +68,17 @@ impl <'a> Imports<'a> { Imports { sources } } - pub fn macro_map(&'a self) -> HashMap<&'a str, Macro<'a>> { - self.sources.iter() - .flat_map(|s| parser::parse(s.as_ref())) - .filter_map(|n| { + pub fn macro_map(&'a self) -> HashMap<(&'a str, &'a str), Macro<'a>> { + let mut macro_map = HashMap::new(); + for (scope, s) in self.sources.iter() { + for n in parser::parse(&s.as_ref()) { match n { - Node::Macro(name, m) => Some((name, m)), + Node::Macro(name, m) => macro_map.insert((*scope, name), m), _ => None, - }}) - .collect() + }; + } + } + macro_map } } |