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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4eeb08bee13a8278c055c33dd6c18a6dad0fc8d
4
- data.tar.gz: 3b733fe765443f5e4b56e9794b66f9bae84af56d
3
+ metadata.gz: e9bb4b4bab84d40e70d311607aa9fcf27ede7b44
4
+ data.tar.gz: d2f2f6aa0ddf9e421ac86e31296554e68f53f8a9
5
5
  SHA512:
6
- metadata.gz: 1fb231ad17a78eccddf31d2c3fc7373d0004a5a5cad0412875d0e50dfc6ac268af1891161e3ed05805ae14f2b38f22629fd694ae79a627924b09256219671b46
7
- data.tar.gz: ee68b316c2ba4c1b87cd1f5d3ca1ceaeb6d791881f064267bbdb59b1be775353fd24ddfbe999554ab83d99fa572e33e2ca04d29c718a89da735e9a0573dd932a
6
+ metadata.gz: dabe3d744f0c26832981c7c9bd9b265ef6684645a892cb190eb5c67d7e01a926234d370e9e8aa76839b3e2c0920a323bd567bd08234c96aa46b3db1663e615ed
7
+ data.tar.gz: 558350fdb7d8bd5de5ba2c36cc5f3a2f49f3b5fcf8f38198d07f6d8ad6d6325471c0df7ce180ac59ec5e09afef00afc7e00a95fd61fa325ef7156719a5849a34
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rocx (0.5.8)
4
+ rocx (0.6.0)
5
5
  nokogiri
6
6
  open_xml_package
7
7
 
data/README.md CHANGED
@@ -1,34 +1,67 @@
1
1
  # Rocx [![Code Climate](https://codeclimate.com/github/genebot/rocx.png)](https://codeclimate.com/github/genebot/rocx)
2
2
 
3
- Rocx is a gem for creating .docx (Microsoft Word 2007) files. Using a simple API, you can create Word documents with:
3
+ Rocx is a gem for creating .docx (Office Open XML) files. It's designed to validate _before_ the document is generated, so (hopefully) any errors are caught prior to opening the file using software that can handle OOXML (like Microsoft Word, Apache Open Office, Google Docs, etc).
4
4
 
5
- - Paragraphs
6
- - Titles
7
- - Headings
8
- - Page breaks
9
- - Bullet points
10
- - Tables
11
-
12
- And, coming soon, images and more.
5
+ An example:
6
+
7
+ ```ruby
8
+ require "rocx"
9
+
10
+ text = Rocx::Elements::Text.new("Some text that I want to include in my new OOXML document")
11
+ run = Rocx::Elements::Run.new
12
+ run.bold = true
13
+ run << text
14
+ paragraph = Rocx::Elements::Paragraph.new
15
+ paragraph << run
16
+
17
+ document = Rocx::Package.new
18
+ document.document << paragraph
19
+ document.save("/path/where/i/save/things/test.docx")
20
+ ```
13
21
 
14
22
  ## Installation
15
23
 
16
- Add to your Rails application in the Gemfile:
24
+ You can install Rocx by running `gem install rocx`, or if you like Rails, include `gem "rocx"` in your Gemfile.
25
+
26
+ ## Current features
17
27
 
18
- gem 'rocx'
19
-
20
- And then run:
28
+ - Paragraphs
29
+ - Runs and text
30
+ - Formatting and styles for the paragraphs, runs, and text
21
31
 
22
- bundle install
23
-
24
- Or install it yourself:
32
+ ## Roadmap
33
+
34
+ It's important to note that lists goes off into the future quite a bit, therefore it's very likely that it will change. That being said, this is the plan for future releases:
35
+
36
+ - 0.7.0: Sections
37
+ - 0.8.0: Increased support for styles and fonts
38
+ - 0.9.0: Images and movies
39
+ - 0.10.0: Numbering and lists
40
+ - 0.11.0: Headers and footers
41
+ - 0.12.0: Footnotes and endnotes
42
+ - 0.13.0: Glossary documents
43
+ - 0.14.0: Annotations
44
+ - 0.15.0: Increased support for document-level settings
45
+ - 0.16.0: Tables
46
+ - 0.17.0: Embedded custom markup
47
+ - 0.18.0: Fields and hyperlinks
48
+ - 0.19.0: Mail merge
49
+ - 0.20.0: Layer on a DSL for making the whole thing smoother
25
50
 
