Move handlebars helper to its own file
This commit is contained in:
13
src/handlebars_util.rs
Normal file
13
src/handlebars_util.rs
Normal 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));
|
||||
}
|
||||
Reference in New Issue
Block a user