File tree Expand file tree Collapse file tree 5 files changed +61
-21
lines changed Expand file tree Collapse file tree 5 files changed +61
-21
lines changed Original file line number Diff line number Diff line change @@ -3,9 +3,9 @@ use crate::xml_builder::*;
33
44#[ derive( Debug , Clone ) ]
55pub struct Delete {
6- author : String ,
7- date : String ,
8- run : Run ,
6+ pub author : String ,
7+ pub date : String ,
8+ pub run : Run ,
99}
1010
1111impl Default for Delete {
@@ -19,14 +19,26 @@ impl Default for Delete {
1919}
2020
2121impl Delete {
22- pub fn new ( ) -> Delete {
23- Default :: default ( )
22+ pub fn new ( run : Run ) -> Delete {
23+ Self {
24+ run,
25+ ..Default :: default ( )
26+ }
2427 }
25-
2628 pub fn run ( mut self , run : Run ) -> Delete {
2729 self . run = run;
2830 self
2931 }
32+
33+ pub fn author ( mut self , author : impl Into < String > ) -> Delete {
34+ self . author = author. into ( ) ;
35+ self
36+ }
37+
38+ pub fn date ( mut self , date : impl Into < String > ) -> Delete {
39+ self . date = date. into ( ) ;
40+ self
41+ }
3042}
3143
3244impl HistoryId for Delete { }
@@ -51,7 +63,7 @@ mod tests {
5163
5264 #[ test]
5365 fn test_delete_default ( ) {
54- let b = Delete :: new ( ) . build ( ) ;
66+ let b = Delete :: new ( Run :: new ( ) ) . build ( ) ;
5567 assert_eq ! (
5668 str :: from_utf8( & b) . unwrap( ) ,
5769 r#"<w:del w:id="123" w:author="unnamed" w:date="1970-01-01T00:00:00Z"><w:r><w:rPr /></w:r></w:del>"#
Original file line number Diff line number Diff line change @@ -3,9 +3,9 @@ use crate::xml_builder::*;
33
44#[ derive( Debug , Clone ) ]
55pub struct Insert {
6- author : String ,
7- date : String ,
8- run : Run ,
6+ pub run : Run ,
7+ pub author : String ,
8+ pub date : String ,
99}
1010
1111impl Default for Insert {
@@ -19,12 +19,20 @@ impl Default for Insert {
1919}
2020
2121impl Insert {
22- pub fn new ( ) -> Insert {
23- Default :: default ( )
22+ pub fn new ( run : Run ) -> Insert {
23+ Self {
24+ run,
25+ ..Default :: default ( )
26+ }
27+ }
28+
29+ pub fn author ( mut self , author : impl Into < String > ) -> Insert {
30+ self . author = author. into ( ) ;
31+ self
2432 }
2533
26- pub fn run ( mut self , run : Run ) -> Insert {
27- self . run = run ;
34+ pub fn date ( mut self , date : impl Into < String > ) -> Insert {
35+ self . date = date . into ( ) ;
2836 self
2937 }
3038}
@@ -51,7 +59,7 @@ mod tests {
5159
5260 #[ test]
5361 fn test_ins_default ( ) {
54- let b = Insert :: new ( ) . build ( ) ;
62+ let b = Insert :: new ( Run :: new ( ) ) . build ( ) ;
5563 assert_eq ! (
5664 str :: from_utf8( & b) . unwrap( ) ,
5765 r#"<w:ins w:id="123" w:author="unnamed" w:date="1970-01-01T00:00:00Z"><w:r><w:rPr /></w:r></w:ins>"#
Original file line number Diff line number Diff line change @@ -223,8 +223,8 @@ pub fn history() -> Result<(), DocxError> {
223223 Docx :: new ( )
224224 . add_paragraph (
225225 Paragraph :: new ( )
226- . add_insert ( Insert :: new ( ) . run ( Run :: new ( ) . add_text ( "Hello" ) ) )
227- . add_delete ( Delete :: new ( ) . run ( Run :: new ( ) . add_delete_text ( "World" ) ) ) ,
226+ . add_insert ( Insert :: new ( Run :: new ( ) . add_text ( "Hello" ) ) )
227+ . add_delete ( Delete :: new ( Run :: new ( ) . add_delete_text ( "World" ) ) ) ,
228228 )
229229 . build ( )
230230 . pack ( file) ?;
Original file line number Diff line number Diff line change @@ -7,12 +7,22 @@ use wasm_bindgen::prelude::*;
77pub struct Delete ( docx_core:: Delete ) ;
88
99#[ wasm_bindgen( js_name = createDelete) ]
10- pub fn create_delete ( ) -> Delete {
11- Delete ( docx_core:: Delete :: new ( ) )
10+ pub fn create_delete ( run : Run ) -> Delete {
11+ Delete ( docx_core:: Delete :: new ( run . take ( ) ) )
1212}
1313
1414impl Delete {
1515 pub fn take ( self ) -> docx_core:: Delete {
1616 self . 0
1717 }
18+
19+ pub fn author ( mut self , author : String ) -> Delete {
20+ self . 0 . author = author;
21+ self
22+ }
23+
24+ pub fn date ( mut self , date : String ) -> Delete {
25+ self . 0 . date = date;
26+ self
27+ }
1828}
Original file line number Diff line number Diff line change @@ -7,12 +7,22 @@ use wasm_bindgen::prelude::*;
77pub struct Insert ( docx_core:: Insert ) ;
88
99#[ wasm_bindgen( js_name = createInsert) ]
10- pub fn create_insert ( ) -> Insert {
11- Insert ( docx_core:: Insert :: new ( ) )
10+ pub fn create_insert ( run : Run ) -> Insert {
11+ Insert ( docx_core:: Insert :: new ( run . take ( ) ) )
1212}
1313
1414impl Insert {
1515 pub fn take ( self ) -> docx_core:: Insert {
1616 self . 0
1717 }
18+
19+ pub fn author ( mut self , author : String ) -> Insert {
20+ self . 0 . author = author;
21+ self
22+ }
23+
24+ pub fn date ( mut self , date : String ) -> Insert {
25+ self . 0 . date = date;
26+ self
27+ }
1828}
You can’t perform that action at this time.
0 commit comments