aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Christian Legnitto <christian@legnitto.com>2017-03-10 13:32:30 -0800
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-03-10 22:41:46 +0100
commit7362ca0dcb61ec70ad88f74873f459702c5c0dde (patch)
tree97b6470602d893ef50fc0d8e846d48b262d830e6
parentba70b11f40b960bf09d2a43e106bdad196cc158b (diff)
downloadaskama-7362ca0dcb61ec70ad88f74873f459702c5c0dde.tar.gz
askama-7362ca0dcb61ec70ad88f74873f459702c5c0dde.tar.bz2
askama-7362ca0dcb61ec70ad88f74873f459702c5c0dde.zip
Add `lower` and `upper` filters
Diffstat (limited to '')
-rw-r--r--askama/src/filters.rs32
1 files changed, 32 insertions, 0 deletions
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(&"<&>"), "&lt;&amp;&gt;");
assert_eq!(escape(&"bla&"), "bla&amp;");
assert_eq!(escape(&"<foo"), "&lt;foo");
+
+ assert_eq!(lower(&"Foo"), "foo");
+ assert_eq!(lower(&"FOO"), "foo");
+ assert_eq!(lower(&"FooBar"), "foobar");
+ assert_eq!(lower(&"foo"), "foo");
+
+ assert_eq!(upper(&"Foo"), "FOO");
+ assert_eq!(upper(&"FOO"), "FOO");
+ assert_eq!(upper(&"FooBar"), "FOOBAR");
+ assert_eq!(upper(&"foo"), "FOO");
}
}