diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-03-11 22:24:00 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-03-11 22:24:00 +0100 |
commit | fe00fabd5c45fae4c6049bc4762d1fae7463a42e (patch) | |
tree | 647fb2abfcc4a8766e8823a5b407be006c2943e0 | |
parent | bedc16cbe3c6938180f53ddfc781333a2ece52ee (diff) | |
download | askama-fe00fabd5c45fae4c6049bc4762d1fae7463a42e.tar.gz askama-fe00fabd5c45fae4c6049bc4762d1fae7463a42e.tar.bz2 askama-fe00fabd5c45fae4c6049bc4762d1fae7463a42e.zip |
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.
-rw-r--r-- | askama_derive/src/generator.rs | 16 |
1 files changed, 8 insertions, 8 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("}"); |