blob: 8c61f70454226081dfd169c5e19693ea7ab4da4b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
}
|