diff options
Diffstat (limited to 'askama_shared/src/generator.rs')
-rw-r--r-- | askama_shared/src/generator.rs | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index 82f3994..e5ffd08 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -223,25 +223,35 @@ impl<'a> Generator<'a> { self.write(&format!(".{}", attr)); } - fn visit_filter(&mut self, name: &str, args: &[Expr]) { - if name == "format" { - self.write("format!("); - } else if BUILT_IN_FILTERS.contains(&name) { - self.write(&format!("::askama::filters::{}(&", name)); - } else { - self.write(&format!("filters::{}(&", name)); - } - + fn _visit_filter_args(&mut self, args: &[Expr]) { for (i, arg) in args.iter().enumerate() { if i > 0 { self.write(", &"); } self.visit_expr(arg); } + } + + fn _visit_format_filter(&mut self, args: &[Expr]) { + self.write("format!("); + self._visit_filter_args(args); self.write(")"); - if name != "format" { - self.write("?"); + } + + fn visit_filter(&mut self, name: &str, args: &[Expr]) { + if name == "format" { + self._visit_format_filter(args); + return; + } + + if BUILT_IN_FILTERS.contains(&name) { + self.write(&format!("::askama::filters::{}(&", name)); + } else { + self.write(&format!("filters::{}(&", name)); } + + self._visit_filter_args(args); + self.write(")?"); } fn visit_binop(&mut self, op: &str, left: &Expr, right: &Expr) { |