From 7362ca0dcb61ec70ad88f74873f459702c5c0dde Mon Sep 17 00:00:00 2001 From: Christian Legnitto Date: Fri, 10 Mar 2017 13:32:30 -0800 Subject: Add `lower` and `upper` filters --- askama/src/filters.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/askama/src/filters.rs b/askama/src/filters.rs index 3f6aede..bd64bb0 100644 --- a/askama/src/filters.rs +++ b/askama/src/filters.rs @@ -57,6 +57,28 @@ pub fn e(s: &fmt::Display) -> String { /// the Askama code generator. pub fn format() { } +/// Converts to lowercase. +pub fn lower(s: &fmt::Display) -> String { + let s = format!("{}", s); + s.to_lowercase() +} + +/// Alias for the `lower()` filter. +pub fn lowercase(s: &fmt::Display) -> String { + lower(s) +} + +/// Converts to uppercase. +pub fn upper(s: &fmt::Display) -> String { + let s = format!("{}", s); + s.to_uppercase() +} + +/// Alias for the `upper()` filter. +pub fn uppercase(s: &fmt::Display) -> String { + upper(s) +} + #[cfg(test)] mod tests { use super::*; @@ -66,5 +88,15 @@ mod tests { assert_eq!(escape(&"<&>"), "<&>"); assert_eq!(escape(&"bla&"), "bla&"); assert_eq!(escape(&"