aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-02-05 15:01:45 +0100
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-02-05 15:01:45 +0100
commit4fb4bed8f103b4e26de97bd68a22d6b350d531f6 (patch)
treece6a2ad76a7f3e1beade35f06c05ca9fa9245395
parent78782783102e069862de005112fe1a2fbb5baea1 (diff)
downloadaskama-4fb4bed8f103b4e26de97bd68a22d6b350d531f6.tar.gz
askama-4fb4bed8f103b4e26de97bd68a22d6b350d531f6.tar.bz2
askama-4fb4bed8f103b4e26de97bd68a22d6b350d531f6.zip
Extract helper function from Generator class
-rw-r--r--askama/src/generator.rs30
1 files changed, 15 insertions, 15 deletions
diff --git a/askama/src/generator.rs b/askama/src/generator.rs
index 0f5ec85..3650ddb 100644
--- a/askama/src/generator.rs
+++ b/askama/src/generator.rs
@@ -3,6 +3,19 @@ use std::str;
use std::collections::HashSet;
use syn;
+fn annotations(generics: &syn::Generics) -> String {
+ if generics.lifetimes.len() < 1 {
+ return String::new();
+ }
+ let mut res = String::new();
+ res.push('<');
+ for lt in &generics.lifetimes {
+ res.push_str(lt.lifetime.ident.as_ref());
+ }
+ res.push('>');
+ res
+}
+
fn path_as_identifier(s: &str) -> String {
let mut res = String::new();
for c in s.chars() {
@@ -183,29 +196,16 @@ impl Generator {
fn path_based_name(&mut self, ast: &syn::DeriveInput, path: &str) {
let encoded = path_as_identifier(path);
let original = ast.ident.as_ref();
- let anno = self.annotations(&ast.generics);
+ let anno = annotations(&ast.generics);
self.writeln("#[allow(dead_code, non_camel_case_types)]");
let s = format!("type TemplateFrom{}{} = {}{};",
encoded, &anno, original, &anno);
self.writeln(&s);
}
- fn annotations(&self, generics: &syn::Generics) -> String {
- if generics.lifetimes.len() < 1 {
- return String::new();
- }
- let mut res = String::new();
- res.push('<');
- for lt in &generics.lifetimes {
- res.push_str(lt.lifetime.ident.as_ref());
- }
- res.push('>');
- res
- }
-
fn template_impl(&mut self, ast: &syn::DeriveInput, nodes: &Vec<Node>) {
self.write("impl");
- let anno = self.annotations(&ast.generics);
+ let anno = annotations(&ast.generics);
self.write(&anno);
self.write(" askama::Template for ");
self.write(ast.ident.as_ref());