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,45 +3,53 @@ require "spec_helper"
3
3
  describe Rocx::Elements::Break do
4
4
  include ElementTestMacros
5
5
 
6
- context "when creating a new break" do
7
- it "should not accept invalid values for the clear property" do
8
- expect { described_class.new(clear: :obviouslyInvalid) }.to raise_error(ArgumentError)
6
+ it_should_use tag: :br, name: "break"
7
+
8
+ for_attribute(:clear) do
9
+ with_value(:all) do
10
+ it_should_assign_successfully
11
+ it_should_output "<w:br w:clear=\"all\"/>"
9
12
  end
10
13
 
11
- it "should not accept invalid values for the break_type property" do
12
- expect { described_class.new(break_type: :invalidType) }.to raise_error(ArgumentError)
14
+ with_value(:left) do
15
+ it_should_assign_successfully
16
+ it_should_output "<w:br w:clear=\"left\"/>"
13
17
  end
14
- end
15
18
 
16
- context "after initial creation" do
17
- before(:each) do
18
- @node = described_class.new
19
+ with_value(:none) do
20
+ it_should_assign_successfully
21
+ it_should_output "<w:br w:clear=\"none\"/>"
19
22
  end
20
23
 
21
- it "should still not accept invalid values for the clear property" do
22
- node = described_class.new
23
- expect { node.clear = :invalid }.to raise_error(ArgumentError)
24
+ with_value(:right) do
25
+ it_should_assign_successfully
26
+ it_should_output "<w:br w:clear=\"right\"/>"
24
27
  end
25
28
 
26
- it "should still not accept invalid values for the break_type property" do
27
- node = described_class.new
28
- expect { node.break_type = :weird }.to raise_error(ArgumentError)
29
+ with_value(:somethingElse) do
30
+ it_should_raise_an_exception
29
31
  end
30
32
  end
31
33
 
32
- context "when both properties are nil" do
33
- before(:each) do
34
- @node = described_class.new
34
+ for_attribute(:type) do
35
+ with_value(:column) do
36
+ it_should_assign_successfully
37
+ it_should_output "<w:br w:type=\"column\"/>"
35
38
  end
36
39
 
37
- it_should_output_correct_xml
38
- end
40
+ with_value(:page) do
41
+ it_should_assign_successfully
42
+ it_should_output "<w:br w:type=\"page\"/>"
43
+ end
39
44
 
40
- context "when either of the properties isn't nil" do
41
- before(:each) do
42
- @node = described_class.new(break_type: :page, clear: :left)
45
+ with_value(:textWrapping) do
46
+ it_should_assign_successfully
47
+ it_should_output "<w:br w:type=\"textWrapping\"/>"
43
48
  end
44
49
 
45
- it_should_output_correct_xml node_xml: "break_with_attributes"
50
+ with_value(:somethingElse) do
51
+ it_should_raise_an_exception
52
+ end
46
53
  end
54
+
47
55
  end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::CarriageReturn do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :cr, name: "carriage_return"
