diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2016-12-24 10:12:59 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2016-12-24 10:12:59 +0100 |
commit | 99a83551f555021602bb950d98a5f63dbe4c2f35 (patch) | |
tree | 3f3cb973bf35d87e81cccc9c3c30a805d55446b4 /askama_codegen/src/lib.rs | |
parent | 8f0aae265cb3471b2472cb95c820746df7213bed (diff) | |
download | askama-99a83551f555021602bb950d98a5f63dbe4c2f35.tar.gz askama-99a83551f555021602bb950d98a5f63dbe4c2f35.tar.bz2 askama-99a83551f555021602bb950d98a5f63dbe4c2f35.zip |
Move impl code generator into separate module
Diffstat (limited to '')
-rw-r--r-- | askama_codegen/src/lib.rs | 23 |
1 files changed, 2 insertions, 21 deletions
diff --git a/askama_codegen/src/lib.rs b/askama_codegen/src/lib.rs index 72e51ba..d923e19 100644 --- a/askama_codegen/src/lib.rs +++ b/askama_codegen/src/lib.rs @@ -7,13 +7,13 @@ extern crate proc_macro; extern crate quote; extern crate syn; +mod generator; mod parser; use proc_macro::TokenStream; use std::fs::File; use std::io::Read; use std::path::{Path, PathBuf}; -use std::str; fn get_path_from_attrs(attrs: &Vec<syn::Attribute>) -> String { for attr in attrs { @@ -68,24 +68,5 @@ pub fn derive_template(input: TokenStream) -> TokenStream { let path = get_path_from_attrs(&ast.attrs); let src = get_template_source(&path); let tokens = parser::parse(&src); - - let mut code = String::new(); - code.push_str("impl askama::Template for "); - code.push_str(name.as_ref()); - code.push_str(" {\n"); - code.push_str(" fn render(&self) -> String {\n"); - code.push_str(" let mut buf = String::new();\n"); - code.push_str(" buf.push_str(\""); - code.push_str(str::from_utf8(tokens[0]).unwrap()); - code.push_str("\");\n"); - code.push_str(" buf.push_str(&self."); - code.push_str(str::from_utf8(tokens[1]).unwrap()); - code.push_str(");\n"); - code.push_str(" buf.push_str(\""); - code.push_str(str::from_utf8(tokens[2]).unwrap()); - code.push_str("\");\n"); - code.push_str(" buf"); - code.push_str(" }\n"); - code.push_str("}\n\n"); - code.parse().unwrap() + generator::generate(name.as_ref(), &tokens).parse().unwrap() } |