aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaditya Dhruv <[email protected]>2025-06-05 16:51:33 -0500
committerAaditya Dhruv <[email protected]>2025-06-05 16:51:33 -0500
commit46d22e77d458b1e5cd9a9b17df67c63849574a95 (patch)
tree9f3b6bcf132fbf17078f11332a3041662ab1b651
Barebones rendering framework
-rw-r--r--.gitignore1
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml4
-rw-r--r--out.html1
-rw-r--r--src/main.rs13
-rw-r--r--src/types/elements.rs125
-rw-r--r--src/types/mod.rs1
7 files changed, 152 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ea8c4bf
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/target
diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644
index 0000000..9da8dd8
--- /dev/null
+++ b/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "palpad"
+version = "0.1.0"
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..76c96ac
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,4 @@
+[package]
+name = "palpad"
+version = "0.1.0"
+edition = "2021"
diff --git a/out.html b/out.html
new file mode 100644
index 0000000..6c70bcf
--- /dev/null
+++ b/out.html
@@ -0,0 +1 @@
+<html></html> \ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..585eff6
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,13 @@
+mod types;
+use std::fs::File;
+use std::io::prelude::*;
+
+use crate::types::elements;
+use crate::types::elements::Renderable;
+
+fn main() {
+ let doc = elements::HTML::new();
+ let doc = doc.render();
+ let mut file = File::create("out.html").unwrap();
+ file.write_all(doc.as_bytes()).unwrap();
+}
diff --git a/src/types/elements.rs b/src/types/elements.rs
new file mode 100644
index 0000000..0f766e4
--- /dev/null
+++ b/src/types/elements.rs
@@ -0,0 +1,125 @@
+pub trait Renderable {
+ fn render(&self) -> String;
+}
+
+//Body
+pub struct Body {
+ items: Vec<Box<dyn Renderable>>,
+}
+
+impl Body {
+ pub fn new() -> Self {
+ let _vec = Vec::<Box<dyn Renderable>>::new();
+ Body { items: _vec }
+ }
+}
+impl Renderable for Body {
+ fn render(&self) -> String {
+ let mut master = String::new();
+ let start_tag = "<body>";
+ let end_tag = "</body>";
+
+ master.push_str(&start_tag);
+ for child in &self.items {
+ let text = child.render();
+ master.push_str(text.as_str());
+ }
+ master.push_str(&end_tag);
+ master
+ }
+}
+
+//Paragraph
+pub struct Paragraph {
+ text: String,
+}
+
+impl Paragraph {
+ pub fn new() -> Self {
+ Paragraph { text: String::new() }
+ }
+}
+impl Renderable for Paragraph {
+ fn render(&self) -> String {
+ let mut master = String::new();
+ let start_tag = "<p>";
+ let end_tag = "</p>";
+
+ master.push_str(&start_tag);
+ master.push_str(&self.text);
+ master.push_str(&end_tag);
+ master
+ }
+}
+//Head
+pub struct Head {
+ text: String,
+}
+
+impl Head {
+ pub fn new() -> Self {
+ Head { text: String::new() }
+ }
+}
+impl Renderable for Head {
+ fn render(&self) -> String {
+ let mut master = String::new();
+ let start_tag = "<head>";
+ let end_tag = "</head>";
+
+ master.push_str(&start_tag);
+ master.push_str(&self.text);
+ master.push_str(&end_tag);
+ master
+ }
+}
+// Heading
+pub struct Heading {
+ text: String,
+ level: u8,
+}
+
+impl Heading {
+ pub fn new() -> Self {
+ Heading { text: String::new(), level: 1 }
+ }
+}
+impl Renderable for Heading {
+ fn render(&self) -> String {
+ let mut master = String::new();
+ let start_tag = format!("<h{}>", self.level);
+ let end_tag = format!("</h{}>", self.level);
+
+ master.push_str(&start_tag);
+ master.push_str(&self.text);
+ master.push_str(&end_tag);
+ master
+ }
+}
+
+// Heading
+pub struct HTML {
+ items: Vec<Box<dyn Renderable>>,
+}
+
+impl HTML {
+ pub fn new() -> Self {
+ let _vec = Vec::<Box<dyn Renderable>>::new();
+ HTML { items: _vec }
+ }
+}
+impl Renderable for HTML {
+ fn render(&self) -> String {
+ let mut master = String::new();
+ let start_tag = "<html>";
+ let end_tag = "</html>";
+
+ master.push_str(&start_tag);
+ for child in &self.items {
+ let text = child.render();
+ master.push_str(text.as_str());
+ }
+ master.push_str(&end_tag);
+ master
+ }
+}
diff --git a/src/types/mod.rs b/src/types/mod.rs
new file mode 100644
index 0000000..2da6a8c
--- /dev/null
+++ b/src/types/mod.rs
@@ -0,0 +1 @@
+pub mod elements;