7
+
8
+ with_no_attributes_set do
9
+ it_should_output "<w:cr/>", assign: false
10
+ end
11
+
12
+ end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::ContentPart do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :contentPart, name: "content_part"
7
+
8
+ for_attribute(:id) do
9
+ with_value("rId8") do
10
+ it_should_assign_successfully
11
+ it_should_output "<w:contentPart r:id=\"rId8\"/>"
12
+ end
13
+
14
+ with_value("") do
15
+ it_should_raise_an_exception
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::Control do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :control, name: "control"
7
+
8
+ for_attribute(:id) do
9
+ with_value("rId5") do
10
+ it_should_assign_successfully
11
+ it_should_output "<w:control r:id=\"rId5\"/>"
12
+ end
13
+
14
+ with_value("") do
15
+ it_should_raise_an_exception
16
+ end
17
+ end
18
+
19
+ for_attribute(:unique_name) do
20
+ with_value("CheckBox1") do
21
+ it_should_assign_successfully
22
+ it_should_output "<w:control w:name=\"CheckBox1\"/>"
23
+ end
24
+
25
+ with_value("") do
26
+ it_should_raise_an_exception
27
+ end
28
+ end
29
+
30
+ for_attribute(:shape_id) do
31
+ with_value("_x0000_s1027") do
32
+ it_should_assign_successfully
33
+ it_should_output "<w:control w:shapeid=\"_x0000_s1027\"/>"
34
+ end
35
+
36
+ with_value("") do
37
+ it_should_raise_an_exception
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::DeletedText do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :del, name: "deleted_text"
7
+
8
+ for_attribute(:space) do
9
+ with_value(nil) do
10
+ it_should_assign_successfully
11
+ it_should_output "<w:del/>"
12
+ end
13
+
14
+ with_value(:preserve) do
15
+ it_should_assign_successfully
16
+ it_should_output "<w:del xml:space=\"preserve\"/>"
17
+ end
18
+
19
+ with_value(:the_final_frontier) do
20
+ it_should_raise_an_exception
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::Dirty do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :dirty, name: "dirty"
7
+
8
+ with_no_attributes_set do
9
+ it_should_output "<w:dirty/>", assign: false
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::LastRenderedPageBreak do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :lastRenderedPageBreak, name: "last_rendered_page_break"
7
+
8
+ with_no_attributes_set do
9
+ it_should_output "<w:lastRenderedPageBreak/>", assign: false
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::LongDay do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :dayLong, name: "long_day"
7
+
8
+ with_no_attributes_set do
9
+ it_should_output "<w:dayLong/>", assign: false
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::LongMonth do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :monthLong, name: "long_month"
7
+
8
+ with_no_attributes_set do
9
+ it_should_output "<w:monthLong/>", assign: false
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::LongYear do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :yearLong, name: "long_year"
7
+
8
+ with_no_attributes_set do
9
+ it_should_output "<w:yearLong/>", assign: false
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::NonbreakingHyphen do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :noBreakHyphen, name: "nonbreaking_hyphen"
7
+
8
+ with_no_attributes_set do
9
+ it_should_output "<w:noBreakHyphen/>", assign: false
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::OptionalHyphen do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :softHyphen, name: "optional_hyphen"
7
+
8
+ with_no_attributes_set do
9
+ it_should_output "<w:softHyphen/>", assign: false
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::PageNumber do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :pgNum, name: "page_number"
7
+
8
+ with_no_attributes_set do
9
+ it_should_output "<w:pgNum/>", assign: false
10
+ end
11
+
12
+ end
@@ -3,17 +3,19 @@ require "spec_helper"
3
3
  describe Rocx::Elements::Paragraph do
4
4
  include ElementTestMacros
5
5
 
6
+ it_should_use tag: :p, name: "paragraph"
7
+
6
8
  context "with runs" do
7
9
  before(:each) do
8
- @node = described_class.new
9
- node.indentation.start = 720
10
- node.indentation.end = -1440
10
+ @instance = described_class.new
11
+ instance.indentation.start = 720
12
+ instance.indentation.end = -1440
11
13
  run = Rocx::Elements::Run.new
12
14
  run << Rocx::Elements::Text.new("Hey Run 1")
13
- node << run
15
+ instance << run
14
16
  run = Rocx::Elements::Run.new
15
17
  run << Rocx::Elements::Text.new("Hey Run 2")
16
- node << run
18
+ instance << run
17
19
  end
18
20
 
19
21
  it_should_output_correct_xml node_xml: "paragraph_with_runs"
@@ -21,8 +23,8 @@ describe Rocx::Elements::Paragraph do
21
23
 
22
24
  context "without runs" do
23
25
  before(:each) do
24
- @node = described_class.new
25
- node.alignment = :center
26
+ @instance = described_class.new
27
+ instance.alignment = :center
26
28
  end
27
29
 
28
30
  it_should_output_correct_xml
