1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use crate::templates::helpers::register_helpers;
use handlebars::Handlebars;
use std::sync::Arc;
lazy_static! {
static ref APP_DATA: Arc<AppData> = {
Arc::new(AppData::new())
};
}
#[derive(Clone)]
pub struct AppData {
template_registry: Arc<Handlebars<'static>>,
}
impl AppData {
fn new() -> Self {
let mut template_registry = Handlebars::new();
template_registry
.register_templates_directory(".hbs", "templates")
.map_err(|e| {
error!("Failed to properly register handlebars templates: {}", e);
e
})
.unwrap();
register_helpers(&mut template_registry);
info!("Handlebars templates registered.");
Self {
template_registry: Arc::new(template_registry),
}
}
pub fn global() -> Arc<AppData> {
APP_DATA.clone()
}
pub fn get_handlebars_registry(&self) -> Arc<Handlebars<'static>> {
self.template_registry.clone()
}
}