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,77 +6,30 @@ describe OpenXml::Docx::Properties::PageSize do
6
6
  it_should_use tag: :pgSz, name: "page_size"
7
7
 
8
8
  for_attribute(:code) do
9
- with_value(1) do
10
- it_should_assign_successfully
11
- it_should_output "<w:pgSz w:code=\"1\"/>"
12
- end
13
-
14
- with_value(-10) do
15
- it_should_assign_successfully
16
- it_should_output "<w:pgSz w:code=\"-10\"/>"
17
- end
18
-
19
- with_value(122.2) do
20
- it_should_raise_an_exception
21
- end
22
-
23
- with_value(:cool) do
24
- it_should_raise_an_exception
25
- end
9
+ values = [1, -10]
10
+ it_should_assign_and_output_xml values
11
+ it_should_not_allow_floats
12
+ it_should_not_allow_invalid_value
26
13
  end
27
14
 
28
15
  for_attribute(:height) do
29
- with_value(1) do
30
- it_should_assign_successfully
31
- it_should_output "<w:pgSz w:h=\"1\"/>"
32
- end
33
-
34
- with_value(-10) do
35
- it_should_raise_an_exception
36
- end
37
-
38
- with_value(122.2) do
39
- it_should_raise_an_exception
40
- end
41
-
42
- with_value(:cool) do
43
- it_should_raise_an_exception
44
- end
16
+ it_should_assign_and_output_xml 1
17
+ it_should_not_allow_negative_numbers
18
+ it_should_not_allow_floats
19
+ it_should_not_allow_invalid_value
45
20
  end
46
21
 
47
22
  for_attribute(:orientation) do
48
- with_value(:portrait) do
49
- it_should_assign_successfully
50
- it_should_output "<w:pgSz w:orient=\"portrait\"/>"
51
- end
52
-
53
- with_value(:landscape) do
54
- it_should_assign_successfully
55
- it_should_output "<w:pgSz w:orient=\"landscape\"/>"
56
- end
57
-
58
- with_value(:somethingWeird) do
59
- it_should_raise_an_exception
60
- end
23
+ values = %i(portrait landscape)
24
+ it_should_assign_and_output_xml values
25
+ it_should_not_allow_invalid_value
61
26
  end
62
27
 
63
28
  for_attribute(:width) do
64
- with_value(1) do
65
- it_should_assign_successfully
66
- it_should_output "<w:pgSz w:w=\"1\"/>"
67
- end
68
-
69
- with_value(-10) do
70
- it_should_raise_an_exception
71
- end
72
-
73
- with_value(122.2) do
74
- it_should_raise_an_exception
75
- end
76
-
77
- with_value(:cool) do
78
- it_should_raise_an_exception
79
- end
29
+ it_should_assign_and_output_xml 1
30
+ it_should_not_allow_negative_numbers
31
+ it_should_not_allow_floats
32
+ it_should_not_allow_invalid_value
80
33
  end
81
34
 
82
35
  with_no_attributes_set do
@@ -6,43 +6,17 @@ describe OpenXml::Docx::Properties::PaperSource do
6
6
  it_should_use tag: :paperSrc, name: "paper_source"
7
7
 
8
8
  for_attribute(:first) do
9
- with_value(1) do
10
- it_should_assign_successfully
11
- it_should_output "<w:paperSrc w:first=\"1\"/>"
12
- end
13
-
14
- with_value(-1) do
15
- it_should_assign_successfully
16
- it_should_output "<w:paperSrc w:first=\"-1\"/>"
17
- end
18
-
19
- with_value(1234.4) do
20
- it_should_raise_an_exception
21
- end
22
-
23
- with_value(:one_million) do
24
- it_should_raise_an_exception
25
- end
9
+ values = [1, -1]
10
+ it_should_assign_and_output_xml values
11
+ it_should_not_allow_floats
12
+ it_should_not_allow_invalid_value
26
13
  end
27
14
 
28
15
  for_attribute(:other) do
29
- with_value(1) do
30
- it_should_assign_successfully
31
- it_should_output "<w:paperSrc w:other=\"1\"/>"
32
- end
33
-
34
- with_value(-1) do
35
- it_should_assign_successfully
36
- it_should_output "<w:paperSrc w:other=\"-1\"/>"
37
- end
38
-
39
- with_value(1234.4) do
40
- it_should_raise_an_exception
41
- end
42
-
43
- with_value(:one_million) do
44
- it_should_raise_an_exception
45
- end
16
+ values = [1, -1]
17
+ it_should_assign_and_output_xml values
18
+ it_should_not_allow_floats
19
+ it_should_not_allow_invalid_value
46
20
  end
47
21
 
48
22
  with_no_attributes_set do
@@ -6,122 +6,51 @@ describe OpenXml::Docx::Properties::Shading do
6
6
  it_should_use tag: :shd, name: "shading"
7
7
 
8
8
  for_attribute(:color) do