@@ -0,0 +1,66 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::Ruby do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :ruby, name: "ruby"
7
+
8
+ it_should_have_property :font_size, as_instance_of: :phonetic_guide_font_size, with_value: 1
9
+ it_should_have_property :base_font_size, as_instance_of: :phonetic_guide_base_font_size, with_value: 1
10
+ it_should_have_property :font_size_raise, as_instance_of: :phonetic_guide_font_size_raise, with_value: 1
11
+ it_should_have_property :language, as_instance_of: :phonetic_guide_language, with_value: "ja-JP"
12
+ it_should_have_property :alignment, as_instance_of: :phonetic_guide_alignment, with_value: :left
13
+
14
+ context "for base text" do
15
+ before(:each) do
16
+ @instance = described_class.new
17
+ text = Rocx::Elements::Text.new("Howdy Partner")
18
+ run = Rocx::Elements::Run.new
19
+ run << text
20
+ instance.base = run
21
+ end
22
+
23
+ it_should_output "<w:ruby>\n <w:rt/>\n <w:rubyBase>\n <w:r>\n <w:t>Howdy Partner</w:t>\n </w:r>\n </w:rubyBase>\n </w:ruby>", assign: false
24
+ end
25
+
26
+ context "for base text and ruby text" do
27
+ before(:each) do
28
+ @instance = described_class.new
29
+ text = Rocx::Elements::Text.new("東̄")
30
+ run = Rocx::Elements::Run.new
31
+ run.bold = true
32
+ run << text
33
+ instance.base = run
34
+
35
+ text = Rocx::Elements::Text.new("tō")
36
+ run = Rocx::Elements::Run.new
37
+ run.bold = true
38
+ run << text
39
+ instance.ruby = run
40
+ end
41
+
42
+ it_should_output "<w:ruby>\n <w:rt>\n <w:r>\n <w:rPr>\n <w:b/>\n </w:rPr>\n <w:t>to&#x304;</w:t>\n </w:r>\n </w:rt>\n <w:rubyBase>\n <w:r>\n <w:rPr>\n <w:b/>\n </w:rPr>\n <w:t>&#x6771;&#x304;</w:t>\n </w:r>\n </w:rubyBase>\n </w:ruby>", assign: false
43
+ end
44
+
45
+ context "with base text, ruby text and properties set" do
46
+ before(:each) do
47
+ @instance = described_class.new
48
+ text = Rocx::Elements::Text.new("東̄")
49
+ run = Rocx::Elements::Run.new
50
+ run.bold = true
51
+ run << text
52
+ instance.base = run
53
+
54
+ text = Rocx::Elements::Text.new("tō")
55
+ run = Rocx::Elements::Run.new
56
+ run.bold = true
57
+ run << text
58
+ instance.ruby = run
59
+
60
+ instance.alignment = :left
61
+ end
62
+
63
+ it_should_output "<w:ruby>\n <w:rubyPr>\n <w:rubyAlign w:val=\"left\"/>\n </w:rubyPr>\n <w:rt>\n <w:r>\n <w:rPr>\n <w:b/>\n </w:rPr>\n <w:t>to&#x304;</w:t>\n </w:r>\n </w:rt>\n <w:rubyBase>\n <w:r>\n <w:rPr>\n <w:b/>\n </w:rPr>\n <w:t>&#x6771;&#x304;</w:t>\n </w:r>\n </w:rubyBase>\n </w:ruby>", assign: false
64
+ end
65
+
66
+ end
@@ -5,8 +5,8 @@ describe Rocx::Elements::Run do
5
5
 
6
6
  context "after creation" do
7
7
  before(:each) do
8
- @node = described_class.new
9
- node.italics = true
8
+ @instance = described_class.new
9
+ instance.italics = true
10
10
  end
11
11
 
12
12
  it_should_output_correct_xml
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::ShortDay do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :dayShort, name: "short_day"
7
+
8
+ with_no_attributes_set do
9
+ it_should_output "<w:dayShort/>", assign: false
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::ShortMonth do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :monthShort, name: "short_month"
7
+
8
+ with_no_attributes_set do
9
+ it_should_output "<w:monthShort/>", assign: false
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe Rocx::Elements::ShortYear do
4
+ include ElementTestMacros
5
+
6
+ it_should_use tag: :yearShort, name: "short_year"
7
+
8
+ with_no_attributes_set do
9
+ it_should_output "<w:yearShort/>", assign: false
10
+ end
11
+
12
+ end