diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-08 12:17:11 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-08-08 12:17:11 +0200 |
commit | 21e5c86ea2b001906dc690f8bf5bc42decbfbce2 (patch) | |
tree | 1b09a6325be33370670bc3af90465425d5bc239e | |
parent | b3b9849f7e035337aa8beed6b6843a3ee8eb1812 (diff) | |
download | askama-21e5c86ea2b001906dc690f8bf5bc42decbfbce2.tar.gz askama-21e5c86ea2b001906dc690f8bf5bc42decbfbce2.tar.bz2 askama-21e5c86ea2b001906dc690f8bf5bc42decbfbce2.zip |
Add some comments to clarify code generator methods
-rw-r--r-- | askama_derive/src/generator.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index b8176d3..f2bb88a 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -334,6 +334,8 @@ impl<'a> Generator<'a> { } } + // Writes header for the `impl` for `TraitFromPathName` or `Template` + // for the given context struct. fn write_header(&mut self, ast: &syn::DeriveInput, target: &str) { let mut full_anno = Tokens::new(); let mut orig_anno = Tokens::new(); @@ -379,6 +381,7 @@ impl<'a> Generator<'a> { orig_anno.as_str(), where_clause.as_str())); } + // Implement `Template` for the given context struct. fn impl_template(&mut self, ast: &syn::DeriveInput, nodes: &'a [Node]) { self.write_header(ast, "::askama::Template"); self.writeln("fn render_to(&self, writer: &mut ::std::fmt::Write) {"); @@ -388,6 +391,7 @@ impl<'a> Generator<'a> { self.writeln("}"); } + // Implement `TraitFromPathName` for the given context struct. fn impl_trait(&mut self, ast: &syn::DeriveInput, base: &str, blocks: &'a [Node], nodes: Option<&'a [Node]>) { let trait_name = format!("TraitFrom{}", path_as_identifier(base)); @@ -411,6 +415,7 @@ impl<'a> Generator<'a> { self.writeln("}"); } + // Implement `Template` for templates that implement a template trait. fn impl_template_for_trait(&mut self, ast: &syn::DeriveInput, derived: bool) { self.write_header(ast, "::askama::Template"); self.writeln("fn render_to(&self, writer: &mut ::std::fmt::Write) {"); @@ -423,6 +428,7 @@ impl<'a> Generator<'a> { self.writeln("}"); } + // Defines the `TraitFromPathName` trait. fn define_trait(&mut self, path: &str, block_names: &[&str]) { let trait_name = format!("TraitFrom{}", path_as_identifier(path)); self.writeln(&format!("trait {} {{", &trait_name)); |