use std::fmt::Write;
mod attributes;
mod tag;
mod html_trait;
pub use attributes::*;
use escapes::HtmlEscaper;
pub use tag::*;
pub use html_trait::*;
pub mod escapes;
pub mod tags;
pub use write_html_macro::html;
pub struct Empty;
pub struct Sum<A, B>(pub A, pub B);
pub trait HtmlEnv: Write + Sized {
fn write_html(&mut self, html: impl Html) -> Result<&mut Self, std::fmt::Error> {
html.write_html(self)?;
Ok(self)
}
fn doctype(&mut self) {
write!(self, "<!DOCTYPE html>").unwrap();
}
fn write_html_text<'s>(&'s mut self) -> HtmlEscaper<'s, Self> {
HtmlEscaper::new(self)
}
fn open_tag<'s, 't>(
&'s mut self,
tag: &'t str, compactability: Compactability
) -> Result<TagOpening<'s, 't, Self>, std::fmt::Error> {
TagOpening::<'s, 't, Self>::new(tag, self, compactability)
}
fn with_html_writer(self, f: impl FnOnce(&mut Self) -> std::fmt::Result) -> Result<Self, std::fmt::Error> {
let mut s = self;
f(&mut s)?;
Ok(s)
}
}
impl<W: Write> HtmlEnv for W {}
pub struct DefaultMeta;
impl Html for DefaultMeta {
fn write_html(self, env: &mut impl HtmlEnv) -> std::fmt::Result {
env
.write_html(tags::meta(
[
("http-equiv", "X-UA-Compatible"),
("content", "ie=edge")
],
Empty,
))?
.write_html(tags::meta(
[("charset", "UTF-8")],
Empty,
))?
.write_html(tags::meta(
[
("name", "viewport"),
("content", "width=device-width, initial-scale=1.0")
],
Empty,
)).map(|_| ())
}
}
pub struct Doctype;
impl Html for Doctype {
fn write_html(self, env: &mut impl HtmlEnv) -> std::fmt::Result {
env.doctype();
Ok(())
}
}