Crates.io | liquid-filter-commafy |
lib.rs | liquid-filter-commafy |
version | 0.1.1 |
source | src |
created_at | 2023-10-03 09:05:35.198238 |
updated_at | 2023-10-03 09:05:35.198238 |
description | Filter for the liquid template engine to commafy a number (put comma after every 3 digtist from right to left). |
homepage | |
repository | https://github.com/szabgab/liquid-filter-commafy.rs |
max_upload_size | |
id | 990861 |
size | 4,988 |
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 commafy a number.
Cargo.toml
:[dependencies]
liquid = "0.26"
liquid-filter-reverse-string = "0.1"
src/main.rs
:
use liquid_filter_commafy::Commafy;
fn main() {
println!("{}", render("{{value | commafy}}", liquid::object!({ "value": "2345" })));
println!("{}", render("{{value | commafy}}", liquid::object!({ "value": 123456 })));
}
fn render(tmpl: &str, glob: liquid::Object) -> String {
let template = liquid::ParserBuilder::with_stdlib()
.filter(Commafy)
.build()
.unwrap()
.parse(tmpl)
.unwrap();
template.render(&glob).unwrap()
}
The important pieces:
The use
statement:
use liquid_filter_commafy::Commafy;
The use of the commafy
filter in the template:
let template = "{{value | commafy}}";
.filter(Commafy)
version
number in Cargo.toml
cargo publish
git tag -a v0.1.0 -m v0.1.0
git push --tags