use crate::html::Render;
#[allow(non_camel_case_types)]
pub(crate) struct h1 {
text: String,
}
impl Render for h1 {
fn render(&self) -> String {
format!("
{}
", self.text)
}
}
impl h1 {
pub(crate) fn new(text: T) -> Self
where
T: Into,
{
Self { text: text.into() }
}
}
#[allow(non_camel_case_types)]
pub(crate) struct h2 {
text: String,
}
impl Render for h2 {
fn render(&self) -> String {
format!("{}
", self.text)
}
}
impl h2 {
pub(crate) fn new(text: T) -> Self
where
T: Into,
{
Self { text: text.into() }
}
}
#[allow(non_camel_case_types)]
pub(crate) struct link {
rel: String,
href: String,
}
impl Render for link {
fn render(&self) -> String {
format!("", self.rel, self.href)
}
}
impl link {
pub(crate) fn new(rel: T, href: U) -> Self
where
T: Into,
U: Into,
{
Self {
rel: rel.into(),
href: href.into(),
}
}
}
#[allow(non_camel_case_types)]
pub(crate) struct div {
id: String,
classes: Vec,
content: Vec>,
}
impl Render for div {
fn render(&self) -> String {
let classes = self.classes.join(" ");
format!(
"{}
",
self.id,
classes,
self.content.render()
)
}
}
impl div {
pub(crate) fn new(id: T, classes: Vec) -> Self
where
T: Into,
U: Into + Clone,
{
Self {
id: id.into(),
classes: classes.iter().map(|x| x.clone().into()).collect(),
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: String,
classes: Vec,
text: String,
}
impl Render for p {
fn render(&self) -> String {
let classes = self.classes.join(" ");
format!(
"{}
",
self.id, classes, self.text
)
}
}
impl p {
pub(crate) fn new(id: T, classes: Vec, text: V) -> Self
where
T: Into,
U: Into + Clone,
V: Into,
{
Self {
id: id.into(),
classes: classes.iter().map(|x| x.clone().into()).collect(),
text: text.into(),
}
}
}
#[allow(non_camel_case_types)]
pub(crate) struct img {
id: String,
classes: Vec,
src: String,
}
impl Render for img {
fn render(&self) -> String {
let classes = self.classes.join(" ");
format!(
"
",
self.id, classes, self.src
)
}
}
impl img {
pub(crate) fn new(id: T, classes: Vec, src: V) -> Self
where
T: Into,
U: Into + Clone,
V: Into,
{
Self {
id: id.into(),
classes: classes.iter().map(|x| x.clone().into()).collect(),
src: src.into(),
}
}
}
#[allow(non_camel_case_types)]
pub(crate) struct a {
id: String,
classes: Vec,
href: String,
text: String,
}
impl Render for a {
fn render(&self) -> String {
let classes = self.classes.join(" ");
format!(
"{}",
self.id, classes, self.href, self.text
)
}
}
impl a {
pub(crate) fn new(id: T, classes: Vec, href: V, text: W) -> Self
where
T: Into,
U: Into + Clone,
V: Into,
W: Into,
{
Self {
id: id.into(),
classes: classes.iter().map(|x| x.clone().into()).collect(),
href: href.into(),
text: text.into(),
}
}
}