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
@@ -3,22 +3,32 @@ require "spec_helper"
3
3
  describe Rocx::Elements::Symbol do
4
4
  include ElementTestMacros
5
5
 
6
- context "always" do
7
- before(:each) do
8
- @node = described_class.new
6
+ it_should_use tag: :sym, name: "symbol"
7
+
8
+ for_attribute(:font) do
9
+ with_value("Wingdings") do
10
+ it_should_assign_successfully
11
+ it_should_output "<w:sym w:font=\"Wingdings\"/>"
9
12
  end
10
13
 
11
- it "should raise an exception if the char property isn't a 4-digit hex" do
12
- expect { node.char = "not valid" }.to raise_error(ArgumentError)
13
- expect { node.char = "43fd" }.to_not raise_error
14
+ with_value(123) do
15
+ it_should_raise_an_exception
14
16
  end
15
17
  end
16
18
 
17
- context "with valid attributes" do
18
- before(:each) do
19
- @node = described_class.new(char: "43fd", font: "Wingdings")
19
+ for_attribute(:character) do
20
+ with_value("43FD") do
21
+ it_should_assign_successfully
22
+ it_should_output "<w:sym w:char=\"43FD\"/>"
23
+ end
24
+
25
+ with_value("43gg") do
26
+ it_should_raise_an_exception
20
27
  end
21
28
 
22
- it_should_output_correct_xml
29
+ with_value("abcdef") do
30
+ it_should_raise_an_exception
31
+ end
23
32
  end
33
+
24
34
  end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::Tab do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :tab, name: "tab"
7
+
8
+ with_no_attributes_set do
9
+ it_should_output "<w:tab/>", assign: false
10
+ end
11
+
12
+ end
@@ -3,21 +3,22 @@ require "spec_helper"
3
3
  describe Rocx::Elements::Text do
4
4
  include ElementTestMacros
5
5
 
6
- context "for the space attribute" do
7
- it "shoudl require space to be :preserve or nil" do
8
- expect { described_class.new("Banana", space: :preserve) }.to_not raise_error
6
+ it_should_use tag: :t, name: "text"
9
7
 
10
- expect { described_class.new("Banana") }.to_not raise_error
11
-
12
- expect { described_class.new("Banana", space: :the_final_frontier) }.to raise_error(ArgumentError)
8
+ for_attribute(:space) do
9
+ with_value(nil) do
10
+ it_should_assign_successfully
11
+ it_should_output "<w:t/>"
13
12
  end
14
- end
15
13
 
16
- context "with valid attributes" do
17
- before(:each) do
18
- @node = described_class.new("Banana", space: :preserve)
14
+ with_value(:preserve) do
15
+ it_should_assign_successfully
16
+ it_should_output "<w:t xml:space=\"preserve\"/>"
19
17
  end
20
18
 
21
- it_should_output_correct_xml
19
+ with_value(:the_final_frontier) do
20
+ it_should_raise_an_exception
21
+ end
22
22
  end
23
+
23
24
  end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Properties::PhoneticGuideAlignment do
