1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
//! provides DOM Document (root node) use crate::{Render, DomNode}; /// DOM Document Node (root node) /// /// # Example /// ``` /// // Use DomDocument as root node /// // Macro `domdoc!(..)` extracts DomNode::Document(DomDocument::new(vec![..])). /// /// use dom_renderer::*; /// /// let doc = domdoc!( /// doctype!("html"), /// elem!("head"; /// end_elem!("title"; "TITLE") /// ), /// end_elem!("body"; "BODY"), /// ); /// /// let expect = "<!DOCTYPE html><head><title>TITLE</title></head><body>BODY</body>"; /// assert_eq!(expect, doc.render()); #[derive(Debug, Clone)] pub struct DomDocument { pub nodes: Vec<DomNode>, } impl DomDocument { pub fn new(nodes: Vec<DomNode>) -> Self { DomDocument { nodes: nodes } } } impl Render for DomDocument { fn render(&self) -> String { self.nodes .iter() .map(|x| x.render()) .collect::<Vec<_>>() .join("") } }