use super::{TableGrid, TableProperty, TableRow}; use crate::documents::BuildXML; use crate::types::*; use crate::xml_builder::*; #[derive(Debug, Clone)] pub struct Table { pub rows: Vec, pub grid: Vec, property: TableProperty, } impl Table { pub fn new(rows: Vec) -> Table { let property = TableProperty::new(); let grid = vec![]; Self { property, rows, grid, } } pub fn set_grid(mut self, grid: Vec) -> Table { self.grid = grid; self } pub fn indent(mut self, v: usize) -> Table { self.property = self.property.indent(v); self } pub fn align(mut self, v: TableAlignmentType) -> Table { self.property = self.property.align(v); self } } impl BuildXML for Table { fn build(&self) -> Vec { let grid = TableGrid::new(self.grid.clone()); let b = XMLBuilder::new() .open_table() .add_child(&self.property) .add_child(&grid) .add_children(&self.rows); b.close().build() } } #[cfg(test)] mod tests { use super::*; #[cfg(test)] use pretty_assertions::assert_eq; use std::str; #[test] fn test_table() { let b = Table::new(vec![TableRow::new(vec![])]).build(); assert_eq!( str::from_utf8(&b).unwrap(), r#" "# ); } #[test] fn test_table_grid() { let b = Table::new(vec![TableRow::new(vec![])]) .set_grid(vec![100, 200]) .build(); assert_eq!( str::from_utf8(&b).unwrap(), r#" "# ); } }