26
- gem install rocx
27
-
28
51
  ## Contribute!
29
52
 
53
+ Want to help? Thanks, friend! Here's how:
54
+
30
55
  1. Fork it
31
- 2. Create your feature branch (`git checkout -b my-new-feature`)
32
- 3. Commit your changes (`git commit -am 'Add some feature`)
33
- 4. Push to the branch (`git push origin my-new-feature`)
34
- 5. Create new Pull Request
56
+ 2. Make your changes on a topic branch
57
+ 3. Create new a pull request
58
+ 4. Receive many thank-yous
59
+
60
+ ## Changelog
61
+
62
+ - 0.6.0: Added additional run content
63
+ - 0.5.8: Added run properties
64
+ - 0.5.7: Added paragraph properties
65
+ - 0.5.0: First version with document content (i.e. paragraphs)
66
+ - 0.4.0: Rudimentary support for styles
67
+ - 0.3.0: First version supporting outputting in target format
data/Rakefile CHANGED
@@ -2,3 +2,4 @@ require "rspec/core/rake_task"
2
2
 
3
3
  RSpec::Core::RakeTask.new
4
4
  task default: :spec
5
+ task test: :spec
data/lib/rocx.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "rocx/attribute_builder"
1
2
  require "rocx/properties"
2
3
  require "rocx/elements"
3
4
  require "rocx/package"
