diff options
Diffstat (limited to 'askama_shared/src/generator.rs')
-rw-r--r-- | askama_shared/src/generator.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index 82f68ff..e45acb6 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -999,6 +999,9 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { if name == "format" { self._visit_format_filter(buf, args); return DisplayWrap::Unwrapped; + } else if name == "fmt" { + self._visit_fmt_filter(buf, args); + return DisplayWrap::Unwrapped; } else if name == "join" { self._visit_join_filter(buf, args); return DisplayWrap::Unwrapped; @@ -1038,6 +1041,21 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { buf.write(")"); } + fn _visit_fmt_filter(&mut self, buf: &mut Buffer, args: &[Expr]) { + buf.write("format!("); + if let Some(Expr::StrLit(v)) = args.get(1) { + self.visit_str_lit(buf, v); + buf.write(", "); + } else { + panic!("invalid expression type for fmt filter"); + } + self._visit_args(buf, &args[0..1]); + if args.len() > 2 { + panic!("only two arguments allowed to fmt filter"); + } + buf.write(")"); + } + // Force type coercion on first argument to `join` filter (see #39). fn _visit_join_filter(&mut self, buf: &mut Buffer, args: &[Expr]) { buf.write("::askama::filters::join((&"); |