use crate::attributes::Attributes;
use crate::content::BodyContent;
use crate::Container;
use crate::Html;
use crate::Table;
pub trait HtmlContainer: Html + Sized {
fn add_html<H: Html>(&mut self, html: H);
#[inline]
fn with_html<H: Html>(mut self, html: H) -> Self {
self.add_html(html);
self
}
#[inline]
fn add_container(&mut self, container: Container) {
self.add_html(container)
}
#[inline]
fn with_container(self, container: Container) -> Self {
self.with_html(container)
}
fn add_table(&mut self, table: Table) {
self.add_html(table);
}
fn with_table(self, table: Table) -> Self {
self.with_html(table)
}
fn add_header(&mut self, level: u8, text: impl ToString) {
let content = BodyContent::Header {
level,
content: text.to_string(),
attr: Attributes::default(),
};
self.add_html(content);
}
fn with_header(self, level: u8, text: impl ToString) -> Self {
let content = BodyContent::Header {
level,
content: text.to_string(),
attr: Attributes::default(),
};
self.with_html(content)
}
fn add_header_attr<A, S>(&mut self, level: u8, text: impl ToString, attr: A)
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = BodyContent::Header {
level,
content: text.to_string(),
attr: attr.into(),
};
self.add_html(content);
}
fn with_header_attr<A, S>(self, level: u8, text: impl ToString, attr: A) -> Self
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = BodyContent::Header {
level,
content: text.to_string(),
attr: attr.into(),
};
self.with_html(content)
}
fn add_image(&mut self, src: impl ToString, alt: impl ToString) {
let content = BodyContent::Image {
src: src.to_string(),
alt: alt.to_string(),
attr: Attributes::default(),
};
self.add_html(content);
}
fn with_image(self, src: impl ToString, alt: impl ToString) -> Self {
let content = BodyContent::Image {
src: src.to_string(),
alt: alt.to_string(),
attr: Attributes::default(),
};
self.with_html(content)
}
fn add_image_attr<A, S>(&mut self, src: impl ToString, alt: impl ToString, attr: A)
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = BodyContent::Image {
src: src.to_string(),
alt: alt.to_string(),
attr: attr.into(),
};
self.add_html(content);
}
fn with_image_attr<A, S>(self, src: impl ToString, alt: impl ToString, attr: A) -> Self
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = BodyContent::Image {
src: src.to_string(),
alt: alt.to_string(),
attr: attr.into(),
};
self.with_html(content)
}
fn add_link(&mut self, href: impl ToString, text: impl ToString) {
let content = BodyContent::Link {
href: href.to_string(),
content: text.to_string(),
attr: Attributes::default(),
};
self.add_html(content)
}
fn with_link(self, href: impl ToString, text: impl ToString) -> Self {
let content = BodyContent::Link {
href: href.to_string(),
content: text.to_string(),
attr: Attributes::default(),
};
self.with_html(content)
}
fn add_link_attr<A, S>(&mut self, href: impl ToString, text: impl ToString, attr: A)
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = BodyContent::Link {
href: href.to_string(),
content: text.to_string(),
attr: attr.into(),
};
self.add_html(content);
}
fn with_link_attr<A, S>(self, href: impl ToString, text: impl ToString, attr: A) -> Self
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = BodyContent::Link {
href: href.to_string(),
content: text.to_string(),
attr: attr.into(),
};
self.with_html(content)
}
fn add_paragraph(&mut self, text: impl ToString) {
let content = BodyContent::Paragraph {
content: text.to_string(),
attr: Attributes::default(),
};
self.add_html(content)
}
fn with_paragraph(self, text: impl ToString) -> Self {
let content = BodyContent::Paragraph {
content: text.to_string(),
attr: Attributes::default(),
};
self.with_html(content)
}
fn add_paragraph_attr<A, S>(&mut self, text: impl ToString, attr: A)
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = BodyContent::Paragraph {
content: text.to_string(),
attr: attr.into(),
};
self.add_html(content);
}
fn with_paragraph_attr<A, S>(self, text: impl ToString, attr: A) -> Self
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = BodyContent::Paragraph {
content: text.to_string(),
attr: attr.into(),
};
self.with_html(content)
}
fn add_preformatted(&mut self, text: impl ToString) {
let content = BodyContent::Preformatted {
content: text.to_string(),
attr: Attributes::default(),
};
self.add_html(content);
}
fn with_preformatted(self, text: impl ToString) -> Self {
let content = BodyContent::Preformatted {
content: text.to_string(),
attr: Attributes::default(),
};
self.with_html(content)
}
fn add_preformatted_attr<A, S>(&mut self, text: impl ToString, attr: A)
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = BodyContent::Preformatted {
content: text.to_string(),
attr: attr.into(),
};
self.add_html(content);
}
fn with_preformatted_attr<A, S>(self, text: impl ToString, attr: A) -> Self
where
A: IntoIterator<Item = (S, S)>,
S: ToString,
{
let content = BodyContent::Preformatted {
content: text.to_string(),
attr: attr.into(),
};
self.with_html(content)
}
fn add_raw(&mut self, content: impl ToString) {
self.add_html(BodyContent::Raw {
content: content.to_string(),
});
}
fn with_raw(self, content: impl ToString) -> Self {
self.with_html(BodyContent::Raw {
content: content.to_string(),
})
}
}