@@ -0,0 +1,296 @@
1
+ module Rocx
2
+ module AttributeBuilder
3
+
4
+ VALID_THEME_COLORS = %i(accent1 accent2 accent3 accent4 accent5 accent6 background1 background2 dark1 dark2 followedHyperlink hyperlink light1 light2 none text1 text2)
5
+
6
+ VALID_TYPES = %i(apples
7
+ archedScallops
8
+ babyPacifier
9
+ babyRattle
10
+ balloons3Colors
11
+ balloonsHotAir
12
+ basicBlackDashes
13
+ basicBlackDots
14
+ basicBlackSquares
15
+ basicThinLines
16
+ basicWhiteDashes
17
+ basicWhiteDots
18
+ basicWhiteSquares
19
+ basicWideInline
20
+ basicWideMidline
21
+ basicWideOutline
22
+ bats
23
+ birds
24
+ birdsFlight
25
+ cabins
26
+ cakeSlice
27
+ candyCorn
28
+ celticKnotwork
29
+ certificateBanner
30
+ chainLink
31
+ champagneBottle
32
+ checkedBarBlack
33
+ checkedBarColor
34
+ checkered
35
+ christmasTree
36
+ circlesLines
37
+ circlesRectangles
38
+ classicalWave
39
+ clocks
40
+ compass
41
+ confetti
42
+ confettiGrays
43
+ confettiOutlines
44
+ confettiStreamers
45
+ confettiWhite
46
+ cornerTriangles
47
+ couponCutoutDashes
48
+ couponCutoutDots
49
+ crazyMaze
50
+ creaturesButterfly
51
+ creaturesFish
52
+ creaturesInsects
53
+ creaturesLadyBug
54
+ crossStitch
55
+ cup
56
+ custom
57
+ dashDotStroked
58
+ dashed
59
+ dashSmallGap
60
+ decoArch
61
+ decoArchColor
62
+ decoBlocks
63
+ diamondsGray
64
+ dotDash
65
+ dotDotDash
66
+ dotted
67
+ double
68
+ doubleD
69
+ doubleDiamonds
70
+ doubleWave
71
+ earth1
72
+ earth2
73
+ earth3
74
+ eclipsingSquares1
75
+ eclipsingSquares2
76
+ eggsBlack
77
+ fans
78
+ film
79
+ firecrackers
80
+ flowersBlockPrint
81
+ flowersDaisies
82
+ flowersModern1
83
+ flowersModern2
84
+ flowersPansy
85
+ flowersRedRose
86
+ flowersRoses
87
+ flowersTeacup
88
+ flowersTiny
89
+ gems
90
+ gingerbreadMan
91
+ gradient
92
+ handmade1
93
+ handmade2
94
+ heartBalloon
95
+ heartGray
96
+ hearts
97
+ heebieJeebies
98
+ holly
99
+ houseFunky
100
+ hypnotic
101
+ iceCreamCones
102
+ inset
103
+ lightBulb
104
+ lightning1
105
+ lightning2
106
+ mapleLeaf
107
+ mapleMuffins
108
+ mapPins
109
+ marquee
110
+ marqueeToothed
111
+ moons
112
+ mosaic
113
+ musicNotes
114
+ nil
115
+ none
116
+ northwest
117
+ outset
118
+ ovals
119
+ packages
120
+ palmsBlack
121
+ palmsColor
122
+ paperClips
123
+ papyrus
124
+ partyFavor
125
+ partyGlass
126
+ pencils
127
+ people
128
+ peopleHats
129
+ peopleWaving
130
+ poinsettias
131
+ postageStamp
132
+ pumpkin1
133
+ pushPinNote1
134
+ pushPinNote2
135
+ pyramids
136
+ pyramidsAbove
137
+ quadrants
138
+ rings
139
+ safari
140
+ sawtooth
141
+ sawtoothGray
142
+ scaredCat
143
+ seattle
144
+ shadowedSquares
145
+ shapes1
146
+ shapes2
147
+ sharksTeeth
148
+ shorebirdTracks
149
+ single
150
+ skyrocket
151
+ snowflakeFancy
152
+ snowflaskes
153
+ sombrero
154
+ southwest
155
+ stars
156
+ stars3d
157
+ starsBlack
158
+ starsShadowed
159
+ starsTop
160
+ sun
161
+ swirligig
162
+ thick
163
+ thickThinLargeGap
164
+ thickThinMediumGap
165
+ thickThinSmallGap
166
+ thinThickLargeGap
167
+ thinThickMediumGap
168
+ thinThickSmallGap
169
+ thinThickThinLargeGap
170
+ thinThickThinMediumGap
171
+ thinThickThinSmallGap
172
+ threeDEmboss
173
+ threeDEngrave
174
+ tornPaper
175
+ tornPaperBlack
176
+ trees
177
+ triangle1
178
+ triangle2
179
+ triangleCircle1
180
+ triangleCircle2
181
+ triangleParty
182
+ triangle
183
+ triple
184
+ twistedLines1
185
+ twistedLines2
186
+ vine
187
+ wave
188
+ waveline
189
+ weavingAngles
190
+ weavingBraid
191
+ weavingRibbon
192
+ weavingStrips
193
+ whiteFlowers
194
+ woodwork
195
+ xIllusions
196
+ zanyTriangles
197
+ zigZag
198
+ zigZagStitch)
199
+
200
+ def self.included(base)
201
+ base.extend(ClassMethods)
202
+ end
203
+
204
+ module ClassMethods
205
+ def attribute(name, expects: nil, displays_as: nil, namespace: nil)
206
+ bad_names = %w(tag name namespace properties_tag)
207
+ raise ArgumentError if bad_names.member? name
208
+
209
+ attr_reader name
210
+
211
+ define_method "#{name}=" do |value|
212
+ send(expects, value)
213
+ instance_variable_set "@#{name}", value
214
+ end
215
+
216
+ camelized_name = name.to_s.gsub(/_([a-z])/i) { $1.upcase }.to_sym
217
+ attributes[name] = [displays_as || camelized_name, namespace || :w]
218
+ end
219
+
220
+ def attributes
221
+ @attributes ||= {}
222
+ end
223
+ end
224
+
225
+ def render?
226
+ attributes.keys.map(&method(:send)).any?
227
+ end
228
+
229
+ def attributes
230
+ self.class.attributes
231
+ end
232
+
233
+ private
234
+
235
+ def xml_attributes
236
+ attributes.each_with_object({}) do |(name, options), attrs|
237
+ display, namespace = options
238
+ value = send(name)
239
+ attrs["#{namespace}:#{display}"] = value if value
240
+ end
241
+ end
242
+
243
+ def true_or_false(value)
244
+ message = "Invalid #{name}: frame must be true or false"
245
+ raise ArgumentError, message unless [true, false].member? value
246
+ end
247
+
248
+ def hex_color(value)
249
+ message = "Invalid #{name}: must be :auto or a hex color, e.g. 4F1B8C"
250
+ raise ArgumentError, message unless value == :auto || value =~ /[0-9A-F]{6}/
251
+ end
252
+
253
+ def hex_digit(value)
254
+ message = "Invalid #{name}: must be a two-digit hex number, e.g. BF"
255
+ raise ArgumentError, message unless value =~ /[0-9A-F]{2}/
256
+ end
257
+
258
+ def hex_digit_4(value)
259
+ message = "Invalid #{name}: must be a four-digit hex number, e.g. BF12"
260
+ raise ArgumentError, message unless value =~ /[0-9A-F]{4}/
261
+ end
262
+
263
+ def integer(value)
264
+ message = "Invalid #{name}: must be an integer"
265
+ raise ArgumentError, message unless value.is_a?(Integer)
266
+ end
267
+
268
+ def positive_integer(value)
269
+ message = "Invalid #{name}: must be a positive integer"
270
+ raise ArgumentError, message unless value.is_a?(Integer) && value >= 0
271
+ end
272
+
273
+ def string(value)
274
+ message = "Invalid #{name}: must be a string"
275
+ raise ArgumentError, message if !value.is_a?(String) || value.length.zero?
276
+ end
277
+
278
+ def on_or_off(value)
279
+ valid_in? value, [:on, :off]
280
+ end
281
+
282
+ def valid_theme_color(value)
283
+ valid_in? value, VALID_THEME_COLORS
284
+ end
285
+
286
+ def valid_type(value)
287
+ valid_in? value, VALID_TYPES
288
+ end
289
+
290
+ def valid_in?(value, list)
291
+ message = "Invalid #{name}: must be one of #{list.join(", ")} (was #{value.inspect})"
292
+ raise ArgumentError, message unless list.member?(value)
293
+ end
294
+
295
+ end
296
+ end
data/lib/rocx/elements.rb CHANGED
@@ -3,8 +3,9 @@ module Rocx
3
3
  end
