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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9566d9952e4f4b81a945e27bc633c7367bcfa2c9
4
- data.tar.gz: 23feeec4fecf2d69f371afcb15c1f42ecc5a2041
3
+ metadata.gz: 7ebac9d8d2e707e65cf407ccc36232723b714808
4
+ data.tar.gz: 31d5f1ddbf1b278ffd9e7f28a615bd53e58c5f05
5
5
  SHA512:
6
- metadata.gz: de7d040a6ce8215a2cb59f4a5edeb40a44cc5ef60bb93780bbe4eff81573426e5cdaaa270d1d5718f498b016b88aeee0fc4107abfe39ee976a3c69ae8825fb86
7
- data.tar.gz: 0ff4f77e0df501a0d137146aa397fc8dced38476e6b970ef32cdeccf1416be399d5a77784c66b9dddf1baf584c67fd9aa8446e2b85141e189c1ec4332dfbc77c
6
+ metadata.gz: ff8b3600a3cb1319f49cfc4abef91b0494973f21f4cf3b8c958d860bf61c2223fdb32fe7b4f6bd959096fe5198cb10349ffb4d15417b24f48d067055deb5258d
7
+ data.tar.gz: 2227d88abf6fe8c3829fce89535b371af53302c0c761b63569fbd9d0b0831bc7acc80f383f09e3a0d7cf80ae1c2afa90978f14ba543f9f11330693aa1b2ec175
@@ -0,0 +1,6 @@
1
+ # .travis.yml
2
+ language: ruby
3
+ rvm:
4
+ - 2.0.0
5
+ script:
6
+ - bundle exec rake test
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rocx (0.5.5)
4
+ rocx (0.5.7)
5
5
  nokogiri
6
6
  open_xml_package
7
7
 
@@ -1,7 +1,7 @@
1
+ require "rocx/properties"
1
2
  require "rocx/elements"
2
3
  require "rocx/package"
3
4
  require "rocx/parts"
4
- require "rocx/properties"
5
5
  require "rocx/style"
6
6
 
7
7
  module Rocx
@@ -9,7 +9,7 @@ module Rocx
9
9
  @properties_tag
10
10
  end
11
11
 
12
- def property(name)
12
+ def value_property(name)
13
13
  attr_reader name
14
14
 
15
15
  define_method "#{name}=" do |value|
@@ -21,6 +21,21 @@ module Rocx
21
21
  properties << name
22
22
  end
23
23
 
24
+ def property(name)
25
+ define_method "#{name}" do
26
+ class_name = name.to_s.split("_").map(&:capitalize).join
27
+ prop_class = Rocx::Properties.const_get class_name
28
+
29
+ if instance_variable_get("@#{name}").nil?
30
+ instance_variable_set "@#{name}", prop_class.new
31
+ end
32
+
33
+ instance_variable_get "@#{name}"
34
+ end
35
+
36
+ properties << name
37
+ end
38
+
24
39
  def properties
25
40
  @properties ||= []
26
41
  end
@@ -46,7 +61,7 @@ module Rocx
46
61
 
47
62
  def property_xml(xml)
48
63
  props = properties.map(&method(:send)).compact
49
- return if props.empty?
64
+ return if props.none?(&:render?)
50
65
  xml[namespace].public_send(properties_tag) {
51
66
  props.each { |prop| prop.to_xml(xml) }
52
67
  }
@@ -5,27 +5,39 @@ module Rocx
5
5
  namespace :w
6
6
  properties_tag :pPr
7
7
 
