aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-02-05 10:11:12 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-02-05 10:11:12 +0100
commitf98b6285ba11d2d1580ff8be37d0fd7b60107733 (patch)
tree847e0947d5abcc7a8e493b74a5c55dcbdf01f063
parent07cf1d545b0a060c52b3db4a15b19cfa2dfdc713 (diff)
downloadaskama-f98b6285ba11d2d1580ff8be37d0fd7b60107733.tar.gz
askama-f98b6285ba11d2d1580ff8be37d0fd7b60107733.tar.bz2
askama-f98b6285ba11d2d1580ff8be37d0fd7b60107733.zip
Clarify code around writing template impl
Diffstat (limited to '')
-rw-r--r--askama/src/generator.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/askama/src/generator.rs b/askama/src/generator.rs
index 3c5e2a1..f262f7c 100644
--- a/askama/src/generator.rs
+++ b/askama/src/generator.rs
@@ -173,21 +173,21 @@ impl Generator {
res
}
- fn init(&mut self, name: &str, generics: &syn::Generics) {
+ fn template_impl(&mut self, ast: &syn::DeriveInput, tokens: &Vec<Node>) {
self.write("impl");
- let anno = self.annotations(generics);
+ let anno = self.annotations(&ast.generics);
self.write(&anno);
self.write(" askama::Template for ");
- self.write(name);
+ self.write(ast.ident.as_ref());
self.write(&anno);
self.writeln(" {");
self.indent();
self.writeln("fn render_into(&self, writer: &mut std::fmt::Write) {");
self.indent();
- }
- fn finalize(&mut self) {
+ self.handle(tokens);
+
self.dedent();
self.writeln("}");
self.dedent();
@@ -202,8 +202,6 @@ impl Generator {
pub fn generate(ast: &syn::DeriveInput, tokens: &Vec<Node>) -> String {
let mut gen = Generator::new();
- gen.init(ast.ident.as_ref(), &ast.generics);
- gen.handle(tokens);
- gen.finalize();
+ gen.template_impl(ast, tokens);
gen.result()
}