tera_thousands 0.1.0

Simple filter for tera to split the numbers by thousands
Documentation
  • Coverage
  • 0%
    0 out of 5 items documented0 out of 4 items with examples
  • Size
  • Source code size: 22.33 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.83 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 37s Average build duration of successful builds.
  • all releases: 37s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • kirbylife

tera_thousands

Simple filter for tera to split the numbers by thousands

dependencies:

Usage

The usage is simple:

First add this crate to the Cargo.toml file:

tera_thousands = "0.1.0"

Now add the filter to your Tera instance:

let mut tera = Tera::default();
tera.register_filter("separate_with_commas", tera_thousands::separate_with_commas);

You can now divide the numbers in your tera template with commas:

let mut context = Context::new();
context.insert("number", &123456);

let output = tera
    .render_str("{{ number | separate_with_commas }}", &context)
    .expect("Expected a number");
assert_eq!(output, "123,456");

Also, you can use it with Rocket or any framework compatible with Tera. For example, this is how it would be used with Rocket:

use rocket_dyn_templates::Template;
use tera_thousands::separate_with_commas;

#[launch]
fn rocket() -> _ {
    rocket::build()
        .attach(Template::custom(|engines| {
            engines.tera.register_filter("separate_with_commas", separate_with_commas)
        }))
        .mount(...)
}

The possible options are:

  • separate_with_commas
  • separate_with_dots
  • separate_with_spaces
  • separate_with_underscores

TO-DO

  • An addition customizable filter from the template

Contributors are welcome :).