aboutsummaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
authorLibravatar Andrew Dona-Couch <hi@andrewcou.ch>2020-07-08 17:03:02 +0000
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2020-07-14 20:48:15 +0200
commit42c4cb1d877d696bb97aa2e9402429dad42d7d66 (patch)
tree81db4dfc1925a2a8cc4e99c42ae4cc003e60f9e5 /testing
parent21fb60466c9bae2fac325f057da20d7143618412 (diff)
downloadaskama-42c4cb1d877d696bb97aa2e9402429dad42d7d66.tar.gz
askama-42c4cb1d877d696bb97aa2e9402429dad42d7d66.tar.bz2
askama-42c4cb1d877d696bb97aa2e9402429dad42d7d66.zip
Add fmt filter that swaps the first two arguments to format!().
This allows a more natural filter usage: `{{ val | fmt("{:?}") }}` as well as enabling convenient filter composition: `{{ price | to_f64 | fmt("${:.2}") | center }}`
Diffstat (limited to '')
-rw-r--r--testing/tests/filters.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/testing/tests/filters.rs b/testing/tests/filters.rs
index b02a64b..035e5da 100644
--- a/testing/tests/filters.rs
+++ b/testing/tests/filters.rs
@@ -39,6 +39,18 @@ fn filter_format() {
}
#[derive(Template)]
+#[template(source = "{{ var|fmt(\"{:?}\") }}", ext = "html", escape = "none")]
+struct FmtTemplate<'a> {
+ var: &'a str,
+}
+
+#[test]
+fn filter_fmt() {
+ let t = FmtTemplate { var: "formatted" };
+ assert_eq!(t.render().unwrap(), "\"formatted\"");
+}
+
+#[derive(Template)]
#[template(source = "{{ s|myfilter }}", ext = "txt")]
struct MyFilterTemplate<'a> {
s: &'a str,