rocx 0.5.8 → 0.6.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 (89) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +55 -22
  4. data/Rakefile +1 -0
  5. data/lib/rocx.rb +1 -0
  6. data/lib/rocx/attribute_builder.rb +296 -0
  7. data/lib/rocx/elements.rb +3 -2
  8. data/lib/rocx/elements/absolute_position_tab.rb +29 -0
  9. data/lib/rocx/elements/bidi_embed.rb +17 -0
  10. data/lib/rocx/elements/bidi_override.rb +17 -0
  11. data/lib/rocx/elements/break.rb +19 -5
  12. data/lib/rocx/elements/carriage_return.rb +8 -0
  13. data/lib/rocx/elements/{base_container.rb → container.rb} +21 -16
  14. data/lib/rocx/elements/content_part.rb +8 -0
  15. data/lib/rocx/elements/control.rb +10 -0
  16. data/lib/rocx/elements/deleted_text.rb +8 -0
  17. data/lib/rocx/elements/dirty.rb +6 -0
  18. data/lib/rocx/elements/element.rb +62 -0
  19. data/lib/rocx/elements/last_rendered_page_break.rb +6 -0
  20. data/lib/rocx/elements/long_day.rb +8 -0
  21. data/lib/rocx/elements/long_month.rb +8 -0
  22. data/lib/rocx/elements/long_year.rb +8 -0
  23. data/lib/rocx/elements/nonbreaking_hyphen.rb +7 -0
  24. data/lib/rocx/elements/optional_hyphen.rb +8 -0
  25. data/lib/rocx/elements/page_number.rb +7 -0
  26. data/lib/rocx/elements/paragraph.rb +2 -4
  27. data/lib/rocx/elements/ruby.rb +46 -0
  28. data/lib/rocx/elements/run.rb +2 -4
  29. data/lib/rocx/elements/short_day.rb +8 -0
  30. data/lib/rocx/elements/short_month.rb +8 -0
  31. data/lib/rocx/elements/short_year.rb +8 -0
  32. data/lib/rocx/elements/symbol.rb +6 -5
  33. data/lib/rocx/elements/tab.rb +6 -0
  34. data/lib/rocx/elements/text.rb +14 -7
  35. data/lib/rocx/properties/border.rb +0 -2
  36. data/lib/rocx/properties/color.rb +0 -2
  37. data/lib/rocx/properties/complex_property.rb +1 -0
  38. data/lib/rocx/properties/conditional_formatting.rb +0 -2
  39. data/lib/rocx/properties/east_asian_layout.rb +2 -4
  40. data/lib/rocx/properties/font.rb +0 -2
  41. data/lib/rocx/properties/frame.rb +7 -9
  42. data/lib/rocx/properties/indentation.rb +0 -2
  43. data/lib/rocx/properties/language.rb +1 -2
  44. data/lib/rocx/properties/manual_width.rb +1 -2
  45. data/lib/rocx/properties/numbering.rb +0 -2
  46. data/lib/rocx/properties/phonetic_guide_alignment.rb +13 -0
  47. data/lib/rocx/properties/phonetic_guide_base_font_size.rb +8 -0
  48. data/lib/rocx/properties/phonetic_guide_font_size.rb +8 -0
  49. data/lib/rocx/properties/phonetic_guide_font_size_raise.rb +8 -0
  50. data/lib/rocx/properties/phonetic_guide_language.rb +17 -0
  51. data/lib/rocx/properties/shading.rb +0 -2
  52. data/lib/rocx/properties/spacing.rb +0 -2
  53. data/lib/rocx/properties/underline.rb +0 -2
  54. data/lib/rocx/properties/value_property.rb +1 -1
  55. data/lib/rocx/version.rb +1 -1
  56. data/spec/elements/absolute_position_tab_spec.rb +84 -0
  57. data/spec/elements/bidi_embed_spec.rb +31 -0
  58. data/spec/elements/bidi_override_spec.rb +31 -0
  59. data/spec/elements/break_spec.rb +32 -24
  60. data/spec/elements/carriage_return_spec.rb +12 -0
  61. data/spec/elements/content_part_spec.rb +18 -0
  62. data/spec/elements/control_spec.rb +41 -0
  63. data/spec/elements/deleted_text_spec.rb +24 -0
  64. data/spec/elements/dirty_spec.rb +12 -0
  65. data/spec/elements/last_rendered_page_break_spec.rb +12 -0
  66. data/spec/elements/long_day_spec.rb +12 -0
  67. data/spec/elements/long_month_spec.rb +12 -0
  68. data/spec/elements/long_year_spec.rb +12 -0
  69. data/spec/elements/nonbreaking_hyphen_spec.rb +12 -0
  70. data/spec/elements/optional_hyphen_spec.rb +12 -0
  71. data/spec/elements/page_number_spec.rb +12 -0
  72. data/spec/elements/paragraph_spec.rb +9 -7
  73. data/spec/elements/ruby_spec.rb +66 -0
  74. data/spec/elements/run_spec.rb +2 -2
  75. data/spec/elements/short_day_spec.rb +12 -0
  76. data/spec/elements/short_month_spec.rb +12 -0
  77. data/spec/elements/short_year_spec.rb +12 -0
  78. data/spec/elements/symbol_spec.rb +20 -10
  79. data/spec/elements/tab_spec.rb +12 -0
  80. data/spec/elements/text_spec.rb +12 -11
  81. data/spec/properties/phonetic_guide_alignment_spec.rb +42 -0
  82. data/spec/properties/phonetic_guide_base_font_size_spec.rb +25 -0
  83. data/spec/properties/phonetic_guide_font_size_raise_spec.rb +25 -0
  84. data/spec/properties/phonetic_guide_font_size_spec.rb +25 -0
  85. data/spec/properties/phonetic_guide_language_spec.rb +12 -0
  86. data/spec/support/element_test_macros.rb +135 -4
  87. metadata +55 -5
  88. data/lib/rocx/elements/base_element.rb +0 -91
  89. data/lib/rocx/properties/attribute_builder.rb +0 -289