4
+ include ValuePropertyTestMacros
5
+
6
+ it_should_use tag: :rubyAlign, name: "alignment", value: :left
7
+
8
+ with_value(:center) do
9
+ it_should_work
10
+ it_should_output "<w:rubyAlign w:val=\"center\"/>"
11
+ end
12
+
13
+ with_value(:distributeLetter) do
14
+ it_should_work
15
+ it_should_output "<w:rubyAlign w:val=\"distributeLetter\"/>"
16
+ end
17
+
18
+ with_value(:distributeSpace) do
19
+ it_should_work
20
+ it_should_output "<w:rubyAlign w:val=\"distributeSpace\"/>"
21
+ end
22
+
23
+ with_value(:left) do
24
+ it_should_work
25
+ it_should_output "<w:rubyAlign w:val=\"left\"/>"
26
+ end
27
+
28
+ with_value(:right) do
29
+ it_should_work
30
+ it_should_output "<w:rubyAlign w:val=\"right\"/>"
31
+ end
32
+
33
+ with_value(:rightVertical) do
34
+ it_should_work
35
+ it_should_output "<w:rubyAlign w:val=\"rightVertical\"/>"
36
+ end
37
+
38
+ with_value(:nope) do
39
+ it_should_not_work
40
+ end
41
+
42
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Properties::PhoneticGuideBaseFontSize do
4
+ include ValuePropertyTestMacros
5
+
6
+ it_should_use tag: :hpsBaseText, name: "base_font_size", value: 1
7
+
8
+ with_value(24) do
9
+ it_should_work
10
+ it_should_output "<w:hpsBaseText w:val=\"24\"/>"
11
+ end
12
+
13
+ with_value(-24) do
14
+ it_should_not_work
15
+ end
16
+
17
+ with_value(:big) do
18
+ it_should_not_work
19
+ end
20
+
21
+ with_value(23.3) do
22
+ it_should_not_work
23
+ end
24
+
25
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Properties::PhoneticGuideFontSizeRaise do
4
+ include ValuePropertyTestMacros
5
+
6
+ it_should_use tag: :hpsRaise, name: "font_size_raise", value: 1
7
+
8
+ with_value(24) do
9
+ it_should_work
10
+ it_should_output "<w:hpsRaise w:val=\"24\"/>"
11
+ end
12
+
13
+ with_value(-24) do
14
+ it_should_not_work
15
+ end
16
+
17
+ with_value(:big) do
18
+ it_should_not_work
19
+ end
20
+
21
+ with_value(23.3) do
22
+ it_should_not_work
23
+ end
24
+
25
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Properties::PhoneticGuideFontSize do
4
+ include ValuePropertyTestMacros
5
+
6
+ it_should_use tag: :hps, name: "font_size", value: 1
7
+
8
+ with_value(24) do
9
+ it_should_work
10
+ it_should_output "<w:hps w:val=\"24\"/>"
11
+ end
12
+
13
+ with_value(-24) do
14
+ it_should_not_work
15
+ end
16
+
17
+ with_value(:big) do
18
+ it_should_not_work
19
+ end
20
+
21
+ with_value(23.3) do
22
+ it_should_not_work
23
+ end
24
+
25
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Properties::PhoneticGuideLanguage do
4
+ include ValuePropertyTestMacros
5
+
6
+ it_should_use tag: :lid, name: "language", value: "ja-JP"
7
+
8
+ with_value("ja-JP") do
9
+ it_should_work
10
+ it_should_output "<w:lid w:val=\"ja-JP\"/>"
11
+ end
12
+ end
@@ -1,11 +1,24 @@
1
1
  module ElementTestMacros
2
2
 
3
- def xml(part)
3
+ def element_xml(part)
4
4
  File.read(File.join(File.dirname(__FILE__), "data", "elements", "#{part}_element.xml")).strip
5
5
  end
6
6
 
7
+ def xml(obj)
8
+ doc = Nokogiri::XML::Builder.new do |xml|
9
+ xml.root("xmlns:w" => "http://wnamespace.org") {
10
+ obj.to_xml(xml)
11
+ }
12
+ end.to_xml
13
+ doc_pattern =~ doc ? $1 : ""
14
+ end
15
+
16
+ def doc_pattern
17
+ /<\?xml\sversion="1.0"\?>\n<root xmlns:w="http:\/\/wnamespace.org">\n\s+([^\s].+)\n<\/root>/m
18
+ end
19
+
7
20
  def self.included(base)
8
- attr_reader :node
21
+ attr_reader :instance, :attribute, :value
9
22
  base.extend ClassMethods
10
23
  end
11
24
 
@@ -20,11 +33,129 @@ module ElementTestMacros
20
33
 
21
34
  generated_xml = Nokogiri::XML::Builder.new do |xml|
22
35
  xml.root("xmlns:w" => "http://wnamespace.org") {
23
- node.to_xml(xml)
36
+ instance.to_xml(xml)
24
37
  }
25
38
  end.to_xml
26
39
 
