aboutsummaryrefslogtreecommitdiffstats
path: root/askama_shared/src/generator.rs
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-09-05 19:54:15 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-09-05 19:54:15 +0200
commitb65d6c07bd028a4f25912b407c8e91bffd0196d2 (patch)
tree4e3d29d4b0556e51a7c9d6a36edda4109b606992 /askama_shared/src/generator.rs
parent6911e1d86caa9fa87457f99b76eb456cb6fd394c (diff)
downloadaskama-b65d6c07bd028a4f25912b407c8e91bffd0196d2.tar.gz
askama-b65d6c07bd028a4f25912b407c8e91bffd0196d2.tar.bz2
askama-b65d6c07bd028a4f25912b407c8e91bffd0196d2.zip
Refactor handling of macros
Diffstat (limited to 'askama_shared/src/generator.rs')
-rw-r--r--askama_shared/src/generator.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs
index 3194cd9..b4be517 100644
--- a/askama_shared/src/generator.rs
+++ b/askama_shared/src/generator.rs
@@ -1,5 +1,5 @@
use filters;
-use parser::{self, Cond, Expr, Node, Target, WS};
+use parser::{self, Cond, Expr, Macro, Node, Target, WS};
use path;
use quote::{Tokens, ToTokens};
@@ -27,8 +27,8 @@ pub fn generate(ast: &syn::DeriveInput, path: &Path, mut nodes: Vec<Node>) -> St
blocks.push(n);
content.push(Node::Block(ws1, name, ws2));
},
- Node::Macro(ws1, name, params, contents, ws2) => {
- macros.insert(name, (ws1, name, params, contents, ws2));
+ Node::Macro(name, m) => {
+ macros.insert(name, m);
},
_ => { content.push(n); },
}
@@ -372,20 +372,20 @@ impl<'a> Generator<'a> {
}
fn write_call(&mut self, ws: &WS, name: &str, args: &[Expr]) {
- self.handle_ws(ws);
let def = self.macros.get(name).expect(&format!("macro '{}' not found", name));
+ self.handle_ws(ws);
self.locals.push();
self.writeln("{");
- self.prepare_ws(&def.0);
- for (i, arg) in def.2.iter().enumerate() {
+ self.prepare_ws(&def.ws1);
+ for (i, arg) in def.args.iter().enumerate() {
self.write(&format!("let {} = &", arg));
self.locals.insert(arg);
- self.visit_expr(&args.get(i)
+ self.visit_expr(args.get(i)
.expect(&format!("macro '{}' takes more than {} arguments", name, i)));
self.writeln(";");
}
- self.handle(&def.3);
- self.flush_ws(&def.4);
+ self.handle(&def.nodes);
+ self.flush_ws(&def.ws2);
self.writeln("}");
self.locals.pop();
}
@@ -527,7 +527,7 @@ impl<'a> Generator<'a> {
self.handle_include(ws, path);
},
Node::Call(ref ws, name, ref args) => self.write_call(ws, name, args),
- Node::Macro(_, _, _, _, _) |
+ Node::Macro(_, _) |
Node::Extends(_) => {
panic!("no extends or macros allowed in content");
},
@@ -757,4 +757,4 @@ enum DisplayWrap {
Unwrapped,
}
-type MacroMap<'a> = HashMap<&'a str, (WS, &'a str, Vec<&'a str>, Vec<Node<'a>>, WS)>;
+type MacroMap<'a> = HashMap<&'a str, Macro<'a>>;