mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 15:25:19 +00:00
Replace format!()
with to_string()
in filters
This commit is contained in:
parent
65e13033e1
commit
5ffe3de311
@ -87,7 +87,7 @@ pub fn format() {}
|
|||||||
/// A single newline becomes an HTML line break `<br>` and a new line
|
/// A single newline becomes an HTML line break `<br>` and a new line
|
||||||
/// followed by a blank line becomes a paragraph break `<p>`.
|
/// followed by a blank line becomes a paragraph break `<p>`.
|
||||||
pub fn linebreaks(s: &fmt::Display) -> Result<String> {
|
pub fn linebreaks(s: &fmt::Display) -> Result<String> {
|
||||||
let s = format!("{}", s);
|
let s = s.to_string();
|
||||||
let linebroken = s.replace("\n\n", "</p><p>").replace("\n", "<br/>");
|
let linebroken = s.replace("\n\n", "</p><p>").replace("\n", "<br/>");
|
||||||
|
|
||||||
Ok(format!("<p>{}</p>", linebroken))
|
Ok(format!("<p>{}</p>", linebroken))
|
||||||
@ -95,13 +95,13 @@ pub fn linebreaks(s: &fmt::Display) -> Result<String> {
|
|||||||
|
|
||||||
/// Converts all newlines in a piece of plain text to HTML line breaks
|
/// Converts all newlines in a piece of plain text to HTML line breaks
|
||||||
pub fn linebreaksbr(s: &fmt::Display) -> Result<String> {
|
pub fn linebreaksbr(s: &fmt::Display) -> Result<String> {
|
||||||
let s = format!("{}", s);
|
let s = s.to_string();
|
||||||
Ok(s.replace("\n", "<br/>"))
|
Ok(s.replace("\n", "<br/>"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts to lowercase
|
/// Converts to lowercase
|
||||||
pub fn lower(s: &fmt::Display) -> Result<String> {
|
pub fn lower(s: &fmt::Display) -> Result<String> {
|
||||||
let s = format!("{}", s);
|
let s = s.to_string();
|
||||||
Ok(s.to_lowercase())
|
Ok(s.to_lowercase())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ pub fn lowercase(s: &fmt::Display) -> Result<String> {
|
|||||||
|
|
||||||
/// Converts to uppercase
|
/// Converts to uppercase
|
||||||
pub fn upper(s: &fmt::Display) -> Result<String> {
|
pub fn upper(s: &fmt::Display) -> Result<String> {
|
||||||
let s = format!("{}", s);
|
let s = s.to_string();
|
||||||
Ok(s.to_uppercase())
|
Ok(s.to_uppercase())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,13 +123,13 @@ pub fn uppercase(s: &fmt::Display) -> Result<String> {
|
|||||||
|
|
||||||
/// Strip leading and trailing whitespace
|
/// Strip leading and trailing whitespace
|
||||||
pub fn trim(s: &fmt::Display) -> Result<String> {
|
pub fn trim(s: &fmt::Display) -> Result<String> {
|
||||||
let s = format!("{}", s);
|
let s = s.to_string();
|
||||||
Ok(s.trim().to_owned())
|
Ok(s.trim().to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Limit string length, appends '...' if truncated
|
/// Limit string length, appends '...' if truncated
|
||||||
pub fn truncate(s: &fmt::Display, len: &usize) -> Result<String> {
|
pub fn truncate(s: &fmt::Display, len: &usize) -> Result<String> {
|
||||||
let mut s = format!("{}", s);
|
let mut s = s.to_string();
|
||||||
if s.len() < *len {
|
if s.len() < *len {
|
||||||
Ok(s)
|
Ok(s)
|
||||||
} else {
|
} else {
|
||||||
@ -141,7 +141,7 @@ pub fn truncate(s: &fmt::Display, len: &usize) -> Result<String> {
|
|||||||
|
|
||||||
/// Indent lines with `width` spaces
|
/// Indent lines with `width` spaces
|
||||||
pub fn indent(s: &fmt::Display, width: &usize) -> Result<String> {
|
pub fn indent(s: &fmt::Display, width: &usize) -> Result<String> {
|
||||||
let s = format!("{}", s);
|
let s = s.to_string();
|
||||||
|
|
||||||
let mut indented = String::new();
|
let mut indented = String::new();
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ where
|
|||||||
|
|
||||||
/// Capitalize a value. The first character will be uppercase, all others lowercase.
|
/// Capitalize a value. The first character will be uppercase, all others lowercase.
|
||||||
pub fn capitalize(s: &fmt::Display) -> Result<String> {
|
pub fn capitalize(s: &fmt::Display) -> Result<String> {
|
||||||
let mut s = format!("{}", s);
|
let mut s = s.to_string();
|
||||||
|
|
||||||
match s.get_mut(0..1).map(|s| {
|
match s.get_mut(0..1).map(|s| {
|
||||||
s.make_ascii_uppercase();
|
s.make_ascii_uppercase();
|
||||||
@ -211,7 +211,7 @@ pub fn capitalize(s: &fmt::Display) -> Result<String> {
|
|||||||
|
|
||||||
/// Centers the value in a field of a given width
|
/// Centers the value in a field of a given width
|
||||||
pub fn center(s: &fmt::Display, l: usize) -> Result<String> {
|
pub fn center(s: &fmt::Display, l: usize) -> Result<String> {
|
||||||
let s = format!("{}", s);
|
let s = s.to_string();
|
||||||
let len = s.len();
|
let len = s.len();
|
||||||
|
|
||||||
if l <= len {
|
if l <= len {
|
||||||
@ -238,7 +238,7 @@ pub fn center(s: &fmt::Display, l: usize) -> Result<String> {
|
|||||||
|
|
||||||
/// Count the words in that string
|
/// Count the words in that string
|
||||||
pub fn wordcount(s: &fmt::Display) -> Result<usize> {
|
pub fn wordcount(s: &fmt::Display) -> Result<usize> {
|
||||||
let s = format!("{}", s);
|
let s = s.to_string();
|
||||||
|
|
||||||
Ok(s.split_whitespace().count())
|
Ok(s.split_whitespace().count())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user