diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-02-18 14:02:38 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2017-02-18 14:02:38 +0100 |
commit | a4588dc02d82ed88084fdf94fc703bb02d2f9971 (patch) | |
tree | 6878c15e27fa5fd432f71aa3335a02f2f8f6873a | |
parent | be2cce3598a77eaf4e9931aa1154e02b6b9561e1 (diff) | |
download | askama-a4588dc02d82ed88084fdf94fc703bb02d2f9971.tar.gz askama-a4588dc02d82ed88084fdf94fc703bb02d2f9971.tar.bz2 askama-a4588dc02d82ed88084fdf94fc703bb02d2f9971.zip |
Implement support for format filter
Diffstat (limited to '')
-rw-r--r-- | askama/src/filters.rs | 4 | ||||
-rw-r--r-- | askama/src/generator.rs | 7 |
2 files changed, 10 insertions, 1 deletions
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(", &"); |