8
- property :alignment
9
- property :auto_adjust_right_indent
10
- property :auto_space_de
11
- property :auto_space_dn
12
- property :bidi
13
- property :conditional_formatting
14
- property :contextual_spacing
15
- property :div_id
16
- property :keep_lines
17
- property :keep_next
18
- property :indentation
19
- property :mirror_indent
20
- property :outline_level
21
- property :overflow_punctuation
22
- property :page_break_before
23
- property :snap_to_grid
24
- property :supress_auto_hyphens
25
- property :supress_line_numbers
26
- property :supress_overlap
27
- property :widow_control
28
- property :word_wrap
8
+ value_property :alignment
9
+ value_property :auto_adjust_right_indent
10
+ value_property :auto_space_de
11
+ value_property :auto_space_dn
12
+ value_property :bidi
13
+ value_property :compress_punctuation
14
+ value_property :conditional_formatting
15
+ value_property :contextual_spacing
16
+ value_property :div_id
17
+ value_property :keep_lines
18
+ value_property :keep_next
19
+ value_property :indentation
20
+ value_property :mirror_indent
21
+ value_property :outline_level
22
+ value_property :overflow_punctuation
23
+ value_property :page_break_before
24
+ value_property :snap_to_grid
25
+ value_property :style
26
+ value_property :supress_auto_hyphens
27
+ value_property :supress_line_numbers
28
+ value_property :supress_overlap
29
+ value_property :textbox_tight_wrap
30
+ value_property :text_direction
31
+ value_property :vertical_alignment
32
+ value_property :widow_control
33
+ value_property :word_wrap
34
+
35
+ property :borders
36
+ property :frame
37
+ property :numbering
38
+ property :shading
39
+ property :spacing
40
+ property :tabs
29
41
  end
30
42
  end
31
43
  end
@@ -4,8 +4,8 @@ module Rocx
4
4
  tag_name :r
5
5
  namespace :w
6
6
  properties_tag :rPr
7
- property :italics
8
- property :bold
7
+ value_property :italics
8
+ value_property :bold
9
9
 
10
10
  end
11
11
  end
@@ -0,0 +1,19 @@
1
+ module Rocx
2
+ module Properties
3
+ class Style < BaseProperty
4
+
5
+ def valid?
6
+ !value.nil?
7
+ end
8
+
9
+ def tag
10
+ :pStyle
11
+ end
12
+
13
+ def to_xml(xml)
14
+ xml["w"].public_send(tag, "w:val" => value)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -15,6 +15,10 @@ module Rocx
15
15
  end
16
16
 
17
17
  def read
18
+ strip_whitespace to_xml
19
+ end
20
+
21
+ def to_xml
18
22
  raise NotImplementedError
19
23
  end
20
24
 
@@ -28,19 +28,15 @@ module Rocx
28
28
  overrides << {"PartName" => part_name, "ContentType" => content_type}
29
29
  end
30
30
 
31
- def read
32
- xml = build_xml do |xml|
31
+ def to_xml
32
+ build_xml do |xml|
33
33
  xml.Types(xmlns: "http://schemas.openxmlformats.org/package/2006/content-types") {
34
34
  defaults.each { |default| xml.Default(default) }
35
35
  overrides.each { |override| xml.Override(override) }
36
36
  }
37
37
  end
38
- strip_whitespace(xml)
39
38
  end
40
39
 
41
40
  end
42
41
  end
43
42
  end
44
-
45
-
46
-
@@ -11,8 +11,8 @@ module Rocx
11
11
  children << child
12
12
  end
13
13
 
14
- def read
15
- xml = build_xml do |xml|
14
+ def to_xml
15
+ build_xml do |xml|
16
16
  xml.document(root_namespaces) {
17
17
  xml.parent.namespace = xml.parent.namespace_definitions.find { |ns| ns.prefix == 'w' }
18
18
  xml['w'].body {
@@ -20,7 +20,6 @@ module Rocx
20
20
  }
21
21
  }
22
22
  end
23
- strip_whitespace(xml)
24
23
  end
25
24
 
26
25
  private
@@ -2,13 +2,12 @@ module Rocx
2
2
  module Parts
3
3
  class GlobalRels < BasePart
4
4
 
5
- def read
6
- xml = build_xml do |xml|
5
+ def to_xml
6
+ build_xml do |xml|
7
7
  xml.Relationships(xmlns: "http://schemas.openxmlformats.org/package/2006/relationships") {
8
8
  xml.Relationship(document_relation_attributes)
9
9
  }
10
10
  end
11
- strip_whitespace(xml)
12
11
  end
13
12
 
14
13
  private
@@ -21,15 +21,14 @@ module Rocx
21
21
  relationships << {"Type" => type, "Target" => target, "Id" => id}
22
22
  end
23
23
 
