]>
Commit | Line | Data |
---|---|---|
8bb4bdeb XL |
1 | extern crate env_logger; |
2 | extern crate handlebars; | |
8bb4bdeb XL |
3 | #[macro_use] |
4 | extern crate maplit; | |
5 | ||
6 | use std::path::Path; | |
7 | use handlebars::Handlebars; | |
8 | ||
8bb4bdeb XL |
9 | fn main() { |
10 | env_logger::init().unwrap(); | |
11 | let mut handlebars = Handlebars::new(); | |
12 | ||
ea8adc8c XL |
13 | handlebars |
14 | .register_template_file("template", &Path::new("./examples/partials/template2.hbs")) | |
7cac9316 XL |
15 | .ok() |
16 | .unwrap(); | |
8bb4bdeb | 17 | |
ea8adc8c XL |
18 | handlebars |
19 | .register_template_file("base0", &Path::new("./examples/partials/base0.hbs")) | |
7cac9316 XL |
20 | .ok() |
21 | .unwrap(); | |
ea8adc8c XL |
22 | handlebars |
23 | .register_template_file("base1", &Path::new("./examples/partials/base1.hbs")) | |
7cac9316 XL |
24 | .ok() |
25 | .unwrap(); | |
8bb4bdeb | 26 | |
83c7162d | 27 | let data0 = btreemap! { |
8bb4bdeb XL |
28 | "title".to_string() => "example 0".to_string(), |
29 | "parent".to_string() => "base0".to_string() | |
30 | }; | |
83c7162d | 31 | let data1 = btreemap! { |
8bb4bdeb XL |
32 | "title".to_string() => "example 1".to_string(), |
33 | "parent".to_string() => "base1".to_string() | |
34 | }; | |
35 | ||
36 | println!("Page 0"); | |
ea8adc8c XL |
37 | println!( |
38 | "{}", | |
83c7162d XL |
39 | handlebars |
40 | .render("template", &data0,) | |
41 | .unwrap_or_else(|e| format!("{}", e),) | |
ea8adc8c | 42 | ); |
8bb4bdeb XL |
43 | println!("======================================================="); |
44 | ||
45 | println!("Page 1"); | |
ea8adc8c XL |
46 | println!( |
47 | "{}", | |
83c7162d XL |
48 | handlebars |
49 | .render("template", &data1,) | |
50 | .unwrap_or_else(|e| format!("{}", e),) | |
ea8adc8c | 51 | ); |
8bb4bdeb | 52 | } |