-
-
Notifications
You must be signed in to change notification settings - Fork 137
/
embed.rs
74 lines (56 loc) · 1.57 KB
/
embed.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#[macro_use]
extern crate serde_json;
#[test]
#[cfg(feature = "rust-embed")]
fn test_embed() {
use rust_embed::RustEmbed;
#[derive(RustEmbed)]
#[folder = "tests/templates/"]
#[include = "*.hbs"]
struct Templates;
let mut hbs = handlebars::Handlebars::new();
hbs.register_embed_templates::<Templates>().unwrap();
assert_eq!(1, hbs.get_templates().len());
let data = json!({
"name": "Andy"
});
assert_eq!(
hbs.render("hello.hbs", &data).unwrap().trim(),
"Hello, Andy"
);
}
#[test]
#[cfg(feature = "rust-embed")]
fn test_embed_with_extension() {
use rust_embed::RustEmbed;
#[derive(RustEmbed)]
#[folder = "tests/templates/"]
struct Templates;
let mut hbs = handlebars::Handlebars::new();
hbs.register_embed_templates_with_extension::<Templates>(".hbs")
.unwrap();
assert_eq!(1, hbs.get_templates().len());
let data = json!({
"name": "Andy"
});
assert_eq!(hbs.render("hello", &data).unwrap().trim(), "Hello, Andy");
}
#[test]
#[cfg(feature = "rust-embed")]
fn test_embed_with_extension_and_tests_struct_root() {
use rust_embed::RustEmbed;
#[derive(RustEmbed)]
#[folder = "tests/"]
struct Templates;
let mut hbs = handlebars::Handlebars::new();
hbs.register_embed_templates_with_extension::<Templates>(".hbs")
.unwrap();
assert_eq!(1, hbs.get_templates().len());
let data = json!({
"name": "Andy"
});
assert_eq!(
hbs.render("templates/hello", &data).unwrap().trim(),
"Hello, Andy"
);
}