@@ -1,91 +0,0 @@
1
- module Rocx
2
- module Elements
3
- class BaseElement
4
- class << self
5
-
6
- def tag_name(*args)
7
- @tag_name = args.first if args.any?
8
- @tag_name
9
- end
10
-
11
- def namespace(*args)
12
- @namespace = args.first if args.any?
13
- @namespace
14
- end
15
-
16
- def attribute(name, limit_to: nil, xml_name: nil, regex: nil)
17
- attr_reader name
18
-
19
- if limit_to
20
- define_method "valid_#{name}" do
21
- limit_to
22
- end
23
-
24
- define_method "valid_#{name}?" do |value|
25
- send("valid_#{name}").member? value
26
- end
27
-
28
- define_method "#{name}=" do |value|
29
- valid_values = send("valid_#{name}").join(", ")
30
- raise ArgumentError, "Invalid #{name}; must be one of #{valid_values}" unless send("valid_#{name}?", value)
31
- instance_variable_set("@#{name}", value)
32
- end
33
- elsif regex
34
- define_method "valid_#{name}?" do |value|
35
- !!(regex =~ value)
36
- end
37
-
38
- define_method "#{name}=" do |value|
39
- raise ArgumentError, "Invalid #{name}; must match #{regex.inspect}" unless send("valid_#{name}?", value)
40
- instance_variable_set("@#{name}", value)
41
- end
42
- else
43
- attr_writer name
44
- end
45
-
46
- attributes[name] = xml_name || name
47
- end
48
-
49
- def attributes
50
- @attributes ||= {}
51
- end
52
- end
53
-
54
- def initialize(**args)
55
- args.each do |property, value|
56
- self.send("#{property}=", value)
57
- end
58
- end
59
-
60
- def to_xml(xml)
61
- if namespace
62
- xml[namespace].public_send tag_name, xml_attributes
63
- else
64
- xml.public_send tag_name, xml_attributes
65
- end
66
- end
67
-
68
- protected
69
-
70
- def xml_attributes
71
- attributes.each_with_object({}) do |(attribute, name), props|
72
- value = send(attribute)
73
- props[name] = value unless value.nil?
74
- end
75
- end
76
-
77
- def attributes
78
- self.class.attributes
79
- end
80
-
81
- def tag_name
82
- self.class.tag_name
83
- end
84
-
85
- def namespace
86
- self.class.namespace
87
- end
88
-
89
- end
90
- end
91
- end
@@ -1,289 +0,0 @@
1
- module Rocx
2
- module Properties
3
- module AttributeBuilder
4
-
5
- VALID_THEME_COLORS = %i(accent1 accent2 accent3 accent4 accent5 accent6 background1 background2 dark1 dark2 followedHyperlink hyperlink light1 light2 none text1 text2)
6
-
7
- VALID_TYPES = %i(apples
8
- archedScallops
9
- babyPacifier
10
- babyRattle
11
- balloons3Colors
12
- balloonsHotAir
13
- basicBlackDashes
14
- basicBlackDots
15
- basicBlackSquares
16
- basicThinLines
17
- basicWhiteDashes
18
- basicWhiteDots
19
- basicWhiteSquares
20
- basicWideInline
21
- basicWideMidline
22
- basicWideOutline
23
- bats
24
- birds
25
- birdsFlight
26
- cabins
27
- cakeSlice
28
- candyCorn
29
- celticKnotwork
30
- certificateBanner
31
- chainLink
32
- champagneBottle
33
- checkedBarBlack
34
- checkedBarColor
35
- checkered
36
- christmasTree
37
- circlesLines
38
- circlesRectangles
39
- classicalWave
40
- clocks
41
- compass
42
- confetti
43
- confettiGrays
44
- confettiOutlines
45
- confettiStreamers
46
- confettiWhite
47
- cornerTriangles
48
- couponCutoutDashes
49
- couponCutoutDots
50
- crazyMaze
51
- creaturesButterfly
52
- creaturesFish
53
- creaturesInsects
54
- creaturesLadyBug
55
- crossStitch
56
- cup
57
- custom
58
- dashDotStroked
59
- dashed
60
- dashSmallGap
61
- decoArch
62
- decoArchColor
63
- decoBlocks
64
- diamondsGray
65
- dotDash
66
- dotDotDash
67
- dotted
68
- double
69
- doubleD
70
- doubleDiamonds
71
- doubleWave
72
- earth1
73
- earth2
74
- earth3
75
- eclipsingSquares1
76
- eclipsingSquares2
77
- eggsBlack
78
- fans
79
- film
80
- firecrackers
81
- flowersBlockPrint
82
- flowersDaisies
83
- flowersModern1
84
- flowersModern2
85
- flowersPansy
86
- flowersRedRose
87
- flowersRoses
88
- flowersTeacup
89
- flowersTiny
90
- gems
91
- gingerbreadMan
92
- gradient
93
- handmade1
94
- handmade2
95
- heartBalloon
96
- heartGray
97
- hearts
98
- heebieJeebies
99
- holly
100
- houseFunky
101
- hypnotic
102
- iceCreamCones
103
- inset
104
- lightBulb
105
- lightning1
106
- lightning2
107
- mapleLeaf
108
- mapleMuffins
109
- mapPins
110
- marquee
111
- marqueeToothed
112
- moons
113
- mosaic
114
- musicNotes
115
- nil
116
- none
117
- northwest
118
- outset
119
- ovals
120
- packages
121
- palmsBlack
122
- palmsColor
123
- paperClips
124
- papyrus
125
- partyFavor
126
- partyGlass
127
- pencils
128
- people
129
- peopleHats
130
- peopleWaving
131
- poinsettias
132
- postageStamp
133
- pumpkin1
134
- pushPinNote1
135
- pushPinNote2
136
- pyramids
137
- pyramidsAbove
138
- quadrants
139
- rings
140
- safari
141
- sawtooth
142
- sawtoothGray
143
- scaredCat
144
- seattle
145
- shadowedSquares
146
- shapes1
147
- shapes2
148
- sharksTeeth
149
- shorebirdTracks
150
- single
151
- skyrocket
152
- snowflakeFancy
153
- snowflaskes
154
- sombrero
155
- southwest
156
- stars
157
- stars3d
158
- starsBlack
159
- starsShadowed
160
- starsTop
161
- sun
162
- swirligig
163
- thick
164
- thickThinLargeGap
165
- thickThinMediumGap
166
- thickThinSmallGap
167
- thinThickLargeGap
168
- thinThickMediumGap
169
- thinThickSmallGap
170
- thinThickThinLargeGap
171
- thinThickThinMediumGap
172
- thinThickThinSmallGap
173
- threeDEmboss
174
- threeDEngrave
175
- tornPaper
176
- tornPaperBlack
177
- trees
178
- triangle1
179
- triangle2
180
- triangleCircle1
181
- triangleCircle2
182
- triangleParty
183
- triangle
184
- triple
185
- twistedLines1
186
- twistedLines2
187
- vine
188
- wave
189
- waveline
190
- weavingAngles
191
- weavingBraid
192
- weavingRibbon
193
- weavingStrips
194
- whiteFlowers
195
- woodwork
196
- xIllusions
197
- zanyTriangles
198
- zigZag
199
- zigZagStitch)
200
-
201
- def self.included(base)
202
- base.extend(ClassMethods)
203
- end
204
-
205
- module ClassMethods
206
- def attribute(name, expects: nil, displays_as: nil)
207
- attr_reader name
208
-
209
- define_method "#{name}=" do |value|
210
- send(expects, value)
211
- instance_variable_set "@#{name}", value
212
- end
213
-
214
- camelized_name = name.to_s.gsub(/_([a-z])/i) { $1.upcase }.to_sym
215
- attributes[name] = displays_as || camelized_name
216
- end
217
-
218
- def attributes
219
- @attributes ||= {}
220
- end
221
- end
222
-
223
- def render?
224
- attributes.keys.map(&method(:send)).any?
225
- end
226
-
227
- def attributes
228
- self.class.attributes
229
- end
230
-
231
- private
232
-
233
- def xml_attributes
234
- attributes.each_with_object({}) do |(name, display), attrs|
235
- value = send(name)
236
- attrs["w:#{display}"] = value if value
237
- end
238
- end
239
-
240
- def true_or_false(value)
241
- message = "Invalid #{name}: frame must be true or false"
242
- raise ArgumentError, message unless [true, false].member? value
243
- end
244
-
245
- def hex_color(value)
246
- message = "Invalid #{name}: must be :auto or a hex color, e.g. 4F1B8C"
247
- raise ArgumentError, message unless value == :auto || value =~ /[0-9A-F]{6}/
248
- end
249
-
250
- def hex_digit(value)
251
- message = "Invalid #{name}: must be a two-digit hex number, e.g. BF"
252
- raise ArgumentError, message unless value =~ /[0-9A-F]{2}/
253
- end
254
-
255
- def integer(value)
256
- message = "Invalid #{name}: must be an integer"
257
- raise ArgumentError, message unless value.is_a?(Integer)
258
- end
259
-
260
- def positive_integer(value)
261
- message = "Invalid #{name}: must be a positive integer"
262
- raise ArgumentError, message unless value.is_a?(Integer) && value >= 0
263
- end
264
-
265
- def string(value)
266
- message = "Invalid #{name}: must be a string"
267
- raise ArgumentError, message unless value.is_a?(String)
268
- end
269
-
270
- def on_or_off(value)
271
- valid_in? value, [:on, :off]
272
- end
273
-
274
- def valid_theme_color(value)
275
- valid_in? value, VALID_THEME_COLORS
276
- end
277
-
278
- def valid_type(value)
279
- valid_in? value, VALID_TYPES
280
- end
281
-
282
- def valid_in?(value, list)
283
- message = "Invalid #{name}: must be one of #{list.join(", ")} (was #{value.inspect})"
284
- raise ArgumentError, message unless list.member?(value)
285
- end
286
-
287
- end
288
- end
289
- end