openxml-docx 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/{example → examples/base} +1 -1
  4. data/examples/table +68 -0
  5. data/lib/openxml/docx/elements/grid_column.rb +12 -0
  6. data/lib/openxml/docx/elements/table.rb +30 -0
  7. data/lib/openxml/docx/elements/table_cell.rb +26 -0
  8. data/lib/openxml/docx/elements/table_grid.rb +10 -0
  9. data/lib/openxml/docx/elements/table_row.rb +36 -0
  10. data/lib/openxml/docx/package.rb +3 -0
  11. data/lib/openxml/docx/properties.rb +2 -0
  12. data/lib/openxml/docx/properties/base_property.rb +14 -0
  13. data/lib/openxml/docx/properties/cant_split.rb +8 -0
  14. data/lib/openxml/docx/properties/columns.rb +2 -0
  15. data/lib/openxml/docx/properties/grid_after.rb +8 -0
  16. data/lib/openxml/docx/properties/grid_before.rb +8 -0
  17. data/lib/openxml/docx/properties/grid_span.rb +8 -0
  18. data/lib/openxml/docx/properties/header.rb +8 -0
  19. data/lib/openxml/docx/properties/headers.rb +12 -0
  20. data/lib/openxml/docx/properties/hidden.rb +8 -0
  21. data/lib/openxml/docx/properties/hide_mark.rb +8 -0
  22. data/lib/openxml/docx/properties/no_wrap.rb +8 -0
  23. data/lib/openxml/docx/properties/table_border.rb +25 -0
  24. data/lib/openxml/docx/properties/table_borders.rb +13 -0
  25. data/lib/openxml/docx/properties/table_caption.rb +10 -0
  26. data/lib/openxml/docx/properties/table_cell_border.rb +25 -0
  27. data/lib/openxml/docx/properties/table_cell_borders.rb +13 -0
  28. data/lib/openxml/docx/properties/table_cell_cell_margin.rb +13 -0
  29. data/lib/openxml/docx/properties/table_cell_fit_text.rb +9 -0
  30. data/lib/openxml/docx/properties/table_cell_margin.rb +13 -0
  31. data/lib/openxml/docx/properties/table_cell_margins.rb +13 -0
  32. data/lib/openxml/docx/properties/table_cell_spacing.rb +13 -0
  33. data/lib/openxml/docx/properties/table_cell_width.rb +13 -0
  34. data/lib/openxml/docx/properties/table_description.rb +10 -0
  35. data/lib/openxml/docx/properties/table_header.rb +10 -0
  36. data/lib/openxml/docx/properties/table_indent.rb +13 -0
  37. data/lib/openxml/docx/properties/table_layout.rb +14 -0
  38. data/lib/openxml/docx/properties/table_look.rb +17 -0
  39. data/lib/openxml/docx/properties/table_overlap.rb +14 -0
  40. data/lib/openxml/docx/properties/table_p_pr.rb +41 -0
  41. data/lib/openxml/docx/properties/table_style.rb +10 -0
  42. data/lib/openxml/docx/properties/table_width.rb +13 -0
  43. data/lib/openxml/docx/properties/tr_height.rb +19 -0
  44. data/lib/openxml/docx/properties/valign.rb +13 -0
  45. data/lib/openxml/docx/properties/wafter.rb +12 -0
  46. data/lib/openxml/docx/properties/wbefore.rb +12 -0
  47. data/lib/openxml/docx/properties/width_property.rb +17 -0
  48. data/lib/openxml/docx/style.rb +17 -7
  49. data/lib/openxml/docx/version.rb +1 -1
  50. data/spec/elements/grid_column_spec.rb +15 -0
  51. data/spec/elements/table_cell_spec.rb +15 -0
  52. data/spec/elements/table_grid_spec.rb +17 -0
  53. data/spec/elements/table_row_spec.rb +18 -0
  54. data/spec/elements/table_spec.rb +21 -0
  55. data/spec/properties/border_spec.rb +21 -95
  56. data/spec/properties/cant_split_spec.rb +23 -0
  57. data/spec/properties/color_spec.rb +9 -29
  58. data/spec/properties/column_spec.rb +6 -22
  59. data/spec/properties/columns_spec.rb +4 -14
  60. data/spec/properties/conditional_formatting_spec.rb +12 -108
  61. data/spec/properties/document_grid_spec.rb +12 -53
  62. data/spec/properties/east_asian_layout_spec.rb +14 -74
  63. data/spec/properties/font_spec.rb +35 -238
  64. data/spec/properties/frame_spec.rb +48 -285
  65. data/spec/properties/grid_after_spec.rb +26 -0
  66. data/spec/properties/grid_before_spec.rb +26 -0
  67. data/spec/properties/grid_span_spec.rb +24 -0
  68. data/spec/properties/header_spec.rb +17 -0
  69. data/spec/properties/headers_spec.rb +39 -0
  70. data/spec/properties/hidden_spec.rb +23 -0
  71. data/spec/properties/hide_mark_spec.rb +23 -0
  72. data/spec/properties/indentation_spec.rb +32 -136
  73. data/spec/properties/language_spec.rb +3 -12
  74. data/spec/properties/latent_styles_exception_spec.rb +7 -22
  75. data/spec/properties/latent_styles_spec.rb +5 -18
  76. data/spec/properties/line_numbering_spec.rb +15 -68
  77. data/spec/properties/manual_width_spec.rb +8 -33
  78. data/spec/properties/no_wrap_spec.rb +23 -0
  79. data/spec/properties/numbering_spec.rb +4 -13
  80. data/spec/properties/page_margins_spec.rb +28 -114
  81. data/spec/properties/page_numbering_spec.rb +26 -367
  82. data/spec/properties/page_size_spec.rb +15 -62
  83. data/spec/properties/paper_source_spec.rb +8 -34
  84. data/spec/properties/shading_spec.rb +21 -92
  85. data/spec/properties/spacing_spec.rb +27 -119
  86. data/spec/properties/table_border_spec.rb +119 -0
  87. data/spec/properties/table_borders_spec.rb +41 -0
  88. data/spec/properties/table_caption_spec.rb +17 -0
  89. data/spec/properties/table_cell_border_spec.rb +119 -0
  90. data/spec/properties/table_cell_borders_spec.rb +40 -0
  91. data/spec/properties/table_cell_cell_margin_spec.rb +46 -0
  92. data/spec/properties/table_cell_fit_text.rb +23 -0
  93. data/spec/properties/table_cell_margin_spec.rb +40 -0
  94. data/spec/properties/table_cell_margins_spec.rb +46 -0
  95. data/spec/properties/table_cell_spacing_spec.rb +21 -0
  96. data/spec/properties/table_cell_width.rb +21 -0
  97. data/spec/properties/table_description_spec.rb +17 -0
  98. data/spec/properties/table_header_spec.rb +23 -0
  99. data/spec/properties/table_indent_spec.rb +43 -0
  100. data/spec/properties/table_layout_spec.rb +22 -0
  101. data/spec/properties/table_look_spec.rb +38 -0
  102. data/spec/properties/table_overlap_spec.rb +22 -0
  103. data/spec/properties/table_p_pr_spec.rb +68 -0
  104. data/spec/properties/table_row_height.rb +20 -0
  105. data/spec/properties/table_style_spec.rb +17 -0
  106. data/spec/properties/table_width_spec.rb +21 -0
  107. data/spec/properties/underline_spec.rb +14 -130
  108. data/spec/properties/valign_spec.rb +19 -0
  109. data/spec/properties/wafter_spec.rb +21 -0
  110. data/spec/properties/wbefore_spec.rb +21 -0
  111. data/spec/support/data/elements/grid_column_element.xml +4 -0
  112. data/spec/support/data/elements/table_cell_element.xml +8 -0
  113. data/spec/support/data/elements/table_element.xml +18 -0
  114. data/spec/support/data/elements/table_grid_element.xml +6 -0
  115. data/spec/support/data/elements/table_row_element.xml +13 -0
  116. data/spec/support/property_test_macros.rb +61 -0
  117. metadata +86 -3
