diff options
author | yossyJ <28825627+yossyJ@users.noreply.github.com> | 2019-01-07 22:37:23 +0900 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2019-01-08 15:59:45 +0100 |
commit | 10277d739cae2b98b6629b52c64664bb2975e366 (patch) | |
tree | 590e91a27c48b42ee361befec9434bbb6d9c4808 /askama_derive/src/generator.rs | |
parent | df07f7f5e3345ced96decb0cb4c4f1bdfcdb1b12 (diff) | |
download | askama-10277d739cae2b98b6629b52c64664bb2975e366.tar.gz askama-10277d739cae2b98b6629b52c64664bb2975e366.tar.bz2 askama-10277d739cae2b98b6629b52c64664bb2975e366.zip |
Fix loop.last
Diffstat (limited to 'askama_derive/src/generator.rs')
-rw-r--r-- | askama_derive/src/generator.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 6c02a26..288ddae 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -467,15 +467,15 @@ impl<'a> Generator<'a> { let expr_code = self.visit_expr_root(iter); self.write_buf_writable(buf); - buf.write("for (_loop_index, _loop_last, "); + buf.write("for ("); self.visit_target(buf, var); match iter { Expr::Range(_, _, _) => buf.writeln(&format!( - ") in ::askama::helpers::enumerate({}) {{", + ", _loop_item) in ::askama::helpers::TemplateLoop::new({}) {{", expr_code )), _ => buf.writeln(&format!( - ") in ::askama::helpers::enumerate((&{}).into_iter()) {{", + ", _loop_item) in ::askama::helpers::TemplateLoop::new((&{}).into_iter()) {{", expr_code )), }; @@ -913,16 +913,16 @@ impl<'a> Generator<'a> { if let Expr::Var(name) = *obj { if name == "loop" { if attr == "index" { - buf.write("(_loop_index + 1)"); + buf.write("(_loop_item.index + 1)"); return DisplayWrap::Unwrapped; } else if attr == "index0" { - buf.write("_loop_index"); + buf.write("_loop_item.index"); return DisplayWrap::Unwrapped; } else if attr == "first" { - buf.write("(_loop_index == 0)"); + buf.write("_loop_item.first"); return DisplayWrap::Unwrapped; } else if attr == "last" { - buf.write("_loop_last"); + buf.write("_loop_item.last"); return DisplayWrap::Unwrapped; } else { panic!("unknown loop variable"); |