use crate::html::Render; pub(crate) struct Heading { level: u8, id: String, text: String, classes: Vec, } impl Render for Heading { fn render(&self) -> String { let classes = self.classes.join(" "); format!( "{}", self.level, self.id, classes, self.text, self.level ) } } impl Heading { pub(crate) fn builder() -> HeadingBuilder { HeadingBuilder::new() } } pub(crate) struct HeadingBuilder { level: Option, id: Option, text: Option, classes: Option>, } impl HeadingBuilder { pub(crate) fn new() -> Self { Self { level: None, id: None, text: None, classes: None, } } pub(crate) fn level(self, level: u8) -> Self { Self { level: Some(level), ..self } } pub(crate) fn id(self, id: T) -> Self where T: Into, { Self { id: Some(id.into()), ..self } } pub(crate) fn text(self, text: T) -> Self where T: Into, { Self { text: Some(text.into()), ..self } } pub(crate) fn classes(self, classes: Vec) -> Self where T: Into, { Self { classes: Some(classes.into_iter().map(|x| x.into()).collect()), ..self } } pub(crate) fn build(self) -> Heading { let level = self.level.unwrap_or(1); let id = self.id.unwrap_or(String::new()); let text = self.text.unwrap_or(String::new()); let classes = self.classes.unwrap_or(Vec::new()); Heading { level, id, text, classes, } } } 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 builder() -> LinkBuilder { LinkBuilder::new() } } pub(crate) struct LinkBuilder { rel: Option, href: Option, } impl LinkBuilder { pub(crate) fn new() -> Self { Self { rel: None, href: None, } } pub(crate) fn rel(self, rel: T) -> Self where T: Into, { Self { rel: Some(rel.into()), ..self } } pub(crate) fn href(self, href: T) -> Self where T: Into, { Self { href: Some(href.into()), ..self } } pub(crate) fn build(self) -> Link { let rel = self.rel.unwrap_or(String::new()); let href = self.href.unwrap_or(String::new()); Link { rel, href } } } pub(crate) struct Paragraph { id: String, classes: Vec, text: String, } impl Render for Paragraph { fn render(&self) -> String { let classes = self.classes.join(" "); format!( "

{}

", self.id, classes, self.text ) } } impl Paragraph { pub(crate) fn builder() -> ParagraphBuilder { ParagraphBuilder::new() } } pub(crate) struct ParagraphBuilder { id: Option, classes: Option>, text: Option, } impl ParagraphBuilder { pub(crate) fn new() -> Self { Self { id: None, classes: None, text: None, } } pub(crate) fn id(self, id: T) -> Self where T: Into, { Self { id: Some(id.into()), ..self } } pub(crate) fn classes(self, classes: Vec) -> Self where T: Into, { Self { classes: Some(classes.into_iter().map(|x| x.into()).collect()), ..self } } pub(crate) fn text(self, text: T) -> Self where T: Into, { Self { text: Some(text.into()), ..self } } pub(crate) fn build(self) -> Paragraph { let id = self.id.unwrap_or(String::new()); let classes = self.classes.unwrap_or(Vec::new()); let text = self.text.unwrap_or(String::new()); Paragraph { id, classes, text } } } pub(crate) struct Image { id: String, classes: Vec, src: String, } impl Render for Image { fn render(&self) -> String { let classes = self.classes.join(" "); format!( "", self.id, classes, self.src ) } } impl Image { pub(crate) fn builder() -> ImageBuilder { ImageBuilder::new() } } pub(crate) struct ImageBuilder { id: Option, classes: Option>, src: Option, } impl ImageBuilder { pub(crate) fn new() -> Self { Self { id: None, classes: None, src: None, } } pub(crate) fn id(self, id: T) -> Self where T: Into, { Self { id: Some(id.into()), ..self } } pub(crate) fn classes(self, classes: Vec) -> Self where T: Into, { Self { classes: Some(classes.into_iter().map(|x| x.into()).collect()), ..self } } pub(crate) fn src(self, src: T) -> Self where T: Into, { Self { src: Some(src.into()), ..self } } pub(crate) fn build(self) -> Image { let id = self.id.unwrap_or(String::new()); let classes = self.classes.unwrap_or(Vec::new()); let src = self.src.unwrap_or(String::new()); Image { id, classes, src } } } pub(crate) struct Anchor { id: String, classes: Vec, href: String, text: String, } impl Render for Anchor { fn render(&self) -> String { let classes = self.classes.join(" "); format!( "{}", self.id, classes, self.href, self.text ) } } impl Anchor { pub(crate) fn builder() -> AnchorBuilder { AnchorBuilder::new() } } pub(crate) struct AnchorBuilder { id: Option, classes: Option>, href: Option, text: Option, } impl AnchorBuilder { pub(crate) fn new() -> Self { Self { id: None, classes: None, href: None, text: None, } } pub(crate) fn id(self, id: T) -> Self where T: Into, { Self { id: Some(id.into()), ..self } } pub(crate) fn classes(self, classes: Vec) -> Self where T: Into, { Self { classes: Some(classes.into_iter().map(|x| x.into()).collect()), ..self } } pub(crate) fn href(self, href: T) -> Self where T: Into, { Self { href: Some(href.into()), ..self } } pub(crate) fn text(self, text: T) -> Self where T: Into, { Self { text: Some(text.into()), ..self } } pub(crate) fn build(self) -> Anchor { let id = self.id.unwrap_or(String::new()); let classes = self.classes.unwrap_or(Vec::new()); let href = self.href.unwrap_or(String::new()); let text = self.text.unwrap_or(String::new()); Anchor { id, classes, href, text, } } } pub(crate) struct Iframe { id: String, classes: Vec, src: String, title: String, width: usize, height: usize, } impl Render for Iframe { fn render(&self) -> String { let classes = self.classes.join(" "); format!( "", self.id, classes, self.title, self.width, self.height, self.src ) } } pub(crate) struct IframeBuilder { id: Option, classes: Option>, src: Option, title: Option, width: Option, height: Option, } impl IframeBuilder { pub(crate) fn new() -> Self { Self { id: None, classes: None, src: None, title: None, width: None, height: None, } } pub(crate) fn id(self, id: T) -> Self where T: Into, { Self { id: Some(id.into()), ..self } } pub(crate) fn classes(self, classes: Vec) -> Self where T: Into, { Self { classes: Some(classes.into_iter().map(|x| x.into()).collect()), ..self } } pub(crate) fn src(self, src: T) -> Self where T: Into, { Self { src: Some(src.into()), ..self } } pub(crate) fn title(self, title: T) -> Self where T: Into, { Self { title: Some(title.into()), ..self } } pub(crate) fn width(self, width: usize) -> Self { Self { width: Some(width), ..self } } pub(crate) fn height(self, height: usize) -> Self { Self { height: Some(height), ..self } } pub(crate) fn build(self) -> Iframe { let id = self.id.unwrap_or(String::new()); let classes = self.classes.unwrap_or(Vec::new()); let title = self.title.unwrap_or(String::new()); let width = self.width.unwrap_or(0); let height = self.height.unwrap_or(0); let src = self.src.unwrap_or(String::new()); Iframe { id, title, classes, width, height, src, } } }