@@ -6,333 +6,96 @@ describe OpenXml::Docx::Properties::Frame do
6
6
  it_should_use tag: :framePr, name: "frame"
7
7
 
8
8
  for_attribute(:anchor_lock) do
9
- with_value(true) do
10
- it_should_assign_successfully
11
- it_should_output "<w:framePr w:anchorLock=\"true\"/>"
12
- end
13
-
14
- with_value(false) do
15
- it_should_assign_successfully
16
- it_should_output ""
17
- end
18
-
19
- with_value(:maybe) do
20
- it_should_raise_an_exception
21
- end
9
+ it_should_behave_like_a_boolean_attribute
10
+ it_should_not_allow_invalid_value
22
11
  end
23
12
 
24
13
  for_attribute(:drop_cap) do
25
- with_value(:drop) do
26
- it_should_assign_successfully
27
- it_should_output "<w:framePr w:dropCap=\"drop\"/>"
28
- end
29
-
30
- with_value(:margin) do
31
- it_should_assign_successfully
32
- it_should_output "<w:framePr w:dropCap=\"margin\"/>"
33
- end
34
-
35
- with_value(:none) do
36
- it_should_assign_successfully
37
- it_should_output "<w:framePr w:dropCap=\"none\"/>"
38
- end
39
-
40
- with_value(:bad) do
41
- it_should_raise_an_exception
42
- end
14
+ values = %i(drop margin none)
15
+ it_should_assign_and_output_xml values
16
+ it_should_not_allow_invalid_value
43
17
  end
