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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! # Kitamura
//! Kitamura is an HTML templating engine for rendering HTML based on placeholders
//! defined in your HTML. Placeholders are provided in the form of content parameters
//! that are in JSON.
//!
//! # Overview
//! Below is the general idea of how to use Kitamura. Formatting of the input HTML
//! is respected, and overall there are no expectations that anything but what Kitamura
//! is looking for will be modified.
//! ```text
//! Input HTML
//! <html>Hello ${first_name}!</html>
//!
//! Input Data
//! {
//! "first_name": "Joel"
//! }
//!
//! Output HTML
//! <html>Hello Joel!</html>
//! ```
//!
//! # Features
//! Variables
//!
//! Lists
//!
//! # Examples
//! ```
//! use std::collections::HashMap;
//! use kitamura::render_template;
//! use serde_json::json;
//!
//! let input_html = "<html>Hello ${first_name}!</html>";
//! let mut input_data = HashMap::new();
//! input_data.insert("first_name".to_string(), json!("Joel"));
//!
//! let output_html = render_template(input_html.to_string(), input_data);
//! assert_eq!(output_html, "<html>Hello Joel!</html>");
//! ```
//! ```
//! use std::collections::HashMap;
//! use kitamura::render_template;
//! use serde_json::json;
//!
//! let input_html =
//! "<html>
//! <ul>
//! {#for fruit in fruits#}
//! <ul>
//! <li>${fruit.name}</li>
//! <li>${fruit.colour}</li>
//! <li>${fruit.weight}</li>
//! </ul>
//! {#endfor#}
//! </ul>
//! </html>";
//! let mut input_data = HashMap::new();
//! input_data.insert(
//!"fruits".to_string(),
//!json!([{"name": "Lemon", "colour": "Yellow", "weight": "150g"},
//!{"name": "shiikuwasha", "colour": "Green", "weight": "80g"},
//!{"name": "Lychee", "colour": "Red", "weight": "50g"}]),
//!);
//!
//! let output_html = render_template(input_html.to_string(), input_data);
//! assert_eq!(output_html,
//! "<html>
//! <ul>
//! <ul>
//! <li>Lemon</li>
//! <li>Yellow</li>
//! <li>150g</li>
//! </ul>
//! <ul>
//! <li>shiikuwasha</li>
//! <li>Green</li>
//! <li>80g</li>
//! </ul>
//! <ul>
//! <li>Lychee</li>
//! <li>Red</li>
//! <li>50g</li>
//! </ul>
//! </ul>
//!</html>");
//! ```
use HashMap;