27
- expect(generated_xml).to eq(xml(node_xml) + "\n")
40
+ expect(generated_xml).to eq(element_xml(node_xml) + "\n")
41
+ end
42
+ end
43
+
44
+ def it_should_use(tag: nil, name: nil, value: nil)
45
+ context "always" do
46
+ before(:each) do
47
+ if value.nil?
48
+ @instance = described_class.new
49
+ else
50
+ @instance = described_class.new(*value)
51
+ end
52
+ end
53
+
54
+ it "should use the correct tag" do
55
+ expect(instance.tag).to eq(tag)
56
+ end
57
+
58
+ it "should use the correct name" do
59
+ expect(instance.name).to eq(name)
60
+ end
61
+ end
62
+ end
63
+
64
+ def for_attribute(attribute, &block)
65
+ attribute_context = context "for the #{attribute} attribute" do
66
+ before(:each) do
67
+ @attribute = attribute
68
+ end
69
+ end
70
+
71
+ attribute_context.class_eval &block
72
+ end
73
+
74
+ def with_value(value, &block)
75
+ value_context = context "with the value as #{value}" do
76
+ before(:each) do
77
+ @value = value
78
+ end
79
+ end
80
+
81
+ value_context.class_eval &block
82
+ end
83
+
84
+ def it_should_assign_successfully
85
+ it "should assign successfully" do
86
+ expect do
87
+ obj = described_class.new
88
+ obj.send "#{attribute}=", value
89
+ end.to_not raise_error
90
+ end
91
+ end
92
+
93
+ def it_should_raise_an_exception
94
+ it "should raise an exception" do
95
+ expect do
96
+ obj = described_class.new
97
+ obj.send "#{attribute}=", value
98
+ end.to raise_error(ArgumentError)
99
+ end
100
+ end
101
+
102
+ def it_should_output(expected_xml, assign: true)
103
+ it "should output the correct XML" do
104
+ if assign
105
+ @instance = described_class.new
106
+ instance.send "#{attribute}=", value
107
+ end
108
+
109
+ expect(xml(instance)).to eq(expected_xml)
110
+ end
111
+ end
112
+
113
+ def with_no_attributes_set(&block)
114
+ attribute_context = context "with no attributes set" do
115
+ before(:each) do
116
+ @instance = described_class.new
117
+ end
118
+ end
119
+
120
+ attribute_context.class_eval &block
121
+ end
122
+
123
+ def with_these_attributes_set(attributes, &block)
124
+ attribute_context = context "with valid attributes set" do
125
+ before(:each) do
126
+ @instance = described_class.new
127
+ attributes.each do |attr, val|
128
+ instance.send "#{attr}=", val
129
+ end
130
+ end
131
+ end
132
+
133
+ attribute_context.class_eval &block
134
+ end
135
+
136
+ def it_should_have_property(property, as_instance_of: nil, with_value: nil)
137
+ context "this class" do
138
+ before(:each) do
139
+ @instance = described_class.new
140
+ end
141
+
142
+ it "should have the #{property} method defined" do
143
+ expect(instance.respond_to?("#{property}")).to be(true)
144
+ end
145
+
146
+ it "should have the #{property}= method defined" do
147
+ expect(instance.respond_to?("#{property}=")).to be(true)
148
+ end
149
+
150
+ if as_instance_of
151
+ it "should have #{property} return an instance of #{as_instance_of}" do
152
+ instance.public_send "#{property}=", with_value
153
+ class_name = as_instance_of.to_s.split("_").map(&:capitalize).join
154
+ prop_class = Rocx::Properties.const_get class_name
155
+ expect(instance.public_send(property)).to be_instance_of(prop_class)
156
+ end
157
+ end
158
+
28
159
  end
29
160
  end
30
161
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rocx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.8
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gene Doyel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-12 00:00:00.000000000 Z
11
+ date: 2014-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -137,13 +137,34 @@ files:
137
137
  - README.md
138
138
  - Rakefile
139
139
  - lib/rocx.rb
140
+ - lib/rocx/attribute_builder.rb
140
141
  - lib/rocx/elements.rb
141
- - lib/rocx/elements/base_container.rb
142
- - lib/rocx/elements/base_element.rb
142
+ - lib/rocx/elements/absolute_position_tab.rb
143
+ - lib/rocx/elements/bidi_embed.rb
144
+ - lib/rocx/elements/bidi_override.rb
143
145
  - lib/rocx/elements/break.rb
146
+ - lib/rocx/elements/carriage_return.rb
147
+ - lib/rocx/elements/container.rb
148
+ - lib/rocx/elements/content_part.rb
149
+ - lib/rocx/elements/control.rb
150
+ - lib/rocx/elements/deleted_text.rb
151
+ - lib/rocx/elements/dirty.rb
152
+ - lib/rocx/elements/element.rb
153
+ - lib/rocx/elements/last_rendered_page_break.rb
154
+ - lib/rocx/elements/long_day.rb
155
+ - lib/rocx/elements/long_month.rb
156
+ - lib/rocx/elements/long_year.rb
157
+ - lib/rocx/elements/nonbreaking_hyphen.rb
158
+ - lib/rocx/elements/optional_hyphen.rb
159
+ - lib/rocx/elements/page_number.rb
144
160
  - lib/rocx/elements/paragraph.rb
