diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-08 12:13:57 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-08 12:14:22 +0200 |
commit | b3b9849f7e035337aa8beed6b6843a3ee8eb1812 (patch) | |
tree | 25d3af94056c7e0ce02ceb0587cb5f2dea957e51 /askama_derive | |
parent | ed2fd2b1053fac08bc2e4fa4a6de2d79c136d636 (diff) | |
download | askama-b3b9849f7e035337aa8beed6b6843a3ee8eb1812.tar.gz askama-b3b9849f7e035337aa8beed6b6843a3ee8eb1812.tar.bz2 askama-b3b9849f7e035337aa8beed6b6843a3ee8eb1812.zip |
Simplify write_header() method by taking trait name directly
Diffstat (limited to 'askama_derive')
-rw-r--r-- | askama_derive/src/generator.rs | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 16d7c9e..b8176d3 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -334,8 +334,7 @@ impl<'a> Generator<'a> { } } - fn write_header(&mut self, ast: &syn::DeriveInput, - trait_suffix: Option<&str>) { + fn write_header(&mut self, ast: &syn::DeriveInput, target: &str) { let mut full_anno = Tokens::new(); let mut orig_anno = Tokens::new(); let need_anno = ast.generics.lifetimes.len() > 0 || @@ -375,18 +374,13 @@ impl<'a> Generator<'a> { let mut where_clause = Tokens::new(); ast.generics.where_clause.to_tokens(&mut where_clause); - let name = if let Some(suffix) = trait_suffix { - format!("TraitFrom{}", suffix) - } else { - "::askama::Template".to_string() - }; self.writeln(&format!("impl{} {} for {}{}{} {{", - full_anno.as_str(), &name, ast.ident.as_ref(), + full_anno.as_str(), target, ast.ident.as_ref(), orig_anno.as_str(), where_clause.as_str())); } fn impl_template(&mut self, ast: &syn::DeriveInput, nodes: &'a [Node]) { - self.write_header(ast, None); + self.write_header(ast, "::askama::Template"); self.writeln("fn render_to(&self, writer: &mut ::std::fmt::Write) {"); self.handle(nodes); self.flush_ws(&WS(false, false)); @@ -396,11 +390,11 @@ impl<'a> Generator<'a> { fn impl_trait(&mut self, ast: &syn::DeriveInput, base: &str, blocks: &'a [Node], nodes: Option<&'a [Node]>) { - self.write_header(ast, Some(&path_as_identifier(base))); + let trait_name = format!("TraitFrom{}", path_as_identifier(base)); + self.write_header(ast, &trait_name); self.handle(blocks); 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) {{", trait_name)); @@ -418,7 +412,7 @@ impl<'a> Generator<'a> { } fn impl_template_for_trait(&mut self, ast: &syn::DeriveInput, derived: bool) { - self.write_header(ast, None); + self.write_header(ast, "::askama::Template"); self.writeln("fn render_to(&self, writer: &mut ::std::fmt::Write) {"); if derived { self.writeln("self._parent.render_trait_to(self, writer);"); |