9
- with_value("4F81BD") do
10
- it_should_assign_successfully
11
- it_should_output "<w:shd w:color=\"4F81BD\"/>"
12
- end
13
-
14
- with_value(:auto) do
15
- it_should_assign_successfully
16
- it_should_output "<w:shd w:color=\"auto\"/>"
17
- end
18
-
19
- with_value("green") do
20
- it_should_raise_an_exception
21
- end
9
+ values = ["4F818D", :auto]
10
+ it_should_assign_and_output_xml values
11
+ it_should_not_allow_invalid_value
22
12
  end
23
13
 
24
14
  for_attribute(:fill) do
25
- with_value("4F81BD") do
26
- it_should_assign_successfully
27
- it_should_output "<w:shd w:fill=\"4F81BD\"/>"
28
- end
29
-
30
- with_value(:auto) do
31
- it_should_assign_successfully
32
- it_should_output "<w:shd w:fill=\"auto\"/>"
33
- end
34
-
35
- with_value("green") do
36
- it_should_raise_an_exception
37
- end
15
+ values = ["4F818D", :auto]
16
+ it_should_assign_and_output_xml values
17
+ it_should_not_allow_invalid_value
38
18
  end
39
19
 
40
20
  for_attribute(:theme_color) do
41
- with_value(:hyperlink) do
42
- it_should_assign_successfully
43
- it_should_output "<w:shd w:themeColor=\"hyperlink\"/>"
44
- end
45
-
46
- with_value(:lens_flare) do
47
- it_should_raise_an_exception
48
- end
21
+ it_should_assign_and_output_xml :hyperlink
22
+ it_should_not_allow_invalid_value
49
23
  end
50
24
 
51
25
  for_attribute(:theme_fill) do
52
- with_value(:hyperlink) do
53
- it_should_assign_successfully
54
- it_should_output "<w:shd w:themeFill=\"hyperlink\"/>"
55
- end
56
-
57
- with_value(:lens_flare) do
58
- it_should_raise_an_exception
59
- end
26
+ it_should_assign_and_output_xml :hyperlink
27
+ it_should_not_allow_invalid_value
60
28
  end
61
29
 
62
30
  for_attribute(:theme_fill_shade) do
63
- with_value("BF") do
64
- it_should_assign_successfully
65
- it_should_output "<w:shd w:themeFillShade=\"BF\"/>"
66
- end
67
-
68
- with_value(:dark) do
69
- it_should_raise_an_exception
70
- end
31
+ it_should_assign_and_output_xml "BF"
32
+ it_should_not_allow_invalid_value
71
33
  end
72
34
 
73
35
  for_attribute(:theme_fill_tint) do
74
- with_value("BF") do
75
- it_should_assign_successfully
76
- it_should_output "<w:shd w:themeFillTint=\"BF\"/>"
77
- end
78
-
79
- with_value(:pink) do
80
- it_should_raise_an_exception
81
- end
36
+ it_should_assign_and_output_xml "BF"
37
+ it_should_not_allow_invalid_value
82
38
  end
83
39
 
84
40
  for_attribute(:theme_shade) do
85
- with_value("BF") do
86
- it_should_assign_successfully
87
- it_should_output "<w:shd w:themeShade=\"BF\"/>"
88
- end
89
-
90
- with_value(:dark) do
91
- it_should_raise_an_exception
92
- end
41
+ it_should_assign_and_output_xml "BF"
42
+ it_should_not_allow_invalid_value
93
43
  end
94
44
 
95
45
  for_attribute(:theme_tint) do
96
- with_value("BF") do
97
- it_should_assign_successfully
98
- it_should_output "<w:shd w:themeTint=\"BF\"/>"
99
- end
100
-
101
- with_value(:pink) do
102
- it_should_raise_an_exception
103
- end
46
+ it_should_assign_and_output_xml "BF"
47
+ it_should_not_allow_invalid_value
104
48
  end
105
49
 
106
50
  for_attribute(:pattern) do
107
- with_value(:pct90) do
108
- it_should_assign_successfully
109
- it_should_output "<w:shd w:val=\"pct90\"/>"
110
- end
111
-
112
- with_value(:solid) do
113
- it_should_assign_successfully
114
- it_should_output "<w:shd w:val=\"solid\"/>"
115
- end
116
-
117
- with_value(:vertStripe) do
118
- it_should_assign_successfully
119
- it_should_output "<w:shd w:val=\"vertStripe\"/>"
120
- end
121
-
122
- with_value(:somethingIJustMadeUp) do
123
- it_should_raise_an_exception
124
- end
51
+ values = %i(pct90 solid vertStripe)
52
+ it_should_assign_and_output_xml values
53
+ it_should_not_allow_invalid_value
125
54
  end
126
55
 
127
56
  with_no_attributes_set do
@@ -6,146 +6,54 @@ describe OpenXml::Docx::Properties::Spacing do
6
6
  it_should_use tag: :spacing, name: "spacing"
7
7
 
8
8
  for_attribute(:after) do
9
- with_value(24) do
10
- it_should_assign_successfully
11
- it_should_output "<w:spacing w:after=\"24\"/>"
12
- end
13
-
14
- with_value(-24) do
15
- it_should_raise_an_exception
16
- end
17
-
18
- with_value(:big) do
19
- it_should_raise_an_exception
20
- end
9
+ it_should_assign_and_output_xml 24
10
+ it_should_not_allow_negative_numbers
11
+ it_should_not_allow_invalid_value
21
12
  end