161
+ - lib/rocx/elements/ruby.rb
145
162
  - lib/rocx/elements/run.rb
163
+ - lib/rocx/elements/short_day.rb
164
+ - lib/rocx/elements/short_month.rb
165
+ - lib/rocx/elements/short_year.rb
146
166
  - lib/rocx/elements/symbol.rb
167
+ - lib/rocx/elements/tab.rb
147
168
  - lib/rocx/elements/text.rb
148
169
  - lib/rocx/package.rb
149
170
  - lib/rocx/parts.rb
@@ -156,7 +177,6 @@ files:
156
177
  - lib/rocx/parts/styles.rb
157
178
  - lib/rocx/properties.rb
158
179
  - lib/rocx/properties/alignment.rb
159
- - lib/rocx/properties/attribute_builder.rb
160
180
  - lib/rocx/properties/auto_adjust_right_indent.rb
161
181
  - lib/rocx/properties/auto_space_de.rb
162
182
  - lib/rocx/properties/auto_space_dn.rb
@@ -209,6 +229,11 @@ files:
209
229
  - lib/rocx/properties/overflow_punctuation.rb
210
230
  - lib/rocx/properties/page_break_before.rb
211
231
  - lib/rocx/properties/paragraph_style.rb
232
+ - lib/rocx/properties/phonetic_guide_alignment.rb
233
+ - lib/rocx/properties/phonetic_guide_base_font_size.rb
234
+ - lib/rocx/properties/phonetic_guide_font_size.rb
235
+ - lib/rocx/properties/phonetic_guide_font_size_raise.rb
236
+ - lib/rocx/properties/phonetic_guide_language.rb
212
237
  - lib/rocx/properties/position.rb
213
238
  - lib/rocx/properties/positive_integer_property.rb
214
239
  - lib/rocx/properties/right_to_left.rb
@@ -239,10 +264,30 @@ files:
239
264
  - lib/rocx/style.rb
240
265
  - lib/rocx/version.rb
241
266
  - rocx.gemspec
267
+ - spec/elements/absolute_position_tab_spec.rb
268
+ - spec/elements/bidi_embed_spec.rb
269
+ - spec/elements/bidi_override_spec.rb
242
270
  - spec/elements/break_spec.rb
271
+ - spec/elements/carriage_return_spec.rb
272
+ - spec/elements/content_part_spec.rb
273
+ - spec/elements/control_spec.rb
274
+ - spec/elements/deleted_text_spec.rb
275
+ - spec/elements/dirty_spec.rb
276
+ - spec/elements/last_rendered_page_break_spec.rb
277
+ - spec/elements/long_day_spec.rb
278
+ - spec/elements/long_month_spec.rb
279
+ - spec/elements/long_year_spec.rb
280
+ - spec/elements/nonbreaking_hyphen_spec.rb
281
+ - spec/elements/optional_hyphen_spec.rb
282
+ - spec/elements/page_number_spec.rb
243
283
  - spec/elements/paragraph_spec.rb
284
+ - spec/elements/ruby_spec.rb
244
285
  - spec/elements/run_spec.rb
286
+ - spec/elements/short_day_spec.rb
287
+ - spec/elements/short_month_spec.rb
288
+ - spec/elements/short_year_spec.rb
245
289
  - spec/elements/symbol_spec.rb
290
+ - spec/elements/tab_spec.rb
246
291
  - spec/elements/text_spec.rb
247
292
  - spec/package_spec.rb
248
293
  - spec/parts/content_types_spec.rb
@@ -299,6 +344,11 @@ files:
299
344
  - spec/properties/overflow_punctuation_spec.rb
300
345
  - spec/properties/page_break_before_spec.rb
301
346
  - spec/properties/paragraph_style_spec.rb
347
+ - spec/properties/phonetic_guide_alignment_spec.rb
348
+ - spec/properties/phonetic_guide_base_font_size_spec.rb
349
+ - spec/properties/phonetic_guide_font_size_raise_spec.rb
350
+ - spec/properties/phonetic_guide_font_size_spec.rb
351
+ - spec/properties/phonetic_guide_language_spec.rb
302
352
  - spec/properties/position_spec.rb
303
353
  - spec/properties/right_to_left_spec.rb
304
354
  - spec/properties/run_style_spec.rb