From a35d336dc9a61fda931f4a9158205d590af87bd5 Mon Sep 17 00:00:00 2001 From: Ashelyn Rose Date: Fri, 18 Oct 2024 18:08:40 -0600 Subject: Basic sync rendering --- modules/site_test/src/main.rs | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 modules/site_test/src/main.rs (limited to 'modules/site_test/src') diff --git a/modules/site_test/src/main.rs b/modules/site_test/src/main.rs new file mode 100644 index 0000000..3062c11 --- /dev/null +++ b/modules/site_test/src/main.rs @@ -0,0 +1,59 @@ +use std::collections::HashMap; + +use morgana::{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(RenderNode::Component(Box::new(parent))); + println!("{text}") +} + +struct ParentLayout { + children: Vec +} + +impl Component for ParentLayout { + fn render(self: Box) -> Vec { + 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 +} + +impl Component for Child { + fn render(self: Box) -> Vec { + vec![ + RenderNode::Element { + name: "p".to_string(), + attributes: HashMap::new(), + children: self.children + } + ] + } +} -- cgit 1.4.1