docx_rs/documents/elements/
table_grid.rs1use crate::documents::BuildXML;
2use crate::types::*;
3use crate::xml_builder::*;
4use std::io::Write;
5
6#[derive(Debug, Clone)]
7pub struct TableGrid {
8 grid: Vec<usize>,
9}
10
11impl TableGrid {
12 pub fn new(grid: Vec<usize>) -> TableGrid {
13 TableGrid { grid }
14 }
15}
16
17impl BuildXML for TableGrid {
18 fn build_to<W: Write>(
19 &self,
20 stream: xml::writer::EventWriter<W>,
21 ) -> xml::writer::Result<xml::writer::EventWriter<W>> {
22 XMLBuilder::from(stream)
23 .open_table_grid()?
24 .apply_each(&self.grid, |g, b| b.grid_column(*g as i32, WidthType::Dxa))?
25 .close()?
26 .into_inner()
27 }
28}
29
30#[cfg(test)]
31mod tests {
32
33 use super::*;
34 #[cfg(test)]
35 use pretty_assertions::assert_eq;
36 use std::str;
37
38 #[test]
39 fn test_table_indent() {
40 let b = TableGrid::new(vec![100, 200]).build();
41 assert_eq!(
42 str::from_utf8(&b).unwrap(),
43 r#"<w:tblGrid><w:gridCol w:w="100" w:type="dxa" /><w:gridCol w:w="200" w:type="dxa" /></w:tblGrid>"#
44 );
45 }
46}