aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src/generator.rs
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-08-14 22:01:53 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-08-14 22:01:53 +0200
commit34fd0c07de86ff338e261a6454bad88661c07b2e (patch)
treebe67e6a45c0a5b6a9922b32fcd9932970544f3d1 /askama_derive/src/generator.rs
parent9552bd50403955cfdcac18757ea942894c891fe8 (diff)
downloadaskama-34fd0c07de86ff338e261a6454bad88661c07b2e.tar.gz
askama-34fd0c07de86ff338e261a6454bad88661c07b2e.tar.bz2
askama-34fd0c07de86ff338e261a6454bad88661c07b2e.zip
Add support for simple variable definition statements
Diffstat (limited to 'askama_derive/src/generator.rs')
-rw-r--r--askama_derive/src/generator.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index 3c97845..faf4e48 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -312,6 +312,20 @@ impl<'a> Generator<'a> {
self.writeln("))?;");
}
+ fn write_let(&mut self, ws: &WS, var: &'a Target, val: &Expr) {
+ self.handle_ws(ws);
+ self.write("let ");
+ match *var {
+ Target::Name(name) => {
+ self.locals.insert(name);
+ self.write(name);
+ },
+ }
+ self.write(" = ");
+ self.visit_expr(val);
+ self.writeln(";");
+ }
+
fn write_cond(&mut self, conds: &'a [Cond], ws: &WS) {
for (i, &(ref cws, ref cond, ref nodes)) in conds.iter().enumerate() {
self.handle_ws(cws);
@@ -403,6 +417,7 @@ impl<'a> Generator<'a> {
Node::Lit(lws, val, rws) => { self.write_lit(lws, val, rws); }
Node::Comment() => {},
Node::Expr(ref ws, ref val) => { self.write_expr(ws, val); },
+ Node::Let(ref ws, ref var, ref val) => { self.write_let(ws, var, val); },
Node::Cond(ref conds, ref ws) => {
self.write_cond(conds, ws);
},