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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//! Rempl is a simple toolkit for creating html components
//! directly within your rust code. The intended purpose
//! is to use this library for HTML templating.
//!
//! The main things to look at are the [`macro@html`] and
//! [`macro@component`] macros.
//!
//! All of the HTML structs ([`HtmlTerm`], [`HtmlElement`],
//! [`HtmlNode`]) can be turned into a html string simply
//! be using the [`std::fmt::Display`] trait.
use HashMap;
pub use component;
/// Allows you to write html directly within your source
/// file.
///
/// The html macro expands to the html element types from
/// the main rempl crate, but let's you create them using
/// easy to write HTML. It also allows you to substitute
/// any attributes or even html content with rust expressions.
/// Due to limitations of the rust tokenizer, unfortunately
/// strings in the html will have to wrapped in quotes.
///
/// You can also call [`macro@component`]s by using the `@` syntax,
/// in this case, attributes are passed as parameters, and the child
/// content is passed as the special require children parameter.
///
///
/// No-children Example:
///
/// ```
/// use rempl::{html, component, HtmlNode, HtmlTerm};
///
/// #[component]
/// fn Figure(caption: String, src: String) -> HtmlTerm {
/// html! {
/// <figure>
/// <img src={ src } alt={ caption } />
/// <figcaption>{ caption }</figcaption>
/// </figure>
/// }
/// }
///
///
/// let image_filename = "/image.png".to_string();
/// let test_result = html! {
/// <@Figure caption="A generic caption" src={ image_filename }/>
/// };
/// let expected_result = "<figure><img alt=\"A generic caption\" src=\"/image.png\"/><figcaption>A generic caption</figcaption></figure>";
/// assert_eq!(test_result.to_string(), expected_result);
/// ```
///
/// Example with children:
///
/// ```
/// use rempl::{html, component, HtmlNode, HtmlTerm};
///
/// #[component]
/// fn Echo(children: HtmlNode) -> HtmlTerm {
/// html! {
/// <p>{ children }</p>
/// }
/// }
///
/// let msg = "Hello, world!";
/// let test_result = html! {
/// <@Echo>{ msg }</Echo>
/// };
/// let expected_result = "<p>Hello, world!</p>";
/// assert_eq!(test_result.to_string(), expected_result);
/// ```
pub use html;
/// A rust native description of a html term.
/// A html element
/// Represents the children of a HTML element.
;