From fe00fabd5c45fae4c6049bc4762d1fae7463a42e Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Sat, 11 Mar 2017 22:24:00 +0100 Subject: Reference askama and std from the global scope (fixes #17) With this change, importing `std` and `askama` into modules where templates are defined is no longer necessary. `askama::Template` must still be imported in scopes where methods of the `Template` trait are called. --- askama_derive/src/generator.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'askama_derive') 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("}"); -- cgit From 1d798e4a489709e3fa1603d8af9fb3c48de0d87e Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Sun, 12 Mar 2017 20:55:15 +0100 Subject: Bump version to 0.3.2 --- askama_derive/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'askama_derive') diff --git a/askama_derive/Cargo.toml b/askama_derive/Cargo.toml index 3f17f40..885b11a 100644 --- a/askama_derive/Cargo.toml +++ b/askama_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "askama_derive" -version = "0.3.1" +version = "0.3.2" authors = ["Dirkjan Ochtman "] description = "Procedural macro package for Askama" homepage = "https://github.com/djc/askama" -- cgit From f0efc21b3ec37160c7202b3613f68325d70b5e64 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Fri, 12 May 2017 20:31:31 +0200 Subject: Update dependencies --- askama_derive/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'askama_derive') diff --git a/askama_derive/Cargo.toml b/askama_derive/Cargo.toml index 885b11a..f916d85 100644 --- a/askama_derive/Cargo.toml +++ b/askama_derive/Cargo.toml @@ -12,6 +12,6 @@ workspace = ".." proc-macro = true [dependencies] -nom = "2.1" +nom = "3" syn = "0.11" quote = "0.3" -- cgit From 71d99927a63bc406023484ab21f885cd985c9a88 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Fri, 26 May 2017 11:45:01 +0200 Subject: Add support for chained attributes (fixes #22) --- askama_derive/src/parser.rs | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'askama_derive') diff --git a/askama_derive/src/parser.rs b/askama_derive/src/parser.rs index ce13add..9a9c89e 100644 --- a/askama_derive/src/parser.rs +++ b/askama_derive/src/parser.rs @@ -141,18 +141,27 @@ named!(expr_single, alt!( expr_group )); -named!(expr_attr, 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>)>, do_parse!( + tag_s!(".") >> + attr: identifier >> + args: arguments >> + (attr, args) +)); + +named!(expr_attr, 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>)>, do_parse!( -- cgit