44
18
 
45
19
  for_attribute(:height) do
46
- with_value(24) do
47
- it_should_assign_successfully
48
- it_should_output "<w:framePr w:h=\"24\"/>"
49
- end
50
-
51
- with_value(-24) do
52
- it_should_raise_an_exception
53
- end
54
-
55
- with_value(:big) do
56
- it_should_raise_an_exception
57
- end
20
+ it_should_assign_and_output_xml 24
21
+ it_should_not_allow_negative_numbers
22
+ it_should_not_allow_invalid_value
58
23
  end
59
24
 
60
25
  for_attribute(:horizontal_anchor) do
61
- with_value(:margin) do
62
- it_should_assign_successfully
63
- it_should_output "<w:framePr w:hAnchor=\"margin\"/>"
64
- end
65
-
66
- with_value(:page) do
67
- it_should_assign_successfully
68
- it_should_output "<w:framePr w:hAnchor=\"page\"/>"
69
- end
70
-
71
- with_value(:text) do
72
- it_should_assign_successfully
73
- it_should_output "<w:framePr w:hAnchor=\"text\"/>"
74
- end
26
+ values = %i(margin page text)
27
+ it_should_assign_and_output_xml values
28
+ it_should_not_allow_invalid_value
75
29
  end
76
30
 
77
31
  for_attribute(:height_rule) do
78
- with_value(:atLeast) do
79
- it_should_assign_successfully
80
- it_should_output "<w:framePr w:hRule=\"atLeast\"/>"
81
- end
82
-
83
- with_value(:auto) do
84
- it_should_assign_successfully
85
- it_should_output "<w:framePr w:hRule=\"auto\"/>"
86
- end
87
-
88
- with_value(:exact) do
89
- it_should_assign_successfully
90
- it_should_output "<w:framePr w:hRule=\"exact\"/>"
91
- end
92
-
93
- with_value(:something_bad) do
94
- it_should_raise_an_exception
95
- end
32
+ values = %i(atLeast auto exact)
33
+ it_should_assign_and_output_xml values
34
+ it_should_not_allow_invalid_value
96
35
  end
97
36
 
98
37
  for_attribute(:horizontal_padding) do
99
- with_value(24) do
100
- it_should_assign_successfully
101
- it_should_output "<w:framePr w:hSpace=\"24\"/>"
102
- end
103
-
104
- with_value(-23) do
105
- it_should_raise_an_exception
106
- end
107
-
108
- with_value(19.4) do
109
- it_should_raise_an_exception
110
- end
111
-
112
- with_value(:two) do
113
- it_should_raise_an_exception
114
- end
38
+ it_should_assign_and_output_xml 24
39
+ it_should_not_allow_negative_numbers
40
+ it_should_not_allow_floats
41
+ it_should_not_allow_invalid_value
115
42
  end
116
43
 
117
44
  for_attribute(:lines) do
118
- with_value(24) do
119
- it_should_assign_successfully
120
- it_should_output "<w:framePr w:lines=\"24\"/>"
121
- end
122
-
123
- with_value(-23) do
124
- it_should_raise_an_exception
125
- end
126
-
127
- with_value(19.4) do
128
- it_should_raise_an_exception
129
- end
130
-
131
- with_value(:two) do
132
- it_should_raise_an_exception
133
- end
45
+ it_should_assign_and_output_xml 24
46
+ it_should_not_allow_negative_numbers
47
+ it_should_not_allow_floats
48
+ it_should_not_allow_invalid_value
134
49
  end
135
50
 
136
51
  for_attribute(:vertical_anchor) do
