diff --git a/docx-core/src/documents/elements/delete.rs b/docx-core/src/documents/elements/delete.rs index 5dd75c3..85ea7b6 100644 --- a/docx-core/src/documents/elements/delete.rs +++ b/docx-core/src/documents/elements/delete.rs @@ -3,9 +3,9 @@ use crate::xml_builder::*; #[derive(Debug, Clone)] pub struct Delete { - author: String, - date: String, - run: Run, + pub author: String, + pub date: String, + pub run: Run, } impl Default for Delete { @@ -19,14 +19,26 @@ impl Default for Delete { } impl Delete { - pub fn new() -> Delete { - Default::default() + pub fn new(run: Run) -> Delete { + Self { + run, + ..Default::default() + } } - pub fn run(mut self, run: Run) -> Delete { self.run = run; self } + + pub fn author(mut self, author: impl Into) -> Delete { + self.author = author.into(); + self + } + + pub fn date(mut self, date: impl Into) -> Delete { + self.date = date.into(); + self + } } impl HistoryId for Delete {} @@ -51,7 +63,7 @@ mod tests { #[test] fn test_delete_default() { - let b = Delete::new().build(); + let b = Delete::new(Run::new()).build(); assert_eq!( str::from_utf8(&b).unwrap(), r#""# diff --git a/docx-core/src/documents/elements/insert.rs b/docx-core/src/documents/elements/insert.rs index 4c3becd..79178c8 100644 --- a/docx-core/src/documents/elements/insert.rs +++ b/docx-core/src/documents/elements/insert.rs @@ -3,9 +3,9 @@ use crate::xml_builder::*; #[derive(Debug, Clone)] pub struct Insert { - author: String, - date: String, - run: Run, + pub run: Run, + pub author: String, + pub date: String, } impl Default for Insert { @@ -19,12 +19,20 @@ impl Default for Insert { } impl Insert { - pub fn new() -> Insert { - Default::default() + pub fn new(run: Run) -> Insert { + Self { + run, + ..Default::default() + } } - pub fn run(mut self, run: Run) -> Insert { - self.run = run; + pub fn author(mut self, author: impl Into) -> Insert { + self.author = author.into(); + self + } + + pub fn date(mut self, date: impl Into) -> Insert { + self.date = date.into(); self } } @@ -51,7 +59,7 @@ mod tests { #[test] fn test_ins_default() { - let b = Insert::new().build(); + let b = Insert::new(Run::new()).build(); assert_eq!( str::from_utf8(&b).unwrap(), r#""# diff --git a/docx-core/tests/lib.rs b/docx-core/tests/lib.rs index ae33d28..9370d5e 100644 --- a/docx-core/tests/lib.rs +++ b/docx-core/tests/lib.rs @@ -223,8 +223,8 @@ pub fn history() -> Result<(), DocxError> { Docx::new() .add_paragraph( Paragraph::new() - .add_insert(Insert::new().run(Run::new().add_text("Hello"))) - .add_delete(Delete::new().run(Run::new().add_delete_text("World"))), + .add_insert(Insert::new(Run::new().add_text("Hello"))) + .add_delete(Delete::new(Run::new().add_delete_text("World"))), ) .build() .pack(file)?; diff --git a/docx-wasm/src/delete.rs b/docx-wasm/src/delete.rs index b80d1c7..0088896 100644 --- a/docx-wasm/src/delete.rs +++ b/docx-wasm/src/delete.rs @@ -7,12 +7,22 @@ use wasm_bindgen::prelude::*; pub struct Delete(docx_core::Delete); #[wasm_bindgen(js_name = createDelete)] -pub fn create_delete() -> Delete { - Delete(docx_core::Delete::new()) +pub fn create_delete(run: Run) -> Delete { + Delete(docx_core::Delete::new(run.take())) } impl Delete { pub fn take(self) -> docx_core::Delete { self.0 } + + pub fn author(mut self, author: String) -> Delete { + self.0.author = author; + self + } + + pub fn date(mut self, date: String) -> Delete { + self.0.date = date; + self + } } diff --git a/docx-wasm/src/insert.rs b/docx-wasm/src/insert.rs index aa2a149..fbed278 100644 --- a/docx-wasm/src/insert.rs +++ b/docx-wasm/src/insert.rs @@ -7,12 +7,22 @@ use wasm_bindgen::prelude::*; pub struct Insert(docx_core::Insert); #[wasm_bindgen(js_name = createInsert)] -pub fn create_insert() -> Insert { - Insert(docx_core::Insert::new()) +pub fn create_insert(run: Run) -> Insert { + Insert(docx_core::Insert::new(run.take())) } impl Insert { pub fn take(self) -> docx_core::Insert { self.0 } + + pub fn author(mut self, author: String) -> Insert { + self.0.author = author; + self + } + + pub fn date(mut self, date: String) -> Insert { + self.0.date = date; + self + } }