From 99a83551f555021602bb950d98a5f63dbe4c2f35 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Sat, 24 Dec 2016 10:12:59 +0100 Subject: Move impl code generator into separate module --- askama_codegen/src/generator.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 askama_codegen/src/generator.rs (limited to 'askama_codegen/src/generator.rs') diff --git a/askama_codegen/src/generator.rs b/askama_codegen/src/generator.rs new file mode 100644 index 0000000..8c61f70 --- /dev/null +++ b/askama_codegen/src/generator.rs @@ -0,0 +1,23 @@ +use std::str; + +pub fn generate(ctx_name: &str, tokens: &Vec<&[u8]>) -> String { + let mut code = String::new(); + code.push_str("impl askama::Template for "); + code.push_str(ctx_name); + 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 +} -- cgit