html_site_generator/html/
document.rs

1use crate::html::body::Body;
2use crate::html::head::Head;
3use crate::html::IntoHtmlNode;
4
5#[derive(Debug)]
6pub struct Document {
7    head: Head,
8    body: Body,
9}
10
11impl Document {
12    pub fn new(head: Head, body: Body) -> Self {
13        Document { head, body }
14    }
15}
16
17impl IntoHtmlNode for Document {
18    fn transform_into_html_node(&self, buffer: &mut dyn std::io::Write) -> anyhow::Result<()> {
19        writeln!(buffer, "<!DOCTYPE html>")?;
20        writeln!(buffer, "<html>")?;
21
22        self.head.transform_into_html_node(buffer)?;
23        self.body.transform_into_html_node(buffer)?;
24
25        writeln!(buffer, "</html>")?;
26
27        Ok(())
28    }
29}