151 lines
3.1 KiB
Rust
151 lines
3.1 KiB
Rust
use crate::html::Render;
|
|
|
|
#[allow(non_camel_case_types)]
|
|
pub(crate) struct h1 {
|
|
text: String,
|
|
}
|
|
|
|
impl Render for h1 {
|
|
fn render(&self) -> String {
|
|
format!("<h1>{}</h1>", self.text)
|
|
}
|
|
}
|
|
|
|
impl h1 {
|
|
pub(crate) fn new(text: String) -> Self {
|
|
Self { text }
|
|
}
|
|
}
|
|
|
|
#[allow(non_camel_case_types)]
|
|
pub(crate) struct h2 {
|
|
text: String,
|
|
}
|
|
|
|
impl Render for h2 {
|
|
fn render(&self) -> String {
|
|
format!("<h2>{}</h2>", self.text)
|
|
}
|
|
}
|
|
|
|
impl h2 {
|
|
pub(crate) fn new(text: String) -> Self {
|
|
Self { text }
|
|
}
|
|
}
|
|
|
|
#[allow(non_camel_case_types)]
|
|
pub(crate) struct link {
|
|
rel: &'static str,
|
|
href: &'static str,
|
|
}
|
|
|
|
impl Render for link {
|
|
fn render(&self) -> String {
|
|
format!("<link rel=\"{}\" href=\"{}\">", self.rel, self.href)
|
|
}
|
|
}
|
|
|
|
impl link {
|
|
pub(crate) fn new(rel: &'static str, href: &'static str) -> Self {
|
|
Self { rel, href }
|
|
}
|
|
}
|
|
|
|
#[allow(non_camel_case_types)]
|
|
pub(crate) struct div {
|
|
id: &'static str,
|
|
classes: Vec<&'static str>,
|
|
content: Vec<Box<dyn Render>>,
|
|
}
|
|
|
|
impl Render for div {
|
|
fn render(&self) -> String {
|
|
let classes = self.classes.join(" ");
|
|
format!(
|
|
"<div id=\"{}\" class=\"{}\">{}</div>",
|
|
self.id,
|
|
classes,
|
|
self.content.render()
|
|
)
|
|
}
|
|
}
|
|
|
|
impl div {
|
|
pub(crate) fn new(id: &'static str, classes: Vec<&'static str>) -> Self {
|
|
Self {
|
|
id,
|
|
classes,
|
|
content: vec![],
|
|
}
|
|
}
|
|
|
|
pub(crate) fn append_element(&mut self, element: impl Render + 'static) {
|
|
self.content.push(Box::new(element));
|
|
}
|
|
}
|
|
|
|
#[allow(non_camel_case_types)]
|
|
pub(crate) struct p {
|
|
id: &'static str,
|
|
classes: Vec<&'static str>,
|
|
text: String
|
|
}
|
|
|
|
impl Render for p {
|
|
fn render(&self) -> String {
|
|
let classes = self.classes.join(" ");
|
|
format!("<p id=\"{}\" class=\"{}\">{}</p>", self.id, classes, self.text)
|
|
}
|
|
}
|
|
|
|
impl p {
|
|
pub(crate) fn new(id: &'static str, classes: Vec<&'static str>, text: String) -> Self {
|
|
Self {
|
|
id,
|
|
classes,
|
|
text
|
|
}
|
|
}
|
|
}
|
|
|
|
#[allow(non_camel_case_types)]
|
|
pub(crate) struct img {
|
|
id: &'static str,
|
|
classes: Vec<&'static str>,
|
|
src: &'static str,
|
|
}
|
|
|
|
impl Render for img {
|
|
fn render(&self) -> String {
|
|
let classes = self.classes.join(" ");
|
|
format!("<img id=\"{}\" class=\"{}\" src=\"{}\">", self.id, classes, self.src)
|
|
}
|
|
}
|
|
|
|
impl img {
|
|
pub(crate) fn new(id: &'static str, classes: Vec<&'static str>, src: &'static str) -> Self {
|
|
Self { id, classes, src }
|
|
}
|
|
}
|
|
|
|
#[allow(non_camel_case_types)]
|
|
pub(crate) struct a {
|
|
id: &'static str,
|
|
classes: Vec<&'static str>,
|
|
href: &'static str,
|
|
text: String,
|
|
}
|
|
|
|
impl Render for a {
|
|
fn render(&self) -> String {
|
|
let classes = self.classes.join(" ");
|
|
format!("<a id=\"{}\" class=\"{}\" href=\"{}\">{}</a>", self.id, classes, self.href, self.text)
|
|
}
|
|
}
|
|
|
|
impl a {
|
|
pub(crate) fn new(id: &'static str, classes: Vec<&'static str>, href: &'static str, text: String) -> Self {
|
|
Self { id, classes, href, text }
|
|
}
|
|
} |