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
|
use std::collections::HashMap;
use morgana::{morx, Component, RenderNode};
pub fn main() {
let parent = ParentLayout {
children: vec![
RenderNode::Component(
Box::new(Child {
children: vec![
RenderNode::TextNode { content: "Hello world!".to_string() }
]
})
)
]
};
let text = morgana::render_tree_blocking(RenderNode::Component(Box::new(parent)));
println!("{text}")
}
struct ParentLayout {
children: Vec<RenderNode>
}
impl Component for ParentLayout {
fn render(self: Box<Self>) -> Vec<RenderNode> {
let test = morx! {
html lang="en-US" {
head { title { "test thing" } }
body { "some document" }
}
};
vec![
RenderNode::Element { name: "html".to_string(), attributes: HashMap::from([("lang".to_string(), "en-US".to_string())]), children: vec![
RenderNode::Element { name: "head".to_string(), attributes: HashMap::new(), children: vec![
RenderNode::Element { name: "title".to_string(), attributes: HashMap::new(), children: vec![
RenderNode::TextNode { content: "test thing".to_string() }
] }
] },
RenderNode::Element {
name: "body".to_string(),
attributes: HashMap::new(),
children: self.children,
},
] }
]
}
}
struct Child {
children: Vec<RenderNode>
}
impl Component for Child {
fn render(self: Box<Self>) -> Vec<RenderNode> {
vec![
RenderNode::Element {
name: "p".to_string(),
attributes: HashMap::new(),
children: self.children
}
]
}
}
|