4
4
  end
5
5
 
6
- require "rocx/elements/base_element"
7
- require "rocx/elements/base_container"
6
+ require "rocx/elements/element"
7
+ require "rocx/elements/container"
8
+ require "rocx/elements/text"
8
9
  Dir.glob("#{File.join(File.dirname(__FILE__), "elements", "*.rb")}").each do |file|
9
10
  require file
10
11
  end
@@ -0,0 +1,29 @@
1
+ module Rocx
2
+ module Elements
3
+ class AbsolutePositionTab < Element
4
+ tag :ptab
5
+ attribute :alignment, expects: :valid_ptab_alignment
6
+ attribute :leader, expects: :valid_ptab_leader
7
+ attribute :relativeTo, expects: :valid_ptab_relative_to
8
+
9
+ VALID_PTAB_ALIGNMENTS = %i(center left right)
10
+ VALID_PTAB_LEADERS = %i(dot hyphen middleDot none underscore)
11
+ VALID_PTAB_RELATIVE_TOS = %i(indent margin)
12
+
13
+ private
14
+
15
+ def valid_ptab_alignment(value)
16
+ valid_in? value, VALID_PTAB_ALIGNMENTS
17
+ end
18
+
19
+ def valid_ptab_leader(value)
20
+ valid_in? value, VALID_PTAB_LEADERS
21
+ end
22
+
23
+ def valid_ptab_relative_to(value)
24
+ valid_in? value, VALID_PTAB_RELATIVE_TOS
25
+ end
26
+
27
+ end
28
+ end
29
+ end