diff options
Diffstat (limited to 'askama_derive/src')
-rw-r--r-- | askama_derive/src/generator.rs | 16 | ||||
-rw-r--r-- | askama_derive/src/parser.rs | 33 |
2 files changed, 29 insertions, 20 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index edde3fe..f055cb7 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -129,7 +129,7 @@ impl<'a> Generator<'a> { if name == "format" { self.write("format!("); } else { - self.write(&format!("askama::filters::{}(&", name)); + self.write(&format!("::askama::filters::{}(&", name)); } for (i, arg) in args.iter().enumerate() { @@ -274,7 +274,7 @@ impl<'a> Generator<'a> { ws2: &WS) { self.writeln("#[allow(unused_variables)]"); self.writeln(&format!( - "fn render_block_{}_to(&self, writer: &mut std::fmt::Write) {{", + "fn render_block_{}_to(&self, writer: &mut ::std::fmt::Write) {{", name)); self.prepare_ws(ws1); self.handle(nodes); @@ -351,7 +351,7 @@ impl<'a> Generator<'a> { let name = if let Some(suffix) = trait_suffix { format!("TraitFrom{}", suffix) } else { - "askama::Template".to_string() + "::askama::Template".to_string() }; self.writeln(&format!("impl{} {} for {}{}{} {{", full_anno.as_str(), &name, ast.ident.as_ref(), @@ -360,7 +360,7 @@ impl<'a> Generator<'a> { fn impl_template(&mut self, ast: &syn::DeriveInput, nodes: &'a [Node]) { self.write_header(ast, None); - self.writeln("fn render_to(&self, writer: &mut std::fmt::Write) {"); + self.writeln("fn render_to(&self, writer: &mut ::std::fmt::Write) {"); self.handle(nodes); self.flush_ws(&WS(false, false)); self.writeln("}"); @@ -375,7 +375,7 @@ impl<'a> Generator<'a> { self.writeln("#[allow(unused_variables)]"); let trait_name = format!("TraitFrom{}", path_as_identifier(base)); self.writeln(&format!( - "fn render_trait_to(&self, timpl: &{}, writer: &mut std::fmt::Write) {{", + "fn render_trait_to(&self, timpl: &{}, writer: &mut ::std::fmt::Write) {{", trait_name)); if let Some(nodes) = nodes { @@ -392,7 +392,7 @@ impl<'a> Generator<'a> { fn impl_template_for_trait(&mut self, ast: &syn::DeriveInput, derived: bool) { self.write_header(ast, None); - self.writeln("fn render_to(&self, writer: &mut std::fmt::Write) {"); + self.writeln("fn render_to(&self, writer: &mut ::std::fmt::Write) {"); if derived { self.writeln("self._parent.render_trait_to(self, writer);"); } else { @@ -408,11 +408,11 @@ impl<'a> Generator<'a> { for bname in block_names { self.writeln(&format!( - "fn render_block_{}_to(&self, writer: &mut std::fmt::Write);", + "fn render_block_{}_to(&self, writer: &mut ::std::fmt::Write);", bname)); } self.writeln(&format!( - "fn render_trait_to(&self, timpl: &{}, writer: &mut std::fmt::Write);", + "fn render_trait_to(&self, timpl: &{}, writer: &mut ::std::fmt::Write);", trait_name)); self.writeln("}"); diff --git a/askama_derive/src/parser.rs b/askama_derive/src/parser.rs index 74140bf..61ccb09 100644 --- a/askama_derive/src/parser.rs +++ b/askama_derive/src/parser.rs @@ -156,18 +156,27 @@ named!(expr_single<Expr>, alt!( expr_group )); -named!(expr_attr<Expr>, alt!( - do_parse!( - obj: expr_single >> - tag_s!(".") >> - attr: identifier >> - args: arguments >> - (if args.is_some() { - Expr::Call(Box::new(obj), attr, args.unwrap()) - } else { - Expr::Attr(Box::new(obj), attr) - }) - ) | expr_single +named!(attr<(&str, Option<Vec<Expr>>)>, do_parse!( + tag_s!(".") >> + attr: identifier >> + args: arguments >> + (attr, args) +)); + +named!(expr_attr<Expr>, do_parse!( + obj: expr_single >> + attrs: many0!(attr) >> + ({ + let mut res = obj; + for (aname, args) in attrs { + res = if args.is_some() { + Expr::Call(Box::new(res), aname, args.unwrap()) + } else { + Expr::Attr(Box::new(res), aname) + }; + } + res + }) )); named!(filter<(&str, Option<Vec<Expr>>)>, do_parse!( |