aboutsummaryrefslogtreecommitdiffstats
path: root/askama_codegen/src/generator.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--askama_codegen/src/generator.rs20
1 files changed, 10 insertions, 10 deletions
diff --git a/askama_codegen/src/generator.rs b/askama_codegen/src/generator.rs
index 8c61f70..7689af5 100644
--- a/askama_codegen/src/generator.rs
+++ b/askama_codegen/src/generator.rs
@@ -1,21 +1,21 @@
+use parser::Node;
use std::str;
-pub fn generate(ctx_name: &str, tokens: &Vec<&[u8]>) -> String {
+pub fn generate(ctx_name: &str, tokens: &Vec<Node>) -> 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");
+ for n in tokens {
+ code.push_str(" buf.push_str(");
+ code.push_str(&match n {
+ &Node::Lit(val) => format!("{:#?}", str::from_utf8(val).unwrap()),
+ &Node::Expr(val) => format!("&self.{}", str::from_utf8(val).unwrap()),
+ });
+ code.push_str(");\n");
+ }
code.push_str(" buf");
code.push_str(" }\n");
code.push_str("}\n\n");