Move handlebars helper to its own file

This commit is contained in:
2020-10-28 01:15:58 +01:00
parent e8edaa9acb
commit fe5cd04506
2 changed files with 15 additions and 11 deletions

13
src/handlebars_util.rs Normal file
View File

@ -0,0 +1,13 @@
use rocket_contrib::templates::Engines;
use handlebars::handlebars_helper;
pub fn register_helpers(engines: &mut Engines) {
handlebars_helper!(pretty_datetime: |dt: str| {
let date = dt.trim_end_matches(|c| c != 'T').trim_end_matches('T');
let time = dt.trim_start_matches(|c| c != 'T').trim_start_matches('T')
.trim_end_matches(|c| c != ':').trim_end_matches(':');
format!("{} {}", date, time)
});
engines.handlebars.register_helper("pretty_datetime", Box::new(pretty_datetime));
}