summary refs log tree commit diff
path: root/modules/site_test/src/main.rs
blob: ba40ede66b65676ce63109b647fa72dcd9dc9a28 (plain)
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
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> {
        morx!{
            html lang = "en-US" {
                head {
                    title = "test thing"
                }
                body = {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
            }
        ]
    }
}