137
- with_value(:margin) do
138
- it_should_assign_successfully
139
- it_should_output "<w:framePr w:vAnchor=\"margin\"/>"
140
- end
141
-
142
- with_value(:page) do
143
- it_should_assign_successfully
144
- it_should_output "<w:framePr w:vAnchor=\"page\"/>"
145
- end
146
-
147
- with_value(:text) do
148
- it_should_assign_successfully
149
- it_should_output "<w:framePr w:vAnchor=\"text\"/>"
150
- end
151
-
152
- with_value(:something_bad) do
153
- it_should_raise_an_exception
154
- end
52
+ values = %i(margin page text)
53
+ it_should_assign_and_output_xml values
54
+ it_should_not_allow_invalid_value
155
55
  end
156
56
 
157
57
  for_attribute(:vertical_padding) do
158
- with_value(24) do
159
- it_should_assign_successfully
160
- it_should_output "<w:framePr w:vSpace=\"24\"/>"
161
- end
162
-
163
- with_value(-23) do
164
- it_should_raise_an_exception
165
- end
166
-
167
- with_value(19.4) do
168
- it_should_raise_an_exception
169
- end
170
-
171
- with_value(:two) do
172
- it_should_raise_an_exception
173
- end
58
+ it_should_assign_and_output_xml 24
59
+ it_should_not_allow_negative_numbers
60
+ it_should_not_allow_floats
61
+ it_should_not_allow_invalid_value
174
62
  end
175
63
 
176
64
  for_attribute(:width) do
177
- with_value(24) do
178
- it_should_assign_successfully
179
- it_should_output "<w:framePr w:w=\"24\"/>"
180
- end
181
-
182
- with_value(-23) do
183
- it_should_raise_an_exception
184
- end
185
-
186
- with_value(19.4) do
187
- it_should_raise_an_exception
188
- end
189
-
190
- with_value(:two) do
191
- it_should_raise_an_exception
192
- end
65
+ it_should_assign_and_output_xml 24
66
+ it_should_not_allow_negative_numbers
67
+ it_should_not_allow_floats
68
+ it_should_not_allow_invalid_value
193
69
  end
194
70
 
195
71
  for_attribute(:wrap) do
196
- with_value(:around) do
197
- it_should_assign_successfully
198
- it_should_output "<w:framePr w:wrap=\"around\"/>"
199
- end
200
-
201
- with_value(:auto) do
202
- it_should_assign_successfully
203
- it_should_output "<w:framePr w:wrap=\"auto\"/>"
204
- end
205
-
206
- with_value(:none) do
207
- it_should_assign_successfully
208
- it_should_output "<w:framePr w:wrap=\"none\"/>"
209
- end
210
-
211
- with_value(:notBeside) do
212
- it_should_assign_successfully
213
- it_should_output "<w:framePr w:wrap=\"notBeside\"/>"
214
- end
215
-
216
- with_value(:through) do
217
- it_should_assign_successfully
218
- it_should_output "<w:framePr w:wrap=\"through\"/>"
219
- end
220
-
221
- with_value(:tight) do
222
- it_should_assign_successfully
223
- it_should_output "<w:framePr w:wrap=\"tight\"/>"
224
- end
225
-
226
- with_value(:something_bad) do
227
- it_should_raise_an_exception
228
- end
72
+ values = %i(around auto none notBeside through tight)
73
+ it_should_assign_and_output_xml values
74
+ it_should_not_allow_invalid_value
229
75
  end
230
76
 
231
77
  for_attribute(:horizontal_position) do
232
- with_value(24) do
233
- it_should_assign_successfully
234
- it_should_output "<w:framePr w:x=\"24\"/>"
235
- end
236
-
237
- with_value(-23) do
238
- it_should_assign_successfully
239
- it_should_output "<w:framePr w:x=\"-23\"/>"
240
- end
241
-
242
- with_value(19.4) do
243
- it_should_raise_an_exception
244
- end
245
-
246
- with_value(:two) do
247
- it_should_raise_an_exception
248
- end
78
+ it_should_assign_and_output_xml 24
79
+ it_should_not_allow_floats
80
+ it_should_not_allow_invalid_value
249
81
  end
250
82
 
251
83
  for_attribute(:relative_horizontal_position) do
252
- with_value(:center) do
253
- it_should_assign_successfully
254
- it_should_output "<w:framePr w:xAlign=\"center\"/>"
255
- end
256
-
257
- with_value(:inside) do
258
- it_should_assign_successfully
259
- it_should_output "<w:framePr w:xAlign=\"inside\"/>"
260
- end
261
-
262
- with_value(:left) do
263
- it_should_assign_successfully
264
- it_should_output "<w:framePr w:xAlign=\"left\"/>"
265
- end
266
-
267
- with_value(:outside) do
268
- it_should_assign_successfully
269
- it_should_output "<w:framePr w:xAlign=\"outside\"/>"
270
- end
271
-
272
- with_value(:right) do
273
- it_should_assign_successfully
274
- it_should_output "<w:framePr w:xAlign=\"right\"/>"
275
- end
276
-
277
- with_value(:something_bad) do
278
- it_should_raise_an_exception
279
- end
84
+ values = %i(center inside left outside right)
85
+ it_should_assign_and_output_xml values
86
+ it_should_not_allow_invalid_value
280
87
  end
