From a4588dc02d82ed88084fdf94fc703bb02d2f9971 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Sat, 18 Feb 2017 14:02:38 +0100 Subject: Implement support for format filter --- askama/src/filters.rs | 4 ++++ askama/src/generator.rs | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/askama/src/filters.rs b/askama/src/filters.rs index 17d25c5..a9fe248 100644 --- a/askama/src/filters.rs +++ b/askama/src/filters.rs @@ -43,6 +43,10 @@ pub fn e(s: &fmt::Display) -> String { escape(s) } +/// This is actually unused; format filter calls are forwarded directly to +/// the format!() macro in the code generator (see `visit_filter()`). +pub fn format() { } + #[cfg(test)] mod tests { use super::*; diff --git a/askama/src/generator.rs b/askama/src/generator.rs index 911b860..40b6523 100644 --- a/askama/src/generator.rs +++ b/askama/src/generator.rs @@ -125,7 +125,12 @@ impl<'a> Generator<'a> { } fn visit_filter(&mut self, name: &str, args: &[Expr]) { - self.write(&format!("askama::filters::{}(&", name)); + if name == "format" { + self.write("format!("); + } else { + self.write(&format!("askama::filters::{}(&", name)); + } + for (i, arg) in args.iter().enumerate() { if i > 0 { self.write(", &"); -- cgit