Crates.io | liquid-filter-reverse-string |
lib.rs | liquid-filter-reverse-string |
version | 0.1.1 |
source | src |
created_at | 2023-10-03 07:27:22.124328 |
updated_at | 2023-10-03 07:40:06.57475 |
description | Filter for the liquid template engine to reverse a string. |
homepage | |
repository | https://github.com/szabgab/liquid-filter-reverse-string.rs |
max_upload_size | |
id | 990807 |
size | 4,683 |
The liquid crate, the Rust implementation of the liquid template system has many filters to manipulate the data in the template, but AFAIK there is no filter to reverse a string.
This crate was originally developed as a demo on how to add a filter to liquid.
Cargo.toml
:[dependencies]
liquid = "0.26"
liquid-filter-reverse-string = "0.1"
src/main.rs
:
use liquid_filter_reverse_string::ReverseStr;
fn main() {
let template = "reversed: {{text | reversestr}}";
let text = "Hello World!";
let result = render(&template, &text);
println!("{}", result);
assert_eq!(result, "reversed: !dlroW olleH");
}
fn render(tmpl: &str, text: &str) -> String {
let globals = liquid::object!({
"text": text,
});
let template = liquid::ParserBuilder::with_stdlib()
.filter(ReverseStr)
.build()
.unwrap()
.parse(tmpl).unwrap();
let output = template.render(&globals).unwrap();
return output
}
The important pieces:
The use
statement:
use liquid_filter_reverse_string::ReverseStr;
The use of the reversestr
filter in the template
let template = "reversed: {{text | reversestr}}";
.filter(ReverseStr)
version
number in Cargo.toml
cargo publish
git tag -a v0.1.0 -m v0.1.0
git push --tags