22
13
 
23
14
  for_attribute(:after_auto) do
24
- with_value(:on) do
25
- it_should_assign_successfully
26
- it_should_output "<w:spacing w:afterAutospacing=\"on\"/>"
27
- end
28
-
29
- with_value(:off) do
30
- it_should_assign_successfully
31
- it_should_output "<w:spacing w:afterAutospacing=\"off\"/>"
32
- end
33
-
34
- with_value(:on_and_off) do
35
- it_should_raise_an_exception
36
- end
15
+ values = %i(on off)
16
+ it_should_assign_and_output_xml values
17
+ it_should_not_allow_invalid_value
37
18
  end
38
19
 
39
20
  for_attribute(:after_lines) do
40
- with_value(24) do
41
- it_should_assign_successfully
42
- it_should_output "<w:spacing w:afterLines=\"24\"/>"
43
- end
44
-
45
- with_value(-24) do
46
- it_should_assign_successfully
47
- it_should_output "<w:spacing w:afterLines=\"-24\"/>"
48
- end
49
-
50
- with_value(2.56) do
51
- it_should_raise_an_exception
52
- end
53
-
54
- with_value(:big) do
55
- it_should_raise_an_exception
56
- end
21
+ values = [24, -24]
22
+ it_should_assign_and_output_xml values
23
+ it_should_not_allow_invalid_value
24
+ it_should_not_allow_floats
57
25
  end
58
26
 
59
27
  for_attribute(:before) do
60
- with_value(24) do
61
- it_should_assign_successfully
62
- it_should_output "<w:spacing w:before=\"24\"/>"
63
- end
64
-
65
- with_value(-24) do
66
- it_should_raise_an_exception
67
- end
68
-
69
- with_value(:big) do
70
- it_should_raise_an_exception
71
- end
28
+ it_should_assign_and_output_xml 24
29
+ it_should_not_allow_invalid_value
30
+ it_should_not_allow_negative_numbers
72
31
  end
73
32
 
74
33
  for_attribute(:before_auto) do
75
- with_value(:on) do
76
- it_should_assign_successfully
77
- it_should_output "<w:spacing w:beforeAutospacing=\"on\"/>"
78
- end
79
-
80
- with_value(:off) do
81
- it_should_assign_successfully
82
- it_should_output "<w:spacing w:beforeAutospacing=\"off\"/>"
83
- end
84
-
85
- with_value(:on_and_off) do
86
- it_should_raise_an_exception
87
- end
34
+ values = %i(on off)
35
+ it_should_assign_and_output_xml values
36
+ it_should_not_allow_invalid_value
88
37
  end
89
38
 
90
39
  for_attribute(:before_lines) do
91
- with_value(24) do
92
- it_should_assign_successfully
93
- it_should_output "<w:spacing w:beforeLines=\"24\"/>"
94
- end
95
-
96
- with_value(-24) do
97
- it_should_assign_successfully
98
- it_should_output "<w:spacing w:beforeLines=\"-24\"/>"
99
- end
100
-
101
- with_value(2.56) do
102
- it_should_raise_an_exception
103
- end
104
-
105
- with_value(:big) do
106
- it_should_raise_an_exception
107
- end
40
+ values = [24, -24]
41
+ it_should_assign_and_output_xml values
42
+ it_should_not_allow_invalid_value
43
+ it_should_not_allow_floats
108
44
  end
109
45
 
110
46
  for_attribute(:line) do
111
- with_value(24) do
112
- it_should_assign_successfully
113
- it_should_output "<w:spacing w:line=\"24\"/>"
114
- end
115
-
116
- with_value(-24) do
117
- it_should_assign_successfully
118
- it_should_output "<w:spacing w:line=\"-24\"/>"
119
- end
120
-
121
- with_value(2.56) do
122
- it_should_raise_an_exception
123
- end
124
-
125
- with_value(:big) do
126
- it_should_raise_an_exception
127
- end
47
+ values = [24, -24]
48
+ it_should_assign_and_output_xml values
49
+ it_should_not_allow_invalid_value
50
+ it_should_not_allow_floats
128
51
  end
129
52
 
130
53
  for_attribute(:line_rule) do
131
- with_value(:atLeast) do
132
- it_should_assign_successfully
133
- it_should_output "<w:spacing w:lineRule=\"atLeast\"/>"
134
- end
135
-
136
- with_value(:auto) do
137
- it_should_assign_successfully
138
- it_should_output "<w:spacing w:lineRule=\"auto\"/>"
139
- end
140
-
141
- with_value(:exact) do
142
- it_should_assign_successfully
143
- it_should_output "<w:spacing w:lineRule=\"exact\"/>"
144
- end
145
-
146
- with_value(:something) do
147
- it_should_raise_an_exception
148
- end
54
+ values = %i(atLeast auto exact)
55
+ it_should_assign_and_output_xml values
56
+ it_should_not_allow_invalid_value
149
57
  end
150
58
 
151
59
  with_no_attributes_set do