281
88
 
282
89
  for_attribute(:vertical_position) do
283
- with_value(24) do
284
- it_should_assign_successfully
285
- it_should_output "<w:framePr w:y=\"24\"/>"
286
- end
287
-
288
- with_value(-23) do
289
- it_should_assign_successfully
290
- it_should_output "<w:framePr w:y=\"-23\"/>"
291
- end
292
-
293
- with_value(19.4) do
294
- it_should_raise_an_exception
295
- end
296
-
297
- with_value(:two) do
298
- it_should_raise_an_exception
299
- end
90
+ it_should_assign_and_output_xml 24
91
+ it_should_not_allow_floats
92
+ it_should_not_allow_invalid_value
300
93
  end
301
94
 
302
95
  for_attribute(:relative_vertical_position) do
303
- with_value(:bottom) do
304
- it_should_assign_successfully
305
- it_should_output "<w:framePr w:yAlign=\"bottom\"/>"
306
- end
307
-
308
- with_value(:center) do
309
- it_should_assign_successfully
310
- it_should_output "<w:framePr w:yAlign=\"center\"/>"
311
- end
312
-
313
- with_value(:inline) do
314
- it_should_assign_successfully
315
- it_should_output "<w:framePr w:yAlign=\"inline\"/>"
316
- end
317
-
318
- with_value(:inside) do
319
- it_should_assign_successfully
320
- it_should_output "<w:framePr w:yAlign=\"inside\"/>"
321
- end
322
-
323
- with_value(:outside) do
324
- it_should_assign_successfully
325
- it_should_output "<w:framePr w:yAlign=\"outside\"/>"
326
- end
327
-
328
- with_value(:top) do
329
- it_should_assign_successfully
330
- it_should_output "<w:framePr w:yAlign=\"top\"/>"
331
- end
332
-
333
- with_value(:something_bad) do
334
- it_should_raise_an_exception
335
- end
96
+ values = %i(bottom center inline inside outside top)
97
+ it_should_assign_and_output_xml values
98
+ it_should_not_allow_invalid_value
336
99
  end
337
100
 
338
101
  end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Properties::GridAfter do
4
+ include ValuePropertyTestMacros
5
+
6
+ it_should_use tag: :gridAfter, name: "grid_after", value: 1
7
+
8
+ with_value(400) do
9
+ it_should_work
10
+ it_should_output "<w:gridAfter w:val=\"400\"/>"
11
+ end
12
+
13
+ with_value(-230) do
14
+ it_should_work
15
+ it_should_output "<w:gridAfter w:val=\"-230\"/>"
16
+ end
17
+
18
+ with_value(4.2) do
19
+ it_should_not_work
20
+ end
21
+
22
+ with_value(:twelve) do
23
+ it_should_not_work
24
+ end
25
+
26
+ end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Properties::GridBefore do
4
+ include ValuePropertyTestMacros
5
+
6
+ it_should_use tag: :gridBefore, name: "grid_before", value: 1
7
+
8
+ with_value(400) do
9
+ it_should_work
10
+ it_should_output "<w:gridBefore w:val=\"400\"/>"
11
+ end
12
+
13
+ with_value(-230) do
14
+ it_should_work
15
+ it_should_output "<w:gridBefore w:val=\"-230\"/>"
16
+ end
17
+
18
+ with_value(4.2) do
19
+ it_should_not_work
20
+ end
21
+
22
+ with_value(:twelve) do
23
+ it_should_not_work
24
+ end
25
+
26
+ end
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Properties::GridSpan do
4
+ include ValuePropertyTestMacros
5
+
6
+ it_should_use tag: :gridSpan, name: "grid_span", value: 22
7
+
8
+ with_value(20) do
9
+ it_should_work
10
+ it_should_output "<w:gridSpan w:val=\"20\"/>"
11
+ end
12
+
13
+ with_value(-20) do
14
+ it_should_not_work
15
+ end
16
+
17
+ with_value(23.1) do
18
+ it_should_not_work
19
+ end
20
+
21
+ with_value(:big) do
22
+ it_should_not_work
23
+ end
24
+ end