24
- def read
25
- xml = build_xml do |xml|
24
+ def to_xml
25
+ build_xml do |xml|
26
26
  xml.Relationships(xmlns: "http://schemas.openxmlformats.org/package/2006/relationships") {
27
27
  relationships.each do |rel|
28
28
  xml.Relationship(rel)
29
29
  end
30
30
  }
31
31
  end
32
- strip_whitespace(xml)
33
32
  end
34
33
 
35
34
  private
@@ -7,13 +7,12 @@ module Rocx
7
7
  @settings = []
8
8
  end
9
9
 
10
- def read
11
- xml = build_standalone_xml do |xml|
10
+ def to_xml
11
+ build_standalone_xml do |xml|
12
12
  xml.settings("xmlns:w" => "http://schemas.openxmlformats.org/wordprocessingml/2006/main") {
13
13
  xml.parent.namespace = xml.parent.namespace_definitions.find { |ns| ns.prefix == "w" }
14
14
  }
15
15
  end
16
- strip_whitespace(xml)
17
16
  end
18
17
 
19
18
  end
@@ -11,15 +11,14 @@ module Rocx
11
11
  @styles << style
12
12
  end
13
13
 
14
- def read
15
- xml = build_standalone_xml do |xml|
14
+ def to_xml
15
+ build_standalone_xml do |xml|
16
16
  xml.styles(root_namespaces) {
17
17
  xml.parent.namespace = xml.parent.namespace_definitions.find { |ns| ns.prefix == "w" }
18
18
  add_default_styles(xml)
19
19
  styles.each { |style| style.build_xml(xml) }
20
20
  }
21
21
  end
22
- strip_whitespace(xml)
23
22
  end
24
23
 
25
24
  private
@@ -1,6 +1,6 @@
1
1
  module Rocx
2
2
  module Properties
3
- class Alignment
3
+ class Alignment < BaseProperty
4
4
  attr_reader :value
5
5
 
6
6
  OK_VALUES = [:both, :center, :distribute, :end, :highKashida, :lowKashida, :mediumKashida, :numTab, :start, :thaiDistribute]
@@ -0,0 +1,283 @@
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
+ attributes[name] = displays_as || name
215
+ end
216
+
217
+ def attributes
218
+ @attributes ||= {}
219
+ end
220
+ end
221
+
222
+ def render?
223
+ attributes.keys.map(&method(:send)).any?
224
+ end
225
+
226
+ def attributes
227
+ self.class.attributes
228
+ end
229
+
230
+ private
231
+
232
+ def xml_attributes
233
+ attributes.each_with_object({}) do |(name, display), attrs|
234
+ value = send(name)
235
+ attrs["w:#{display}"] = value if value
236
+ end
237
+ end
238
+
239
+ def true_or_false(value)
240
+ message = "Invalid #{name}: frame must be true or false"
241
+ raise ArgumentError, message unless [true, false].member? value
242
+ end
243
+
244
+ def hex_color(value)
245
+ message = "Invalid #{name}: must be :auto or a hex color, e.g. 4F1B8C"
246
+ raise ArgumentError, message unless value == :auto || value =~ /[0-9A-F]{6}/
247
+ end
248
+
249
+ def hex_digit(value)
250
+ message = "Invalid #{name}: must be a two-digit hex number, e.g. BF"
251
+ raise ArgumentError, message unless value =~ /[0-9A-F]{2}/
252
+ end
253
+
254
+ def integer(value)
255
+ message = "Invalid #{name}: must be an integer"
256
+ raise ArgumentError, message unless value.is_a?(Integer)
257
+ end
258
+
259
+ def positive_integer(value)
260
+ message = "Invalid #{name}: must be a positive integer"
261
+ raise ArgumentError, message unless value.is_a?(Integer) && value >= 0
262
+ end
263
+
264
+ def on_or_off(value)
265
+ valid_in? value, [:on, :off]
266
+ end
267
+
268
+ def valid_theme_color(value)
269
+ valid_in? value, VALID_THEME_COLORS
270
+ end
271
+
272
+ def valid_type(value)
273
+ valid_in? value, VALID_TYPES
274
+ end
275
+
276
+ def valid_in?(value, list)
277
+ message = "Invalid #{name}: must be one of #{list.join(", ")}"
278
+ raise ArgumentError, message unless list.member?(value)
279
+ end
280
+
281
+ end
282
+ end
283
+ end