-
Notifications
You must be signed in to change notification settings - Fork 1
/
library_handlebars.rs
33 lines (27 loc) · 883 Bytes
/
library_handlebars.rs
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
use std::collections;
#[iftree::include_file_tree("paths = '/examples/assets/**'")]
pub struct Asset {
relative_path: &'static str,
contents_str: &'static str,
}
fn main() {
use base::examples::assets;
let template_processor = get_template_processor();
let mut data = collections::HashMap::<String, String>::new();
data.insert("name".into(), "Frodo".into());
assert_eq!(
template_processor
.render(assets::configuration::TRANSLATIONS_CSV.relative_path, &data)
.unwrap(),
"Hi Frodo\n",
);
}
fn get_template_processor<'a>() -> handlebars::Handlebars<'a> {
let mut template_processor = handlebars::Handlebars::new();
for asset in &ASSETS {
template_processor
.register_template_string(asset.relative_path, asset.contents_str)
.unwrap();
}
template_processor
}