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
use fmt;
/// Trait for reusable HTML components.
///
/// A component is a renderable unit that accepts extra HTML attributes and children from its call site. You normally
/// don't implement this trait by hand - use the [`component!`](crate::component) macro instead, which generates a
/// struct and this trait implementation for you.
///
/// # The `render_component` method
///
/// The `attrs` closure writes any extra HTML attributes passed at the call site (those appearing after the `;` in
/// `@Component(props; attrs)`). The `children` closure writes the child content placed inside the component's braces.
///
/// # Example
///
/// ```
/// use plait::{component, html, ToHtml, classes, Class};
///
/// component! {
/// pub fn Alert(class: impl Class) {
/// div(class: classes!("alert", class), #attrs) {
/// #children
/// }
/// }
/// }
///
/// let page = html! {
/// @Alert(class: "alert-danger"; role: "alert") {
/// "Something went wrong!"
/// }
/// };
///
/// assert_eq!(page.to_html(), r#"<div class="alert alert-danger" role="alert">Something went wrong!</div>"#);
/// ```