rocx 0.6.0 → 0.7.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rocx.rb +2 -0
- data/lib/rocx/elements/container.rb +2 -56
- data/lib/rocx/elements/paper_source.rb +11 -0
- data/lib/rocx/elements/paragraph.rb +16 -1
- data/lib/rocx/parts/document.rb +18 -4
- data/lib/rocx/properties.rb +1 -0
- data/lib/rocx/properties/column.rb +16 -0
- data/lib/rocx/properties/columns.rb +13 -0
- data/lib/rocx/properties/container_property.rb +63 -0
- data/lib/rocx/properties/document_grid.rb +20 -0
- data/lib/rocx/properties/form_protection.rb +7 -0
- data/lib/rocx/properties/line_numbering.rb +21 -0
- data/lib/rocx/properties/page_borders.rb +59 -0
- data/lib/rocx/properties/page_margins.rb +15 -0
- data/lib/rocx/properties/page_numbering.rb +87 -0
- data/lib/rocx/properties/page_size.rb +21 -0
- data/lib/rocx/properties/{borders.rb → paragraph_borders.rb} +3 -2
- data/lib/rocx/properties/rtl_gutter.rb +6 -0
- data/lib/rocx/properties/section_type.rb +13 -0
- data/lib/rocx/properties/tabs.rb +2 -41
- data/lib/rocx/properties/vertical_text_alignment.rb +12 -0
- data/lib/rocx/property_builder.rb +72 -0
- data/lib/rocx/section.rb +34 -0
- data/lib/rocx/version.rb +1 -1
- data/spec/elements/ruby_spec.rb +5 -5
- data/spec/parts/document_spec.rb +63 -0
- data/spec/properties/column_spec.rb +46 -0
- data/spec/properties/columns_spec.rb +174 -0
- data/spec/properties/document_grid_spec.rb +78 -0
- data/spec/properties/form_protection_spec.rb +23 -0
- data/spec/properties/line_numbering_spec.rb +96 -0
- data/spec/properties/page_borders_spec.rb +129 -0
- data/spec/properties/page_margins_spec.rb +150 -0
- data/spec/properties/page_numbering_spec.rb +395 -0
- data/spec/properties/page_size_spec.rb +90 -0
- data/spec/properties/paper_source_spec.rb +56 -0
- data/spec/properties/{borders_spec.rb → paragraph_borders_spec.rb} +1 -1
- data/spec/properties/rtl_gutter_spec.rb +23 -0
- data/spec/properties/section_type_spec.rb +33 -0
- data/spec/properties/vertical_text_alignment_spec.rb +28 -0
- data/spec/section_spec.rb +44 -0
- data/spec/support/data/parts/document_with_multiple_sections_part.xml +24 -0
- data/spec/support/data/parts/document_with_one_section_part.xml +16 -0
- data/spec/support/element_test_macros.rb +28 -8
- data/spec/support/part_test_macros.rb +1 -1
- data/spec/support/property_test_macros.rb +4 -4
- metadata +36 -4
@@ -0,0 +1,78 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rocx::Properties::DocumentGrid do
|
4
|
+
include PropertyTestMacros
|
5
|
+
|
6
|
+
it_should_use tag: :docGrid, name: "document_grid"
|
7
|
+
|
8
|
+
for_attribute(:char_space) do
|
9
|
+
with_value(40960) do
|
10
|
+
it_should_assign_successfully
|
11
|
+
it_should_output "<w:docGrid w:charSpace=\"40960\"/>"
|
12
|
+
end
|
13
|
+
|
14
|
+
with_value(:twelve) do
|
15
|
+
it_should_raise_an_exception
|
16
|
+
end
|
17
|
+
|
18
|
+
with_value(-12345) do
|
19
|
+
it_should_assign_successfully
|
20
|
+
it_should_output "<w:docGrid w:charSpace=\"-12345\"/>"
|
21
|
+
end
|
22
|
+
|
23
|
+
with_value(123.45) do
|
24
|
+
it_should_raise_an_exception
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
for_attribute(:line_pitch) do
|
29
|
+
with_value(40960) do
|
30
|
+
it_should_assign_successfully
|
31
|
+
it_should_output "<w:docGrid w:linePitch=\"40960\"/>"
|
32
|
+
end
|
33
|
+
|
34
|
+
with_value(:twelve) do
|
35
|
+
it_should_raise_an_exception
|
36
|
+
end
|
37
|
+
|
38
|
+
with_value(-12345) do
|
39
|
+
it_should_assign_successfully
|
40
|
+
it_should_output "<w:docGrid w:linePitch=\"-12345\"/>"
|
41
|
+
end
|
42
|
+
|
43
|
+
with_value(123.45) do
|
44
|
+
it_should_raise_an_exception
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
for_attribute(:type) do
|
49
|
+
with_value(:default) do
|
50
|
+
it_should_assign_successfully
|
51
|
+
it_should_output "<w:docGrid w:type=\"default\"/>"
|
52
|
+
end
|
53
|
+
|
54
|
+
with_value(:lines) do
|
55
|
+
it_should_assign_successfully
|
56
|
+
it_should_output "<w:docGrid w:type=\"lines\"/>"
|
57
|
+
end
|
58
|
+
|
59
|
+
with_value(:linesAndChars) do
|
60
|
+
it_should_assign_successfully
|
61
|
+
it_should_output "<w:docGrid w:type=\"linesAndChars\"/>"
|
62
|
+
end
|
63
|
+
|
64
|
+
with_value(:snapToChars) do
|
65
|
+
it_should_assign_successfully
|
66
|
+
it_should_output "<w:docGrid w:type=\"snapToChars\"/>"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
with_no_attributes_set do
|
71
|
+
it_should_output "", assign: false
|
72
|
+
end
|
73
|
+
|
74
|
+
with_these_attributes_set(char_space: 40960, line_pitch: 40960, type: :default) do
|
75
|
+
it_should_output "<w:docGrid w:charSpace=\"40960\" w:linePitch=\"40960\" w:type=\"default\"/>", assign: false
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rocx::Properties::FormProtection do
|
4
|
+
include ValuePropertyTestMacros
|
5
|
+
|
6
|
+
it_should_use tag: :formProt, name: "form_protection"
|
7
|
+
|
8
|
+
with_value(true) do
|
9
|
+
it_should_work
|
10
|
+
it_should_output "<w:formProt/>"
|
11
|
+
end
|
12
|
+
|
13
|
+
with_value(false) do
|
14
|
+
it_should_work
|
15
|
+
it_should_output ""
|
16
|
+
end
|
17
|
+
|
18
|
+
with_value(nil) do
|
19
|
+
it_should_work
|
20
|
+
it_should_output ""
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rocx::Properties::LineNumbering do
|
4
|
+
include PropertyTestMacros
|
5
|
+
|
6
|
+
it_should_use tag: :lnNumType, name: "line_numbering"
|
7
|
+
|
8
|
+
for_attribute(:count_by) do
|
9
|
+
with_value(5) do
|
10
|
+
it_should_assign_successfully
|
11
|
+
it_should_output "<w:lnNumType w:countBy=\"5\"/>"
|
12
|
+
end
|
13
|
+
|
14
|
+
with_value(-5) do
|
15
|
+
it_should_assign_successfully
|
16
|
+
it_should_output "<w:lnNumType w:countBy=\"-5\"/>"
|
17
|
+
end
|
18
|
+
|
19
|
+
with_value(123.4) do
|
20
|
+
it_should_raise_an_exception
|
21
|
+
end
|
22
|
+
|
23
|
+
with_value(:twelve) do
|
24
|
+
it_should_raise_an_exception
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
for_attribute(:distance) do
|
29
|
+
with_value(720) do
|
30
|
+
it_should_assign_successfully
|
31
|
+
it_should_output "<w:lnNumType w:distance=\"720\"/>"
|
32
|
+
end
|
33
|
+
|
34
|
+
with_value(-720) do
|
35
|
+
it_should_raise_an_exception
|
36
|
+
end
|
37
|
+
|
38
|
+
with_value(123.4) do
|
39
|
+
it_should_raise_an_exception
|
40
|
+
end
|
41
|
+
|
42
|
+
with_value(:twelve) do
|
43
|
+
it_should_raise_an_exception
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
for_attribute(:restart) do
|
48
|
+
with_value(:continuous) do
|
49
|
+
it_should_assign_successfully
|
50
|
+
it_should_output "<w:lnNumType w:restart=\"continuous\"/>"
|
51
|
+
end
|
52
|
+
|
53
|
+
with_value(:newPage) do
|
54
|
+
it_should_assign_successfully
|
55
|
+
it_should_output "<w:lnNumType w:restart=\"newPage\"/>"
|
56
|
+
end
|
57
|
+
|
58
|
+
with_value(:newSection) do
|
59
|
+
it_should_assign_successfully
|
60
|
+
it_should_output "<w:lnNumType w:restart=\"newSection\"/>"
|
61
|
+
end
|
62
|
+
|
63
|
+
with_value(:somethingElse) do
|
64
|
+
it_should_raise_an_exception
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
for_attribute(:start) do
|
69
|
+
with_value(5) do
|
70
|
+
it_should_assign_successfully
|
71
|
+
it_should_output "<w:lnNumType w:start=\"5\"/>"
|
72
|
+
end
|
73
|
+
|
74
|
+
with_value(-5) do
|
75
|
+
it_should_assign_successfully
|
76
|
+
it_should_output "<w:lnNumType w:start=\"-5\"/>"
|
77
|
+
end
|
78
|
+
|
79
|
+
with_value(123.4) do
|
80
|
+
it_should_raise_an_exception
|
81
|
+
end
|
82
|
+
|
83
|
+
with_value(:twelve) do
|
84
|
+
it_should_raise_an_exception
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
with_no_attributes_set do
|
89
|
+
it_should_output "", assign: false
|
90
|
+
end
|
91
|
+
|
92
|
+
with_these_attributes_set(start: 3, count_by: 5) do
|
93
|
+
it_should_output "<w:lnNumType w:countBy=\"5\" w:start=\"3\"/>", assign: false
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rocx::Properties::PageBorders do
|
4
|
+
include PropertyTestMacros
|
5
|
+
|
6
|
+
it_should_use tag: :pgBorders, name: "page_borders"
|
7
|
+
|
8
|
+
context "when setting values" do
|
9
|
+
before(:each) do
|
10
|
+
@instance = described_class.new
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should allow modifying the left border" do
|
14
|
+
expect { instance.left.color = :auto }.to_not raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should allow modifying the right border" do
|
18
|
+
expect { instance.right.size = 24 }.to_not raise_error
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should allow modifying the top border" do
|
22
|
+
expect { instance.top.space = 1 }.to_not raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should allow modifying the bottom border" do
|
26
|
+
expect { instance.bottom.type = :apples }.to_not raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
for_attribute(:display) do
|
32
|
+
before(:each) do
|
33
|
+
@instance = described_class.new
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should accept the value :allPages" do
|
37
|
+
expect { instance.send("#{attribute}=", :allPages) }.to_not raise_error
|
38
|
+
instance.send "#{attribute}=", :allPages
|
39
|
+
instance.left.color = :auto
|
40
|
+
expect(xml(instance)).to eq("<w:pgBorders w:display=\"allPages\">\n <w:left w:color=\"auto\"/>\n </w:pgBorders>")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should accept the value :firstPage" do
|
44
|
+
expect { instance.send("#{attribute}=", :firstPage) }.to_not raise_error
|
45
|
+
instance.send "#{attribute}=", :firstPage
|
46
|
+
instance.left.color = :auto
|
47
|
+
expect(xml(instance)).to eq("<w:pgBorders w:display=\"firstPage\">\n <w:left w:color=\"auto\"/>\n </w:pgBorders>")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should accept the value :notFirstPage" do
|
51
|
+
expect { instance.send("#{attribute}=", :notFirstPage) }.to_not raise_error
|
52
|
+
instance.send "#{attribute}=", :notFirstPage
|
53
|
+
instance.left.color = :auto
|
54
|
+
expect(xml(instance)).to eq("<w:pgBorders w:display=\"notFirstPage\">\n <w:left w:color=\"auto\"/>\n </w:pgBorders>")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
for_attribute(:offset_from) do
|
59
|
+
before(:each) do
|
60
|
+
@instance = described_class.new
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should accept the value :page" do
|
64
|
+
expect { instance.send("#{attribute}=", :page) }.to_not raise_error
|
65
|
+
instance.send "#{attribute}=", :page
|
66
|
+
instance.left.color = :auto
|
67
|
+
expect(xml(instance)).to eq("<w:pgBorders w:offsetFrom=\"page\">\n <w:left w:color=\"auto\"/>\n </w:pgBorders>")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should accept the value :text" do
|
71
|
+
expect { instance.send("#{attribute}=", :text) }.to_not raise_error
|
72
|
+
instance.send "#{attribute}=", :text
|
73
|
+
instance.left.color = :auto
|
74
|
+
expect(xml(instance)).to eq("<w:pgBorders w:offsetFrom=\"text\">\n <w:left w:color=\"auto\"/>\n </w:pgBorders>")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
for_attribute(:z_order) do
|
79
|
+
before(:each) do
|
80
|
+
@instance = described_class.new
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should accept the value :back" do
|
84
|
+
expect { instance.send("#{attribute}=", :back) }.to_not raise_error
|
85
|
+
instance.send "#{attribute}=", :back
|
86
|
+
instance.left.color = :auto
|
87
|
+
expect(xml(instance)).to eq("<w:pgBorders w:zOrder=\"back\">\n <w:left w:color=\"auto\"/>\n </w:pgBorders>")
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should accept the value :front" do
|
91
|
+
expect { instance.send("#{attribute}=", :front) }.to_not raise_error
|
92
|
+
instance.send "#{attribute}=", :front
|
93
|
+
instance.left.color = :auto
|
94
|
+
expect(xml(instance)).to eq("<w:pgBorders w:zOrder=\"front\">\n <w:left w:color=\"auto\"/>\n </w:pgBorders>")
|
95
|
+
end
|
96
|
+
|
97
|
+
with_value(:side) do
|
98
|
+
it_should_raise_an_exception
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "with no values set" do
|
103
|
+
before(:each) do
|
104
|
+
@instance = described_class.new
|
105
|
+
end
|
106
|
+
|
107
|
+
it_should_output "", assign: false
|
108
|
+
end
|
109
|
+
|
110
|
+
context "when one border has at least one property set" do
|
111
|
+
before(:each) do
|
112
|
+
@instance = described_class.new
|
113
|
+
instance.left.type = :apples
|
114
|
+
end
|
115
|
+
|
116
|
+
it_should_output "<w:pgBorders>\n <w:left w:val=\"apples\"/>\n </w:pgBorders>", assign: false
|
117
|
+
end
|
118
|
+
|
119
|
+
context "when more than one border has at least one property set" do
|
120
|
+
before(:each) do
|
121
|
+
@instance = described_class.new
|
122
|
+
instance.left.color = "FF0000"
|
123
|
+
instance.right.type = :apples
|
124
|
+
end
|
125
|
+
|
126
|
+
it_should_output "<w:pgBorders>\n <w:left w:color=\"FF0000\"/>\n <w:right w:val=\"apples\"/>\n </w:pgBorders>", assign: false
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Rocx::Properties::PageMargins do
|
4
|
+
include PropertyTestMacros
|
5
|
+
|
6
|
+
it_should_use tag: :pgMar, name: "page_margins"
|
7
|
+
|
8
|
+
for_attribute(:bottom) do
|
9
|
+
with_value(1440) do
|
10
|
+
it_should_assign_successfully
|
11
|
+
it_should_output "<w:pgMar w:bottom=\"1440\"/>"
|
12
|
+
end
|
13
|
+
|
14
|
+
with_value(-1440) do
|
15
|
+
it_should_assign_successfully
|
16
|
+
it_should_output "<w:pgMar w:bottom=\"-1440\"/>"
|
17
|
+
end
|
18
|
+
|
19
|
+
with_value(9832.1) do
|
20
|
+
it_should_raise_an_exception
|
21
|
+
end
|
22
|
+
|
23
|
+
with_value(:big) do
|
24
|
+
it_should_raise_an_exception
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
for_attribute(:footer) do
|
29
|
+
with_value(1440) do
|
30
|
+
it_should_assign_successfully
|
31
|
+
it_should_output "<w:pgMar w:footer=\"1440\"/>"
|
32
|
+
end
|
33
|
+
|
34
|
+
with_value(-1440) do
|
35
|
+
it_should_raise_an_exception
|
36
|
+
end
|
37
|
+
|
38
|
+
with_value(9832.1) do
|
39
|
+
it_should_raise_an_exception
|
40
|
+
end
|
41
|
+
|
42
|
+
with_value(:big) do
|
43
|
+
it_should_raise_an_exception
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
for_attribute(:gutter) do
|
48
|
+
with_value(1440) do
|
49
|
+
it_should_assign_successfully
|
50
|
+
it_should_output "<w:pgMar w:gutter=\"1440\"/>"
|
51
|
+
end
|
52
|
+
|
53
|
+
with_value(-1440) do
|
54
|
+
it_should_raise_an_exception
|
55
|
+
end
|
56
|
+
|
57
|
+
with_value(9832.1) do
|
58
|
+
it_should_raise_an_exception
|
59
|
+
end
|
60
|
+
|
61
|
+
with_value(:big) do
|
62
|
+
it_should_raise_an_exception
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
for_attribute(:header) do
|
67
|
+
with_value(1440) do
|
68
|
+
it_should_assign_successfully
|
69
|
+
it_should_output "<w:pgMar w:header=\"1440\"/>"
|
70
|
+
end
|
71
|
+
|
72
|
+
with_value(-1440) do
|
73
|
+
it_should_raise_an_exception
|
74
|
+
end
|
75
|
+
|
76
|
+
with_value(9832.1) do
|
77
|
+
it_should_raise_an_exception
|
78
|
+
end
|
79
|
+
|
80
|
+
with_value(:big) do
|
81
|
+
it_should_raise_an_exception
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
for_attribute(:left) do
|
86
|
+
with_value(1440) do
|
87
|
+
it_should_assign_successfully
|
88
|
+
it_should_output "<w:pgMar w:left=\"1440\"/>"
|
89
|
+
end
|
90
|
+
|
91
|
+
with_value(-1440) do
|
92
|
+
it_should_raise_an_exception
|
93
|
+
end
|
94
|
+
|
95
|
+
with_value(9832.1) do
|
96
|
+
it_should_raise_an_exception
|
97
|
+
end
|
98
|
+
|
99
|
+
with_value(:big) do
|
100
|
+
it_should_raise_an_exception
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
for_attribute(:right) do
|
105
|
+
with_value(1440) do
|
106
|
+
it_should_assign_successfully
|
107
|
+
it_should_output "<w:pgMar w:right=\"1440\"/>"
|
108
|
+
end
|
109
|
+
|
110
|
+
with_value(-1440) do
|
111
|
+
it_should_raise_an_exception
|
112
|
+
end
|
113
|
+
|
114
|
+
with_value(9832.1) do
|
115
|
+
it_should_raise_an_exception
|
116
|
+
end
|
117
|
+
|
118
|
+
with_value(:big) do
|
119
|
+
it_should_raise_an_exception
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
for_attribute(:top) do
|
124
|
+
with_value(1440) do
|
125
|
+
it_should_assign_successfully
|
126
|
+
it_should_output "<w:pgMar w:top=\"1440\"/>"
|
127
|
+
end
|
128
|
+
|
129
|
+
with_value(-1440) do
|
130
|
+
it_should_assign_successfully
|
131
|
+
it_should_output "<w:pgMar w:top=\"-1440\"/>"
|
132
|
+
end
|
133
|
+
|
134
|
+
with_value(9832.1) do
|
135
|
+
it_should_raise_an_exception
|
136
|
+
end
|
137
|
+
|
138
|
+
with_value(:big) do
|
139
|
+
it_should_raise_an_exception
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
with_no_attributes_set do
|
144
|
+
it_should_output "", assign: false
|
145
|
+
end
|
146
|
+
|
147
|
+
with_these_attributes_set(header: 720, bottom: 1440, top: 1440, right: 1440, left: 1440, footer: 720, gutter: 0) do
|
148
|
+
it_should_output "<w:pgMar w:bottom=\"1440\" w:footer=\"720\" w:gutter=\"0\" w:header=\"720\" w:left=\"1440\" w:right=\"1440\" w:top=\"1440\"/>", assign: false
|
149
|
+
end
|
150
|
+
end
|