diff options
author | Ashelyn Rose <git@ashen.earth> | 2024-10-18 18:08:40 -0600 |
---|---|---|
committer | Ashelyn Rose <git@ashen.earth> | 2024-10-18 18:08:40 -0600 |
commit | a35d336dc9a61fda931f4a9158205d590af87bd5 (patch) | |
tree | cde9b67c0a5d938d7caec596664bc9d0610b5d90 /modules |
Basic sync rendering
Diffstat (limited to 'modules')
-rw-r--r-- | modules/proc/Cargo.toml | 3 | ||||
-rw-r--r-- | modules/proc/src/lib.rs | 0 | ||||
-rw-r--r-- | modules/site_test/Cargo.toml | 6 | ||||
-rw-r--r-- | modules/site_test/src/main.rs | 59 |
4 files changed, 68 insertions, 0 deletions
diff --git a/modules/proc/Cargo.toml b/modules/proc/Cargo.toml new file mode 100644 index 0000000..16bcbb8 --- /dev/null +++ b/modules/proc/Cargo.toml @@ -0,0 +1,3 @@ +[package] +name = "morgana_proc" +edition = "2021" diff --git a/modules/proc/src/lib.rs b/modules/proc/src/lib.rs new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/modules/proc/src/lib.rs diff --git a/modules/site_test/Cargo.toml b/modules/site_test/Cargo.toml new file mode 100644 index 0000000..118c9bd --- /dev/null +++ b/modules/site_test/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "morgana_site_test" +edition = "2021" + +[dependencies] +morgana = { path = "../../" } 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<RenderNode> +} + +impl Component for ParentLayout { + fn render(self: Box<Self>) -> Vec<RenderNode> { + 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 + } + ] + } +} |