diff options
Diffstat (limited to '')
-rw-r--r-- | askama_shared/src/generator.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index e92a2c6..e135c13 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -12,8 +12,8 @@ use std::collections::{HashMap, HashSet}; use syn; -pub fn generate(input: &TemplateInput, nodes: &[Node]) -> String { - Generator::default().build(&State::new(input, nodes)) +pub fn generate(input: &TemplateInput, nodes: &[Node], imported: &HashMap<&str, Macro>) -> String { + Generator::default().build(&State::new(input, nodes, imported)) } struct State<'a> { @@ -26,7 +26,7 @@ struct State<'a> { } impl<'a> State<'a> { - fn new<'n>(input: &'n TemplateInput, nodes: &'n [Node]) -> State<'n> { + fn new<'n>(input: &'n TemplateInput, nodes: &'n [Node], imported: &'n HashMap<&'n str, Macro<'n>>) -> State<'n> { let mut base: Option<&Expr> = None; let mut blocks = Vec::new(); let mut macros = HashMap::new(); @@ -47,6 +47,9 @@ impl<'a> State<'a> { _ => {}, } } + for (name, ref m) in imported { + macros.insert(name, m); + } State { input, nodes, @@ -351,6 +354,7 @@ impl<'a> Generator<'a> { }, Node::Call(ref ws, name, ref args) => self.write_call(state, ws, name, args), Node::Macro(_, _) | + Node::Import(_, _) | Node::Extends(_) => { if let AstLevel::Nested = level { panic!("macro or extend blocks only allowed at the top level"); |