aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src/generator.rs
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-06-23 17:07:45 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2018-06-23 17:07:45 +0200
commitf1422f5c66509f251e1e3e2cbd1752131dd1301f (patch)
tree3997c680a877cf474686a980e7a900953a2b9ff9 /askama_derive/src/generator.rs
parent381997a9b095d656d4f3f9e1a5f483390ec52129 (diff)
downloadaskama-f1422f5c66509f251e1e3e2cbd1752131dd1301f.tar.gz
askama-f1422f5c66509f251e1e3e2cbd1752131dd1301f.tar.bz2
askama-f1422f5c66509f251e1e3e2cbd1752131dd1301f.zip
Add support for Index operation (see #95)
Diffstat (limited to 'askama_derive/src/generator.rs')
-rw-r--r--askama_derive/src/generator.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index 59d8134..0e86a27 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -594,6 +594,7 @@ impl<'a> Generator<'a> {
Expr::Path(ref path) => self.visit_path(path, code),
Expr::Array(ref elements) => self.visit_array(elements, code),
Expr::Attr(ref obj, name) => self.visit_attr(obj, name, code),
+ Expr::Index(ref obj, ref key) => self.visit_index(obj, key, code),
Expr::Filter(name, ref args) => self.visit_filter(name, args, code),
Expr::Unary(op, ref inner) => self.visit_unary(op, inner, code),
Expr::BinOp(op, ref left, ref right) => self.visit_binop(op, left, right, code),
@@ -728,6 +729,14 @@ impl<'a> Generator<'a> {
DisplayWrap::Unwrapped
}
+ fn visit_index(&mut self, obj: &Expr, key: &Expr, code: &mut String) -> DisplayWrap {
+ self.visit_expr(obj, code);
+ code.push_str("[");
+ self.visit_expr(key, code);
+ code.push_str("]");
+ DisplayWrap::Unwrapped
+ }
+
fn visit_method_call(
&mut self,
obj: &Expr,