use super::{DocDefaults, Paragraph, Run, Style}; use crate::documents::BuildXML; use crate::xml_builder::*; use crate::StyleType; #[derive(Debug)] pub struct Document { paragraphs: Vec, } impl Document { pub fn new() -> Document { Default::default() } pub fn add_paragraph(mut self, p: Paragraph) -> Self { self.paragraphs.push(p); self } } impl Default for Document { fn default() -> Self { Self { paragraphs: Vec::new(), } } } impl BuildXML for Document { fn build(&self) -> Vec { let b = XMLBuilder::new(); b.declaration(Some(true)) .open_document() .open_body() .add_children(&self.paragraphs) .close() .close() .build() } } #[cfg(test)] mod tests { use super::*; #[cfg(test)] use pretty_assertions::assert_eq; use std::str; #[test] fn test_document() { let b = Document::new() .add_paragraph(Paragraph::new().add_run(Run::new("Hello"))) .build(); assert_eq!( str::from_utf8(&b).unwrap(), r#" Hello "# ); } }