use crate::HtmlElement;
use std::fmt;
use std::fmt::Display;
#[derive(Debug, Default, Clone)]
pub struct HtmlBodyElement {
children: Vec<HtmlElement>,
}
impl HtmlBodyElement {
pub fn new() -> Self {
Self::default()
}
pub fn child(mut self, child: impl Into<HtmlElement>) -> Self {
self.add_child(child);
self
}
pub fn add_child(&mut self, child: impl Into<HtmlElement>) {
self.children.push(child.into());
}
}
impl Display for HtmlBodyElement {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", <&HtmlBodyElement as Into<HtmlElement>>::into(self))
}
}
impl From<HtmlBodyElement> for HtmlElement {
fn from(value: HtmlBodyElement) -> Self {
let mut body = HtmlElement::new("body").no_indent();
for child in value.children {
body.add_child(child);
}
body
}
}
impl From<&HtmlBodyElement> for HtmlElement {
fn from(value: &HtmlBodyElement) -> Self {
Self::from(value.clone())
}
}