diff options
author | defyrlt <defyrlt@users.noreply.github.com> | 2017-08-29 23:02:13 +0300 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-09-02 13:34:52 +0200 |
commit | 7d2d7718aa8467ddd5ca9753bde2c7a87ff55c9f (patch) | |
tree | 98618ab42faa8e64d9ad96f19379e3ec82041a3e /askama_shared/src/generator.rs | |
parent | b0ea82d87aa61576d1565f20276d411295b9a19d (diff) | |
download | askama-7d2d7718aa8467ddd5ca9753bde2c7a87ff55c9f.tar.gz askama-7d2d7718aa8467ddd5ca9753bde2c7a87ff55c9f.tar.bz2 askama-7d2d7718aa8467ddd5ca9753bde2c7a87ff55c9f.zip |
Add `join` filter & tests for it
Diffstat (limited to '')
-rw-r--r-- | askama_shared/src/generator.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index e5ffd08..836da34 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -238,10 +238,35 @@ impl<'a> Generator<'a> { self.write(")"); } + fn _visit_join_filter(&mut self, args: &[Expr]) { + // this is a separate handler because we need to generate code like + // this to force auto-deref for first argument: + // `join((&&&&&&self.s).into_iter(), ", ")` + // otherwise, we were getting errors described in PR #39 + self.write("::askama::filters::join((&"); + + for (i, arg) in args.iter().enumerate() { + if i > 0 { + self.write(", &"); + } + + self.visit_expr(arg); + + if i == 0 { + self.write(").into_iter()"); + } + } + + self.write(")?"); + } + fn visit_filter(&mut self, name: &str, args: &[Expr]) { if name == "format" { self._visit_format_filter(args); return; + } else if name == "join" { + self._visit_join_filter(args); + return; } if BUILT_IN_FILTERS.contains(&name) { |