2020-05-21 22:38:39 -07:00
|
|
|
extern crate human_format;
|
|
|
|
|
use handlebars::*;
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
|
pub struct HumanFormatHelper;
|
|
|
|
|
|
|
|
|
|
impl HelperDef for HumanFormatHelper {
|
2020-05-27 20:46:59 +02:00
|
|
|
fn call<'reg: 'rc, 'rc>(&self, h: &Helper<'reg, 'rc>, _r: &'reg Handlebars<'_>, _ctx: &'rc Context, _rc: &mut RenderContext<'reg, 'rc>, out: &mut dyn Output) -> HelperResult {
|
2020-05-21 22:38:39 -07:00
|
|
|
let param = h.param(0).and_then(|v| v.value().as_f64()).unwrap_or(0.0);
|
|
|
|
|
|
|
|
|
|
let mut formatted = human_format::Formatter::new().format(param);
|
|
|
|
|
formatted.retain(|c| !c.is_whitespace());
|
|
|
|
|
|
|
|
|
|
out.write(formatted.to_uppercase().as_ref())?;
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|