openxml-docx 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Elements::TableRow do
4
+ include ElementTestMacros
5
+
6
+ context "after creation" do
7
+ before(:each) do
8
+ @instance = described_class.new
9
+ instance.hidden = true
10
+ cell = OpenXml::Docx::Elements::TableCell.new
11
+ cell.no_wrap = true
12
+ instance << cell
13
+ end
14
+
15
+ it_should_output_correct_xml
16
+ end
17
+
18
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Elements::Table do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :tbl, name: "table"
7
+
8
+ before(:each) do
9
+ @instance = described_class.new
10
+ instance.cant_split = true
11
+ row = OpenXml::Docx::Elements::TableRow.new
12
+ row.hidden = true
13
+ cell = OpenXml::Docx::Elements::TableCell.new
14
+ cell.no_wrap = true
15
+ row << cell
16
+ instance << row
17
+ end
18
+
19
+ it_should_output_correct_xml
20
+
21
+ end
@@ -32,125 +32,51 @@ describe OpenXml::Docx::Properties::Border do
32
32
  end
33
33
 
34
34
  for_attribute(:color) do
35
- with_value("4F81BD") do
36
- it_should_assign_successfully
37
- it_should_output "<w:bdr w:color=\"4F81BD\"/>"
38
- end
39
-
40
- with_value(:auto) do
41
- it_should_assign_successfully
42
- it_should_output "<w:bdr w:color=\"auto\"/>"
43
- end
44
-
45
- with_value(:green) do
46
- it_should_raise_an_exception
47
- end
35
+ values = ["4581BD", :auto]
36
+ it_should_assign_and_output_xml values
37
+ it_should_not_allow_invalid_value
48
38
  end
49
39
 
50
40
  for_attribute(:frame) do
51
- with_value(true) do
52
- it_should_assign_successfully
53
- it_should_output "<w:bdr w:frame=\"true\"/>"
54
- end
55
-
56
- with_value(false) do
57
- it_should_assign_successfully
58
- it_should_output ""
59
- end
60
-
61
- with_value(:yep) do
62
- it_should_raise_an_exception
63
- end
41
+ it_should_behave_like_a_boolean_attribute
42
+ it_should_not_allow_invalid_value
64
43
  end
65
44
 
66
45
  for_attribute(:shadow) do
67
- with_value(true) do
68
- it_should_assign_successfully
69
- it_should_output "<w:bdr w:shadow=\"true\"/>"
70
- end
71
-
72
- with_value(false) do
73
- it_should_assign_successfully
74
- it_should_output ""
75
- end
76
-
77
- with_value(:yep) do
78
- it_should_raise_an_exception
79
- end
46
+ it_should_behave_like_a_boolean_attribute
47
+ it_should_not_allow_invalid_value
80
48
  end
81
49
 
82
50
  for_attribute(:size) do
83
- with_value(24) do
84
- it_should_assign_successfully
85
- it_should_output "<w:bdr w:sz=\"24\"/>"
86
- end
87
-
88
- with_value(-24) do
89
- it_should_raise_an_exception
90
- end
91
-
92
- with_value(:big) do
93
- it_should_raise_an_exception
94
- end
51
+ it_should_assign_and_output_xml 24
52
+ it_should_not_allow_negative_numbers
53
+ it_should_not_allow_invalid_value
95
54
  end
96
55
 
97
56
  for_attribute(:space) do
98
- with_value(24) do
99
- it_should_assign_successfully
100
- it_should_output "<w:bdr w:space=\"24\"/>"
101
- end
102
-
103
- with_value(-24) do
104
- it_should_raise_an_exception
105
- end
106
-
107
- with_value(:big) do
108
- it_should_raise_an_exception
109
- end
57
+ it_should_assign_and_output_xml 24
58
+ it_should_not_allow_negative_numbers
59
+ it_should_not_allow_invalid_value
110
60
  end
111
61
 
112
62
  for_attribute(:theme_color) do
113
- with_value(:hyperlink) do
114
- it_should_assign_successfully
115
- it_should_output "<w:bdr w:themeColor=\"hyperlink\"/>"
116
- end
117
-
118
- with_value(:lens_flare) do
119
- it_should_raise_an_exception
120
- end
63
+ it_should_assign_and_output_xml :hyperlink
64
+ it_should_not_allow_invalid_value
121
65
  end
122
66
 
123
67
  for_attribute(:theme_shade) do
124
- with_value("BF") do
125
- it_should_assign_successfully
126
- it_should_output "<w:bdr w:themeShade=\"BF\"/>"
127
- end
128
-
129
- with_value(:dark) do
130
- it_should_raise_an_exception
131
- end
68
+ it_should_assign_and_output_xml "BF"
69
+ it_should_not_allow_invalid_value
132
70
  end
133
71
 
134
72
  for_attribute(:theme_tint) do
135
- with_value("BF") do
136
- it_should_assign_successfully
137
- it_should_output "<w:bdr w:themeTint=\"BF\"/>"
138
- end
139
-
140
- with_value(:pink) do
141
- it_should_raise_an_exception
142
- end
73
+ it_should_assign_and_output_xml "BF"
74
+ it_should_not_allow_invalid_value
143
75
  end
144
76
 
145
77
  for_attribute(:type) do
146
- with_value(:single) do
147
- it_should_assign_successfully
148
- it_should_output "<w:bdr w:val=\"single\"/>"
149
- end
150
-
151
- with_value(:programmers) do
152
- it_should_raise_an_exception
153
- end
78
+ it_should_assign_and_output_xml :single
79
+ it_should_not_allow_invalid_value
154
80
  end
155
81
 
156
82
  end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe OpenXml::Docx::Properties::CantSplit do
4
+ include ValuePropertyTestMacros
5
+
6
+ it_should_use tag: :cantSplit, name: "cant_split"
7
+
8
+ with_value(true) do
9
+ it_should_work
10
+ it_should_output "<w:cantSplit/>"
11
+ end
12
+
13
+ with_value(false) do
14
+ it_should_work
15
+ it_should_output ""
16
+ end
17
+
18
+ with_value(nil) do
19
+ it_should_work
20
+ it_should_output ""
21
+ end
22
+
23
+ end
@@ -6,44 +6,24 @@ describe OpenXml::Docx::Properties::Color do
6
6
  it_should_use tag: :color, name: "color"
7
7
 
8
8
  for_attribute(:theme_color) do
9
- with_value(:hyperlink) do
10
- it_should_assign_successfully
11
- it_should_output "<w:color w:themeColor=\"hyperlink\"/>"
12
- end
9
+ it_should_assign_and_output_xml :hyperlink
10
+ it_should_not_allow_invalid_value
13
11
  end
14
12
 
15
13
  for_attribute(:theme_shade) do
16
- with_value("BF") do
17
- it_should_assign_successfully
18
- it_should_output "<w:color w:themeShade=\"BF\"/>"
19
- end
20
-
21
- with_value(:dark) do
22
- it_should_raise_an_exception
23
- end
14
+ it_should_assign_and_output_xml "BF"
15
+ it_should_not_allow_invalid_value
24
16
  end
25
17
 
26
18
  for_attribute(:theme_tint) do
27
- with_value("BF") do
28
- it_should_assign_successfully
29
- it_should_output "<w:color w:themeTint=\"BF\"/>"
30
- end
31
-
32
- with_value(:pink) do
33
- it_should_raise_an_exception
34
- end
19
+ it_should_assign_and_output_xml "BF"
20
+ it_should_not_allow_invalid_value
35
21
  end
36
22
 
37
23
  for_attribute(:color) do
38
- with_value(:D99694) do
39
- it_should_assign_successfully
40
- it_should_output "<w:color w:val=\"D99694\"/>"
41
- end
42
-
43
- with_value(:auto) do
44
- it_should_assign_successfully
45
- it_should_output "<w:color w:val=\"auto\"/>"
46
- end
24
+ values = %i(D99694 auto)
25
+ it_should_assign_and_output_xml values
26
+ it_should_not_allow_invalid_value
47
27
  end
48
28
 
49
29
  end
@@ -11,17 +11,9 @@ describe OpenXml::Docx::Properties::Column do
11
11
  it_should_output "<w:col w:space=\"2\" w:w=\"1\"/>", 1, 1
12
12
  end
13
13
 
14
- with_value(-1) do
15
- it_should_raise_an_exception
16
- end
17
-
18
- with_value(12.1) do
19
- it_should_raise_an_exception
20
- end
21
-
22
- with_value(:big) do
23
- it_should_raise_an_exception
24
- end
14
+ it_should_not_allow_floats
15
+ it_should_not_allow_negative_numbers
16
+ it_should_not_allow_invalid_value
25
17
  end
26
18
 
27
19
  for_attribute(:width) do
@@ -30,17 +22,9 @@ describe OpenXml::Docx::Properties::Column do
30
22
  it_should_output "<w:col w:space=\"1\" w:w=\"2\"/>", 1, 1
31
23
  end
32
24
 
33
- with_value(-1) do
34
- it_should_raise_an_exception
35
- end
36
-
37
- with_value(12.1) do
38
- it_should_raise_an_exception
39
- end
40
-
41
- with_value(:big) do
42
- it_should_raise_an_exception
43
- end
25
+ it_should_not_allow_floats
26
+ it_should_not_allow_negative_numbers
27
+ it_should_not_allow_invalid_value
44
28
  end
45
29
 
46
30
  end
@@ -94,13 +94,8 @@ describe OpenXml::Docx::Properties::Columns do
94
94
  end
95
95
  end
96
96
 
97
- with_value(1.3) do
98
- it_should_raise_an_exception
99
- end
100
-
101
- with_value(:a_lot) do
102
- it_should_raise_an_exception
103
- end
97
+ it_should_not_allow_floats
98
+ it_should_not_allow_invalid_value
104
99
  end
105
100
 
106
101
  for_attribute(:separator) do
@@ -161,13 +156,8 @@ describe OpenXml::Docx::Properties::Columns do
161
156
  end
162
157
  end
163
158
 
164
- with_value(1.3) do
165
- it_should_raise_an_exception
166
- end
167
-
168
- with_value(:a_lot) do
169
- it_should_raise_an_exception
170
- end
159
+ it_should_not_allow_floats
160
+ it_should_not_allow_invalid_value
171
161
  end
172
162
 
173
163
  end
@@ -6,147 +6,51 @@ describe OpenXml::Docx::Properties::ConditionalFormatting do
6
6
  it_should_use tag: :cnfStyle, name: "conditional_formatting"
7
7
 
8
8
  for_attribute(:even_horizontal_band) do
9
- with_value(true) do
10
- it_should_assign_successfully
11
- it_should_output "<w:cnfStyle w:evenHBand=\"true\"/>"
12
- end
13
-
14
- with_value(false) do
15
- it_should_assign_successfully
16
- it_should_output ""
17
- end
9
+ it_should_behave_like_a_boolean_attribute
18
10
  end
19
11
 
20
12
  for_attribute(:even_vertical_band) do
21
- with_value(true) do
22
- it_should_assign_successfully
23
- it_should_output "<w:cnfStyle w:evenVBand=\"true\"/>"
24
- end
25
-
26
- with_value(false) do
27
- it_should_assign_successfully
28
- it_should_output ""
29
- end
13
+ it_should_behave_like_a_boolean_attribute
30
14
  end
31
15
 
32
16
  for_attribute(:first_column) do
33
- with_value(true) do
34
- it_should_assign_successfully
35
- it_should_output "<w:cnfStyle w:firstColumn=\"true\"/>"
36
- end
37
-
38
- with_value(false) do
39
- it_should_assign_successfully
40
- it_should_output ""
41
- end
17
+ it_should_behave_like_a_boolean_attribute
42
18
  end
43
19
 
44
20
  for_attribute(:first_row) do
45
- with_value(true) do
46
- it_should_assign_successfully
47
- it_should_output "<w:cnfStyle w:firstRow=\"true\"/>"
48
- end
49
-
50
- with_value(false) do
51
- it_should_assign_successfully
52
- it_should_output ""
53
- end
21
+ it_should_behave_like_a_boolean_attribute
54
22
  end
55
23
 
56
24
  for_attribute(:first_row_first_column) do
57
- with_value(true) do
58
- it_should_assign_successfully
59
- it_should_output "<w:cnfStyle w:firstRowFirstColumn=\"true\"/>"
60
- end
61
-
62
- with_value(false) do
63
- it_should_assign_successfully
64
- it_should_output ""
65
- end
25
+ it_should_behave_like_a_boolean_attribute
66
26
  end
67
27
 
68
28
  for_attribute(:first_row_last_column) do
69
- with_value(true) do
70
- it_should_assign_successfully
71
- it_should_output "<w:cnfStyle w:firstRowLastColumn=\"true\"/>"
72
- end
73
-
74
- with_value(false) do
75
- it_should_assign_successfully
76
- it_should_output ""
77
- end
29
+ it_should_behave_like_a_boolean_attribute
78
30
  end
79
31
 
80
32
  for_attribute(:last_column) do
81
- with_value(true) do
82
- it_should_assign_successfully
83
- it_should_output "<w:cnfStyle w:lastColumn=\"true\"/>"
84
- end
85
-
86
- with_value(false) do
87
- it_should_assign_successfully
88
- it_should_output ""
89
- end
33
+ it_should_behave_like_a_boolean_attribute
90
34
  end
91
35
 
92
36
  for_attribute(:last_row) do
93
- with_value(true) do
94
- it_should_assign_successfully
95
- it_should_output "<w:cnfStyle w:lastRow=\"true\"/>"
96
- end
97
-
98
- with_value(false) do
99
- it_should_assign_successfully
100
- it_should_output ""
101
- end
37
+ it_should_behave_like_a_boolean_attribute
102
38
  end
103
39
 
104
40
  for_attribute(:last_row_first_column) do
105
- with_value(true) do
106
- it_should_assign_successfully
107
- it_should_output "<w:cnfStyle w:lastRowFirstColumn=\"true\"/>"
108
- end
109
-
110
- with_value(false) do
111
- it_should_assign_successfully
112
- it_should_output ""
113
- end
41
+ it_should_behave_like_a_boolean_attribute
114
42
  end
115
43
 
116
44
  for_attribute(:last_row_last_column) do
117
- with_value(true) do
118
- it_should_assign_successfully
119
- it_should_output "<w:cnfStyle w:lastRowLastColumn=\"true\"/>"
120
- end
121
-
122
- with_value(false) do
123
- it_should_assign_successfully
124
- it_should_output ""
125
- end
45
+ it_should_behave_like_a_boolean_attribute
126
46
  end
127
47
 
128
48
  for_attribute(:odd_horizontal_band) do
129
- with_value(true) do
130
- it_should_assign_successfully
131
- it_should_output "<w:cnfStyle w:oddHBand=\"true\"/>"
132
- end
133
-
134
- with_value(false) do
135
- it_should_assign_successfully
136
- it_should_output ""
137
- end
49
+ it_should_behave_like_a_boolean_attribute
138
50
  end
139
51
 
140
52
  for_attribute(:odd_vertical_band) do
141
- with_value(true) do
142
- it_should_assign_successfully
143
- it_should_output "<w:cnfStyle w:oddVBand=\"true\"/>"
144
- end
145
-
146
- with_value(false) do
147
- it_should_assign_successfully
148
- it_should_output ""
149
- end
53
+ it_should_behave_like_a_boolean_attribute
150
54
  end
151
55
 
152
56
  with_no_attributes_set do