feat: Add row
parent
23b422c25f
commit
f4a93bd4dd
|
@ -24,6 +24,8 @@ mod table_cell_width;
|
|||
mod table_grid;
|
||||
mod table_indent;
|
||||
mod table_property;
|
||||
mod table_row;
|
||||
mod table_row_property;
|
||||
mod table_width;
|
||||
mod text;
|
||||
|
||||
|
@ -53,5 +55,7 @@ pub use table_cell_width::*;
|
|||
pub use table_grid::*;
|
||||
pub use table_indent::*;
|
||||
pub use table_property::*;
|
||||
pub use table_row::*;
|
||||
pub use table_row_property::*;
|
||||
pub use table_width::*;
|
||||
pub use text::*;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use super::{Paragraph, Run, TableCellProperty};
|
||||
use super::{Paragraph, TableCellProperty};
|
||||
use crate::documents::BuildXML;
|
||||
use crate::xml_builder::*;
|
||||
|
||||
|
@ -14,8 +14,8 @@ pub enum TableCellContent {
|
|||
}
|
||||
|
||||
impl TableCell {
|
||||
pub fn new(w: usize) -> TableCell {
|
||||
let property = TableCellProperty::new(w);
|
||||
pub fn new() -> TableCell {
|
||||
let property = TableCellProperty::new();
|
||||
let contents = vec![];
|
||||
Self { property, contents }
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ impl BuildXML for TableCell {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use super::super::*;
|
||||
use super::*;
|
||||
#[cfg(test)]
|
||||
use pretty_assertions::assert_eq;
|
||||
|
@ -49,21 +50,21 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_cell() {
|
||||
let b = TableCell::new(200).build();
|
||||
let b = TableCell::new().build();
|
||||
assert_eq!(
|
||||
str::from_utf8(&b).unwrap(),
|
||||
r#"<w:tc><w:tcPr><w:tcW w:w="200" w:type="dxa" /><w:tcBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tcBorders></w:tcPr></w:tc>"#
|
||||
r#"<w:tc><w:tcPr><w:tcBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tcBorders></w:tcPr></w:tc>"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cell_add_p() {
|
||||
let b = TableCell::new(200)
|
||||
let b = TableCell::new()
|
||||
.add_paragraph(Paragraph::new().add_run(Run::new("Hello")))
|
||||
.build();
|
||||
assert_eq!(
|
||||
str::from_utf8(&b).unwrap(),
|
||||
r#"<w:tc><w:tcPr><w:tcW w:w="200" w:type="dxa" /><w:tcBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tcBorders></w:tcPr><w:p><w:pPr><w:pStyle w:val="Normal" /><w:rPr /></w:pPr><w:r><w:rPr /><w:t xml:space="preserve">Hello</w:t></w:r></w:p></w:tc>"#
|
||||
r#"<w:tc><w:tcPr><w:tcBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tcBorders></w:tcPr><w:p><w:pPr><w:pStyle w:val="Normal" /><w:rPr /></w:pPr><w:r><w:rPr /><w:t xml:space="preserve">Hello</w:t></w:r></w:p></w:tc>"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
use super::{TableCellBorders, TableCellWidth};
|
||||
use super::TableCellBorders;
|
||||
use crate::documents::BuildXML;
|
||||
use crate::types::*;
|
||||
// use crate::types::*;
|
||||
use crate::xml_builder::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TableCellProperty {
|
||||
width: TableCellWidth,
|
||||
// width: TableCellWidth,
|
||||
borders: TableCellBorders,
|
||||
}
|
||||
|
||||
impl TableCellProperty {
|
||||
pub fn new(w: usize) -> TableCellProperty {
|
||||
pub fn new() -> TableCellProperty {
|
||||
TableCellProperty {
|
||||
width: TableCellWidth::new(w, WidthType::DXA),
|
||||
// width: TableCellWidth::new(w, WidthType::DXA),
|
||||
borders: TableCellBorders::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn width(mut self, v: usize) -> TableCellProperty {
|
||||
self.width = TableCellWidth::new(v, WidthType::DXA);
|
||||
self
|
||||
}
|
||||
// pub fn width(mut self, v: usize) -> TableCellProperty {
|
||||
// self.width = TableCellWidth::new(v, WidthType::DXA);
|
||||
// self
|
||||
// }
|
||||
}
|
||||
|
||||
impl BuildXML for TableCellProperty {
|
||||
fn build(&self) -> Vec<u8> {
|
||||
XMLBuilder::new()
|
||||
.open_table_cell_property()
|
||||
.add_child(&self.width)
|
||||
// .add_child(&self.width)
|
||||
.add_child(&self.borders)
|
||||
.close()
|
||||
.build()
|
||||
|
@ -44,11 +44,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_default() {
|
||||
let c = TableCellProperty::new(200);
|
||||
let c = TableCellProperty::new();
|
||||
let b = c.build();
|
||||
assert_eq!(
|
||||
str::from_utf8(&b).unwrap(),
|
||||
r#"<w:tcPr><w:tcW w:w="200" w:type="dxa" /><w:tcBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tcBorders></w:tcPr>"#
|
||||
r#"<w:tcPr><w:tcBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tcBorders></w:tcPr>"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
use super::{TableCell, TableRowProperty};
|
||||
use crate::documents::BuildXML;
|
||||
use crate::xml_builder::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TableRow {
|
||||
property: TableRowProperty,
|
||||
cells: Vec<TableCell>,
|
||||
}
|
||||
|
||||
impl TableRow {
|
||||
pub fn new(cells: Vec<TableCell>) -> TableRow {
|
||||
let property = TableRowProperty::new();
|
||||
Self { property, cells }
|
||||
}
|
||||
}
|
||||
|
||||
impl BuildXML for TableRow {
|
||||
fn build(&self) -> Vec<u8> {
|
||||
let b = XMLBuilder::new()
|
||||
.open_table_row()
|
||||
.add_child(&self.property)
|
||||
.add_children(&self.cells);
|
||||
b.close().build()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use super::*;
|
||||
#[cfg(test)]
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::str;
|
||||
|
||||
#[test]
|
||||
fn test_row() {
|
||||
let b = TableRow::new(vec![TableCell::new()]).build();
|
||||
assert_eq!(
|
||||
str::from_utf8(&b).unwrap(),
|
||||
r#"<w:tr><w:trPr /><w:tc><w:tcPr><w:tcBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tcBorders></w:tcPr></w:tc></w:tr>"#
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
use crate::documents::BuildXML;
|
||||
use crate::xml_builder::*;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TableRowProperty {}
|
||||
|
||||
impl TableRowProperty {
|
||||
pub fn new() -> TableRowProperty {
|
||||
TableRowProperty {}
|
||||
}
|
||||
}
|
||||
|
||||
impl BuildXML for TableRowProperty {
|
||||
fn build(&self) -> Vec<u8> {
|
||||
XMLBuilder::new().open_table_row_property().close().build()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use super::*;
|
||||
#[cfg(test)]
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::str;
|
||||
|
||||
#[test]
|
||||
fn test_default() {
|
||||
let b = TableRowProperty::new().build();
|
||||
assert_eq!(str::from_utf8(&b).unwrap(), r#"<w:trPr />"#);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue