rocx 0.5.6 → 0.5.7

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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -0
  3. data/Gemfile.lock +1 -1
  4. data/lib/rocx.rb +1 -1
  5. data/lib/rocx/elements/base_container.rb +17 -2
  6. data/lib/rocx/elements/paragraph.rb +33 -21
  7. data/lib/rocx/elements/run.rb +2 -2
  8. data/lib/rocx/elements/style.rb +19 -0
  9. data/lib/rocx/parts/base_part.rb +4 -0
  10. data/lib/rocx/parts/content_types.rb +2 -6
  11. data/lib/rocx/parts/document.rb +2 -3
  12. data/lib/rocx/parts/global_rels.rb +2 -3
  13. data/lib/rocx/parts/rels.rb +2 -3
  14. data/lib/rocx/parts/settings.rb +2 -3
  15. data/lib/rocx/parts/styles.rb +2 -3
  16. data/lib/rocx/properties/alignment.rb +1 -1
  17. data/lib/rocx/properties/attribute_builder.rb +283 -0
  18. data/lib/rocx/properties/base_property.rb +4 -0
  19. data/lib/rocx/properties/border.rb +32 -0
  20. data/lib/rocx/properties/borders.rb +48 -0
  21. data/lib/rocx/properties/compress_punctuation.rb +11 -0
  22. data/lib/rocx/properties/frame.rb +70 -0
  23. data/lib/rocx/properties/indentation.rb +1 -1
  24. data/lib/rocx/properties/numbering.rb +28 -0
  25. data/lib/rocx/properties/shading.rb +75 -0
  26. data/lib/rocx/properties/spacing.rb +38 -0
  27. data/lib/rocx/properties/tab.rb +77 -0
  28. data/lib/rocx/properties/tabs.rb +55 -0
  29. data/lib/rocx/properties/text_direction.rb +15 -0
  30. data/lib/rocx/properties/textbox_tight_wrap.rb +15 -0
  31. data/lib/rocx/properties/vertical_alignment.rb +19 -0
  32. data/lib/rocx/version.rb +1 -1
  33. data/rocx.gemspec +1 -0
  34. data/test/package_test.rb +6 -6
  35. data/test/properties/auto_adjust_right_indent_test.rb +4 -4
  36. data/test/properties/auto_space_de_test.rb +4 -4
  37. data/test/properties/auto_space_dn_test.rb +4 -4
  38. data/test/properties/bidi_test.rb +4 -4
  39. data/test/properties/bold_test.rb +4 -4
  40. data/test/properties/border_test.rb +216 -0
  41. data/test/properties/borders_test.rb +95 -0
  42. data/test/properties/compress_punctuation_test.rb +50 -0
  43. data/test/properties/conditional_formatting_test.rb +4 -4
  44. data/test/properties/contextual_spacing_test.rb +4 -4
  45. data/test/properties/div_id_test.rb +3 -3
  46. data/test/properties/frame_test.rb +497 -0
  47. data/test/properties/italics_test.rb +4 -4
  48. data/test/properties/keep_lines_test.rb +4 -4
  49. data/test/properties/keep_next_test.rb +4 -4
  50. data/test/properties/kinsoku_test.rb +4 -4
  51. data/test/properties/mirror_indent_test.rb +4 -4
  52. data/test/properties/numbering_test.rb +86 -0
  53. data/test/properties/outline_level_test.rb +4 -4
  54. data/test/properties/overflow_punctuation_test.rb +4 -4
  55. data/test/properties/page_break_before_test.rb +4 -4
  56. data/test/properties/shading_test.rb +225 -0
  57. data/test/properties/snap_to_grid_test.rb +4 -4
  58. data/test/properties/spacing_test.rb +248 -0
  59. data/test/properties/style_test.rb +30 -0
  60. data/test/properties/supress_auto_hyphens_test.rb +4 -4
  61. data/test/properties/supress_line_numbers_test.rb +4 -4
  62. data/test/properties/supress_overlap_test.rb +4 -4
  63. data/test/properties/tab_test.rb +63 -0
  64. data/test/properties/tabs_test.rb +54 -0
  65. data/test/properties/text_direction_test.rb +100 -0
  66. data/test/properties/textbox_tight_wrap_test.rb +88 -0
  67. data/test/properties/vertical_alignment_test.rb +88 -0
  68. data/test/properties/widow_control_test.rb +4 -4
  69. data/test/properties/word_wrap_test.rb +4 -4
  70. data/test/test_helper.rb +2 -5
  71. metadata +45 -3
@@ -0,0 +1,15 @@
1
+ module Rocx
2
+ module Properties
3
+ class TextDirection < BaseProperty
4
+
5
+ def ok_values
6
+ %i(lr lrV rl rlV tb tbV)
7
+ end
8
+
9
+ def to_xml(xml)
10
+ xml["w"].public_send(tag, "w:val" => value)
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Rocx
2
+ module Properties
3
+ class TextboxTightWrap < BaseProperty
4
+
5
+ def ok_values
6
+ %i(allLines firstAndLastLine firstLineOnly lastLineOnly none)
7
+ end
8
+
9
+ def to_xml(xml)
10
+ xml["w"].public_send(tag, "w:val" => value)
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module Rocx
2
+ module Properties
3
+ class VerticalAlignment < BaseProperty
4
+
5
+ def ok_values
6
+ %i(auto baseline bottom center top)
7
+ end
8
+
9
+ def to_xml(xml)
10
+ xml["w"].public_send(tag, "w:val" => value)
11
+ end
12
+
13
+ def tag
14
+ :textAlignment
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Rocx
2
- VERSION = "0.5.6"
2
+ VERSION = "0.5.7"
3
3
  end
@@ -10,6 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["gene.doyel@cph.org"]
11
11
  gem.description = %q{Create Microsoft Word (.docx) files.}
12
12
  gem.summary = %q{Using a simple API, create docx files programmatically, including bullet points, titles, headings, page breaks and tables!}
13
+ gem.license = "MIT"
13
14
  gem.homepage = "https://github.com/genebot/rocx"
14
15
  gem.required_ruby_version = "~> 2.0"
15
16
 
@@ -9,27 +9,27 @@ class PackageTest < Test::Unit::TestCase
9
9
  end
10
10
 
11
11
  should "create the content types part" do
12
- assert_is_a Rocx::Parts::ContentTypes, package.content_types
12
+ assert_kind_of Rocx::Parts::ContentTypes, package.content_types
13
13
  end
14
14
 
15
15
  should "create the document part" do
16
- assert_is_a Rocx::Parts::Document, package.document
16
+ assert_kind_of Rocx::Parts::Document, package.document
17
17
  end
18
18
 
19
19
  should "create the global rels part" do
20
- assert_is_a Rocx::Parts::GlobalRels, package.global_rels
20
+ assert_kind_of Rocx::Parts::GlobalRels, package.global_rels
21
21
  end
22
22
 
23
23
  should "create the _rels part" do
24
- assert_is_a Rocx::Parts::Rels, package.rels
24
+ assert_kind_of Rocx::Parts::Rels, package.rels
25
25
  end
26
26
 
27
27
  should "create the settings part" do
28
- assert_is_a Rocx::Parts::Settings, package.settings
28
+ assert_kind_of Rocx::Parts::Settings, package.settings
29
29
  end
30
30
 
31
31
  should "create the styles part" do
32
- assert_is_a Rocx::Parts::Styles, package.styles
32
+ assert_kind_of Rocx::Parts::Styles, package.styles
33
33
  end
34
34
  end
35
35
 
@@ -5,7 +5,7 @@ class AutoAdjustRightIndentTest < PropertyTest
5
5
 
6
6
  context "always" do
7
7
  setup do
8
- @auto_adjust_right_ind = Rocx::Properties::AutoAdjustRightIndent.new(false)
8
+ @auto_adjust_right_ind = AutoAdjustRightIndent.new(false)
9
9
  end
10
10
 
11
11
  should "have the right tag" do
@@ -19,7 +19,7 @@ class AutoAdjustRightIndentTest < PropertyTest
19
19
 
20
20
  context "when the value is true, it" do
21
21
  setup do
22
- @auto_adjust_right_ind = Rocx::Properties::AutoAdjustRightIndent.new(true)
22
+ @auto_adjust_right_ind = AutoAdjustRightIndent.new(true)
23
23
  end
24
24
 
25
25
  should "return XML" do
@@ -29,7 +29,7 @@ class AutoAdjustRightIndentTest < PropertyTest
29
29
 
30
30
  context "when the value is false, it" do
31
31
  setup do
32
- @auto_adjust_right_ind = Rocx::Properties::AutoAdjustRightIndent.new(false)
32
+ @auto_adjust_right_ind = AutoAdjustRightIndent.new(false)
33
33
  end
34
34
 
35
35
  should "not return XML" do
@@ -39,7 +39,7 @@ class AutoAdjustRightIndentTest < PropertyTest
39
39
 
40
40
  context "when the value is nil, it" do
41
41
  setup do
42
- @auto_adjust_right_ind = Rocx::Properties::AutoAdjustRightIndent.new(nil)
42
+ @auto_adjust_right_ind = AutoAdjustRightIndent.new(nil)
43
43
  end
44
44
 
45
45
  should "not return XML" do
@@ -5,7 +5,7 @@ class AutoSpaceDeTest < PropertyTest
5
5
 
6
6
  context "always" do
7
7
  setup do
8
- @auto_space_de = Rocx::Properties::AutoSpaceDe.new(false)
8
+ @auto_space_de = AutoSpaceDe.new(false)
9
9
  end
10
10
 
11
11
  should "have the right tag" do
@@ -19,7 +19,7 @@ class AutoSpaceDeTest < PropertyTest
19
19
 
20
20
  context "when the value is true, it" do
21
21
  setup do
22
- @auto_space_de = Rocx::Properties::AutoSpaceDe.new(true)
22
+ @auto_space_de = AutoSpaceDe.new(true)
23
23
  end
24
24
 
25
25
  should "return XML" do
@@ -29,7 +29,7 @@ class AutoSpaceDeTest < PropertyTest
29
29
 
30
30
  context "when the value is false, it" do
31
31
  setup do
32
- @auto_space_de = Rocx::Properties::AutoSpaceDe.new(false)
32
+ @auto_space_de = AutoSpaceDe.new(false)
33
33
  end
34
34
 
35
35
  should "not return XML" do
@@ -39,7 +39,7 @@ class AutoSpaceDeTest < PropertyTest
39
39
 
40
40
  context "when the value is nil, it" do
41
41
  setup do
42
- @auto_space_de = Rocx::Properties::AutoSpaceDe.new(nil)
42
+ @auto_space_de = AutoSpaceDe.new(nil)
43
43
  end
44
44
 
45
45
  should "not return XML" do
@@ -5,7 +5,7 @@ class AutoSpaceDnTest < PropertyTest
5
5
 
6
6
  context "always" do
7
7
  setup do
8
- @auto_space_dn = Rocx::Properties::AutoSpaceDn.new(false)
8
+ @auto_space_dn = AutoSpaceDn.new(false)
9
9
  end
10
10
 
11
11
  should "have the right tag" do
@@ -19,7 +19,7 @@ class AutoSpaceDnTest < PropertyTest
19
19
 
20
20
  context "when the value is true, it" do
21
21
  setup do
22
- @auto_space_dn = Rocx::Properties::AutoSpaceDn.new(true)
22
+ @auto_space_dn = AutoSpaceDn.new(true)
23
23
  end
24
24
 
25
25
  should "return XML" do
@@ -29,7 +29,7 @@ class AutoSpaceDnTest < PropertyTest
29
29
 
30
30
  context "when the value is false, it" do
31
31
  setup do
32
- @auto_space_dn = Rocx::Properties::AutoSpaceDn.new(false)
32
+ @auto_space_dn = AutoSpaceDn.new(false)
33
33
  end
34
34
 
35
35
  should "not return XML" do
@@ -39,7 +39,7 @@ class AutoSpaceDnTest < PropertyTest
39
39
 
40
40
  context "when the value is nil, it" do
41
41
  setup do
42
- @auto_space_dn = Rocx::Properties::AutoSpaceDn.new(nil)
42
+ @auto_space_dn = AutoSpaceDn.new(nil)
43
43
  end
44
44
 
45
45
  should "not return XML" do
@@ -5,7 +5,7 @@ class BidiTest < PropertyTest
5
5
 
6
6
  context "always" do
7
7
  setup do
8
- @bidi = Rocx::Properties::Bidi.new(false)
8
+ @bidi = Bidi.new(false)
9
9
  end
10
10
 
11
11
  should "have the right tag" do
@@ -19,7 +19,7 @@ class BidiTest < PropertyTest
19
19
 
20
20
  context "when the value is true, it" do
21
21
  setup do
22
- @bidi = Rocx::Properties::Bidi.new(true)
22
+ @bidi = Bidi.new(true)
23
23
  end
24
24
 
25
25
  should "return XML" do
@@ -29,7 +29,7 @@ class BidiTest < PropertyTest
29
29
 
30
30
  context "when the value is false, it" do
31
31
  setup do
32
- @bidi = Rocx::Properties::Bidi.new(false)
32
+ @bidi = Bidi.new(false)
33
33
  end
34
34
 
35
35
  should "not return XML" do
@@ -39,7 +39,7 @@ class BidiTest < PropertyTest
39
39
 
40
40
  context "when the value is nil, it" do
41
41
  setup do
42
- @bidi = Rocx::Properties::Bidi.new(nil)
42
+ @bidi = Bidi.new(nil)
43
43
  end
44
44
 
45
45
  should "not return XML" do
@@ -5,7 +5,7 @@ class BoldTest < PropertyTest
5
5
 
6
6
  context "always" do
7
7
  setup do
8
- @bold = Rocx::Properties::Bold.new(false)
8
+ @bold = Bold.new(false)
9
9
  end
10
10
 
11
11
  should "have the right tag" do
@@ -19,7 +19,7 @@ class BoldTest < PropertyTest
19
19
 
20
20
  context "when the value is true, it" do
21
21
  setup do
22
- @bold = Rocx::Properties::Bold.new(true)
22
+ @bold = Bold.new(true)
23
23
  end
24
24
 
25
25
  should "return XML" do
@@ -29,7 +29,7 @@ class BoldTest < PropertyTest
29
29
 
30
30
  context "when the value is false, it" do
31
31
  setup do
32
- @bold = Rocx::Properties::Bold.new(false)
32
+ @bold = Bold.new(false)
33
33
  end
34
34
 
35
35
  should "not return XML" do
@@ -39,7 +39,7 @@ class BoldTest < PropertyTest
39
39
 
40
40
  context "when the value is nil, it" do
41
41
  setup do
42
- @bold = Rocx::Properties::Bold.new(nil)
42
+ @bold = Bold.new(nil)
43
43
  end
44
44
 
45
45
  should "not return XML" do
@@ -0,0 +1,216 @@
1
+ require "test_helper"
2
+
3
+ class BorderTest < PropertyTest
4
+ attr_reader :border
5
+
6
+ context "always" do
7
+ setup do
8
+ @border = Border.new(:left)
9
+ end
10
+
11
+ should "have the right name" do
12
+ assert_equal "border", border.name
13
+ end
14
+
15
+ should "have its tag be an argument on initialize" do
16
+ assert_equal :left, border.tag
17
+ end
18
+ end
19
+
20
+ context "for a border's color attribute" do
21
+ setup do
22
+ @border = Border.new(:left)
23
+ end
24
+
25
+ should "allow hex color values" do
26
+ assert_nothing_raised do
27
+ border.color = "4F81BD"
28
+ end
29
+ end
30
+
31
+ should "allow :auto" do
32
+ assert_nothing_raised do
33
+ border.color = :auto
34
+ end
35
+ end
36
+
37
+ should "not allow anything else" do
38
+ assert_raises ArgumentError do
39
+ border.color = "green"
40
+ end
41
+ end
42
+ end
43
+
44
+ context "for a border's frame attribute" do
45
+ setup do
46
+ @border = Border.new(:right)
47
+ end
48
+
49
+ should "allow true or false" do
50
+ assert_nothing_raised do
51
+ border.frame = true
52
+ end
53
+
54
+ assert_nothing_raised do
55
+ border.frame = false
56
+ end
57
+ end
58
+
59
+ should "not allow anything else" do
60
+ assert_raises ArgumentError do
61
+ border.frame = :yep
62
+ end
63
+ end
64
+ end
65
+
66
+ context "for a border's shadow attribute" do
67
+ setup do
68
+ @border = Border.new(:top)
69
+ end
70
+
71
+ should "allow true or false" do
72
+ assert_nothing_raised do
73
+ border.shadow = true
74
+ end
75
+
76
+ assert_nothing_raised do
77
+ border.shadow = false
78
+ end
79
+ end
80
+
81
+ should "not allow anything else" do
82
+ assert_raises ArgumentError do
83
+ border.shadow = :yep
84
+ end
85
+ end
86
+ end
87
+
88
+ context "for a border's size attribute" do
89
+ setup do
90
+ @border = Border.new(:bar)
91
+ end
92
+
93
+ should "allow positive integers" do
94
+ assert_nothing_raised do
95
+ border.size = 24
96
+ end
97
+ end
98
+
99
+ should "not allow anything else" do
100
+ assert_raises ArgumentError do
101
+ border.size = -24
102
+ end
103
+
104
+ assert_raises ArgumentError do
105
+ border.size = :big
106
+ end
107
+ end
108
+ end
109
+
110
+ context "for a border's space attribute" do
111
+ setup do
112
+ @border = Border.new(:bottom)
113
+ end
114
+
115
+ should "allow positive integers" do
116
+ assert_nothing_raised do
117
+ border.space = 24
118
+ end
119
+ end
120
+
121
+ should "not allow anything else" do
122
+ assert_raises ArgumentError do
123
+ border.space = -24
124
+ end
125
+
126
+ assert_raises ArgumentError do
127
+ border.space = :big
128
+ end
129
+ end
130
+ end
131
+
132
+ context "for a border's theme color" do
133
+ setup do
134
+ @border = Border.new(:between)
135
+ end
136
+
137
+ should "only allow valid theme colors" do
138
+ assert_nothing_raised do
139
+ border.theme_color = :hyperlink
140
+ end
141
+ end
142
+
143
+ should "not allow anything else" do
144
+ assert ArgumentError do
145
+ border.theme_color = :lens_flare
146
+ end
147
+ end
148
+ end
149
+
150
+ context "for a border's theme shade" do
151
+ setup do
152
+ @border = Border.new(:left)
153
+ end
154
+
155
+ should "only allow 2-digit hex colors" do
156
+ assert_nothing_raised do
157
+ border.theme_shade = "BF"
158
+ end
159
+ end
160
+
161
+ should "not allow anything else" do
162
+ assert ArgumentError do
163
+ border.theme_shade = :dark
164
+ end
165
+ end
166
+ end
167
+
168
+ context "for a border's theme tint" do
169
+ setup do
170
+ @border = Border.new(:right)
171
+ end
172
+
173
+ should "only allow 2-digit hex colors" do
174
+ assert_nothing_raised do
175
+ border.theme_shade = "BF"
176
+ end
177
+ end
178
+
179
+ should "not allow anything else" do
180
+ assert ArgumentError do
181
+ border.theme_shade = :pink
182
+ end
183
+ end
184
+ end
185
+
186
+ context "for a border's type" do
187
+ setup do
188
+ @border = Border.new(:top)
189
+ end
190
+
191
+ should "only allow valid types" do
192
+ assert_nothing_raised do
193
+ border.type = :single
194
+ end
195
+ end
196
+
197
+ should "not allow anything else" do
198
+ assert ArgumentError do
199
+ border.type = :programmers
200
+ end
201
+ end
202
+ end
203
+
204
+ context "with proper attributes, it" do
205
+ setup do
206
+ @border = Border.new(:left)
207
+ border.color = "FF00FF"
208
+ border.type = :crazyMaze
209
+ end
210
+
211
+ should "output the right XML" do
212
+ assert_equal "<w:left w:color=\"FF00FF\" w:val=\"crazyMaze\"/>", xml(border)
213
+ end
214
+ end
215
+
216
+ end