xmlss 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -2
- data/Gemfile +1 -0
- data/Gemfile.lock +12 -11
- data/README.rdoc +141 -107
- data/Rakefile +24 -1
- data/bench/profiler.rb +6 -0
- data/bench/profiler_runner.rb +43 -0
- data/examples/example_workbook.rb +8 -12
- data/examples/layout.rb +34 -60
- data/examples/layout.xml +66 -0
- data/examples/simple.rb +16 -21
- data/examples/simple.xml +32 -0
- data/examples/styles.rb +52 -56
- data/examples/styles.xml +50 -0
- data/examples/text.rb +18 -28
- data/examples/text.xml +20 -0
- data/lib/xmlss/{cell.rb → element/cell.rb} +4 -14
- data/lib/xmlss/{column.rb → element/column.rb} +2 -7
- data/lib/xmlss/{data.rb → element/data.rb} +7 -12
- data/lib/xmlss/{row.rb → element/row.rb} +2 -13
- data/lib/xmlss/{worksheet.rb → element/worksheet.rb} +7 -18
- data/lib/xmlss/style/alignment.rb +3 -10
- data/lib/xmlss/style/base.rb +6 -45
- data/lib/xmlss/style/border.rb +5 -5
- data/lib/xmlss/style/font.rb +2 -9
- data/lib/xmlss/style/interior.rb +2 -5
- data/lib/xmlss/style/number_format.rb +4 -7
- data/lib/xmlss/style/protection.rb +4 -7
- data/lib/xmlss/undies_writer.rb +172 -0
- data/lib/xmlss/version.rb +1 -1
- data/lib/xmlss/workbook.rb +97 -31
- data/lib/xmlss.rb +1 -28
- data/test/{cell_test.rb → element/cell_test.rb} +11 -35
- data/test/{column_test.rb → element/column_test.rb} +6 -12
- data/test/{data_test.rb → element/data_test.rb} +15 -10
- data/test/{row_test.rb → element/row_test.rb} +5 -35
- data/test/{worksheet_test.rb → element/worksheet_test.rb} +4 -30
- data/test/helper.rb +13 -30
- data/test/style/alignment_test.rb +13 -45
- data/test/style/base_test.rb +1 -106
- data/test/style/border_test.rb +12 -32
- data/test/style/font_test.rb +11 -43
- data/test/style/interior_test.rb +7 -27
- data/test/style/number_format_test.rb +5 -21
- data/test/style/protection_test.rb +2 -12
- data/test/undies_writer_test.rb +333 -0
- data/test/workbook_test.rb +89 -44
- data/xmlss.gemspec +2 -2
- metadata +37 -39
- data/lib/xmlss/item_set.rb +0 -17
- data/lib/xmlss/table.rb +0 -22
- data/lib/xmlss/xml.rb +0 -60
- data/test/item_set_test.rb +0 -27
- data/test/table_test.rb +0 -56
- data/test/xml_test.rb +0 -81
- data/test/xmlss_test.rb +0 -31
@@ -1,46 +1,38 @@
|
|
1
1
|
require "assert"
|
2
|
+
require 'enumeration/assert_macros'
|
3
|
+
|
2
4
|
require 'xmlss/style/alignment'
|
3
5
|
|
4
6
|
module Xmlss::Style
|
5
7
|
class AlignmentTest < Assert::Context
|
8
|
+
include Enumeration::AssertMacros
|
9
|
+
|
6
10
|
desc "Xmlss::Style::Alignment"
|
7
11
|
before { @a = Alignment.new }
|
8
12
|
subject { @a }
|
9
13
|
|
10
|
-
should
|
11
|
-
|
12
|
-
{
|
14
|
+
should have_enum :horizontal, {
|
13
15
|
:automatic => "Automatic",
|
14
16
|
:left => "Left",
|
15
17
|
:center => "Center",
|
16
18
|
:right => "Right"
|
17
|
-
}
|
18
|
-
should "provide the value for the '#{horizontal}' horizontal" do
|
19
|
-
assert_equal value, Alignment.horizontal(horizontal)
|
20
|
-
end
|
21
|
-
end
|
19
|
+
}
|
22
20
|
|
23
|
-
should
|
24
|
-
|
25
|
-
{
|
21
|
+
should have_enum :vertical, {
|
26
22
|
:automatic => "Automatic",
|
27
23
|
:top => "Top",
|
28
24
|
:center => "Center",
|
29
25
|
:bottom => "Bottom"
|
30
|
-
}
|
31
|
-
should "provide the value for the '#{vertical}' vertical" do
|
32
|
-
assert_equal value, Alignment.vertical(vertical)
|
33
|
-
end
|
34
|
-
end
|
26
|
+
}
|
35
27
|
|
36
|
-
should have_accessors :
|
28
|
+
should have_accessors :wrap_text, :rotate
|
37
29
|
should have_instance_methods :wrap_text?
|
38
30
|
|
39
31
|
should "set it's defaults" do
|
40
32
|
assert_equal false, subject.wrap_text
|
41
|
-
assert_equal nil,
|
42
|
-
assert_equal nil,
|
43
|
-
assert_equal nil,
|
33
|
+
assert_equal nil, subject.horizontal
|
34
|
+
assert_equal nil, subject.vertical
|
35
|
+
assert_equal nil, subject.rotate
|
44
36
|
end
|
45
37
|
|
46
38
|
should "reject invalid rotate alignments" do
|
@@ -55,7 +47,7 @@ module Xmlss::Style
|
|
55
47
|
assert_equal nil, Alignment.new({:rotate => :poo}).rotate
|
56
48
|
end
|
57
49
|
|
58
|
-
should "
|
50
|
+
should "set build with values correctly" do
|
59
51
|
attrs = {
|
60
52
|
:wrap_text => true,
|
61
53
|
:horizontal => :center,
|
@@ -71,30 +63,6 @@ module Xmlss::Style
|
|
71
63
|
assert_equal Alignment.vertical(:bottom), alignment.vertical
|
72
64
|
end
|
73
65
|
|
74
|
-
should "set attrs by key" do
|
75
|
-
subject.horizontal = :left
|
76
|
-
subject.vertical = :top
|
77
|
-
|
78
|
-
assert_equal Alignment.horizontal(:left), subject.horizontal
|
79
|
-
assert_equal Alignment.vertical(:top), subject.vertical
|
80
|
-
end
|
81
|
-
|
82
|
-
should "set attrs by value" do
|
83
|
-
subject.horizontal = Alignment.horizontal(:right)
|
84
|
-
subject.vertical = Alignment.vertical(:center)
|
85
|
-
|
86
|
-
assert_equal Alignment.horizontal(:right), subject.horizontal
|
87
|
-
assert_equal Alignment.vertical(:center), subject.vertical
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
class AlignmentXmlTest < AlignmentTest
|
93
|
-
desc "for generating XML"
|
94
|
-
|
95
|
-
should have_reader :xml
|
96
|
-
should_build_node
|
97
|
-
should_build_no_attributes_by_default(Alignment)
|
98
66
|
end
|
99
67
|
|
100
68
|
end
|
data/test/style/base_test.rb
CHANGED
@@ -8,9 +8,7 @@ module Xmlss::Style
|
|
8
8
|
before { @bs = Base.new(:test) }
|
9
9
|
subject { @bs }
|
10
10
|
|
11
|
-
should have_reader :id, :i_d
|
12
|
-
should have_accessors :borders, :alignment, :font
|
13
|
-
should have_accessors :interior, :number_format, :protection
|
11
|
+
should have_reader :id, :i_d
|
14
12
|
|
15
13
|
should "bark if you don't init with an id" do
|
16
14
|
assert_raises ArgumentError do
|
@@ -26,111 +24,8 @@ module Xmlss::Style
|
|
26
24
|
|
27
25
|
should "set it's defaults" do
|
28
26
|
assert_equal 'test', subject.id
|
29
|
-
assert_equal [], subject.borders
|
30
|
-
[ :alignment, :border, :font,
|
31
|
-
:interior, :number_format, :protection
|
32
|
-
].each do |s|
|
33
|
-
assert_equal nil, subject.send(s)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
class SetAlignmentTest < Assert::Context
|
40
|
-
desc "that sets alignment"
|
41
|
-
before do
|
42
|
-
@s = Base.new(:alignment) do
|
43
|
-
alignment(
|
44
|
-
:horizontal => :left,
|
45
|
-
:vertical => :center,
|
46
|
-
:wrap_text => true
|
47
|
-
)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
subject { @s }
|
51
|
-
|
52
|
-
should "create an Alignment object" do
|
53
|
-
assert_kind_of Alignment, subject.alignment
|
54
|
-
assert_equal true, subject.alignment.wrap_text
|
55
|
-
assert_equal Alignment.horizontal(:left), subject.alignment.horizontal
|
56
|
-
assert_equal Alignment.vertical(:center), subject.alignment.vertical
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
class SetBorderTest < Assert::Context
|
61
|
-
desc "that sets borders"
|
62
|
-
before do
|
63
|
-
@s = Base.new(:borders) do
|
64
|
-
border(:position => :left)
|
65
|
-
border(:position => :right)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
subject { @s }
|
69
|
-
|
70
|
-
should "create Border objects and add them to its borders" do
|
71
|
-
assert_equal 2, subject.borders.size
|
72
|
-
assert_kind_of Border, subject.borders.first
|
73
|
-
assert_equal Border.position(:left), subject.borders.first.position
|
74
|
-
assert_equal Border.position(:right), subject.borders.last.position
|
75
27
|
end
|
76
28
|
|
77
|
-
should "error if manually setting borders to non ItemSet collection" do
|
78
|
-
assert_raises ::ArgumentError do
|
79
|
-
subject.borders = []
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
class SetFontTest < Assert::Context
|
85
|
-
desc "that sets font"
|
86
|
-
before { @s = Base.new(:font) { font(:bold => true) } }
|
87
|
-
subject { @s }
|
88
|
-
|
89
|
-
should "should create a Font object" do
|
90
|
-
assert_kind_of Font, subject.font
|
91
|
-
assert subject.font.bold?
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
class SetInteriorTest < Assert::Context
|
96
|
-
desc "that sets interior"
|
97
|
-
before { @s = Base.new(:interior) { interior(:color => "#000000") } }
|
98
|
-
subject { @s }
|
99
|
-
|
100
|
-
should "should create an Interior object" do
|
101
|
-
assert_kind_of Interior, subject.interior
|
102
|
-
assert_equal "#000000", subject.interior.color
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
class SetNumberFormatTest < Assert::Context
|
107
|
-
desc "that sets number format"
|
108
|
-
before { @s = Base.new(:number_format) { number_format(:format => "General") } }
|
109
|
-
subject { @s }
|
110
|
-
|
111
|
-
should "should create a NumberFormat object" do
|
112
|
-
assert_kind_of NumberFormat, subject.number_format
|
113
|
-
assert_equal "General", subject.number_format.format
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
class SetProtectionTest < Assert::Context
|
118
|
-
desc "that sets protection"
|
119
|
-
before { @s = Base.new(:protection) { protection(:protect => true) } }
|
120
|
-
subject { @s }
|
121
|
-
|
122
|
-
should "should create a Protection object" do
|
123
|
-
assert_kind_of Protection, subject.protection
|
124
|
-
assert subject.protection.protected?
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
class BaseXmlTest < BaseTest
|
129
|
-
desc "for generating XML"
|
130
|
-
|
131
|
-
should have_reader :xml
|
132
|
-
should_build_node
|
133
|
-
should_build_no_attributes_by_default(Xmlss::Style::Alignment)
|
134
29
|
end
|
135
30
|
|
136
31
|
end
|
data/test/style/border_test.rb
CHANGED
@@ -1,56 +1,43 @@
|
|
1
1
|
require "assert"
|
2
|
+
require 'enumeration/assert_macros'
|
3
|
+
|
2
4
|
require 'xmlss/style/border'
|
3
5
|
|
4
6
|
module Xmlss::Style
|
5
7
|
class BorderTest < Assert::Context
|
8
|
+
include Enumeration::AssertMacros
|
9
|
+
|
6
10
|
desc "Xmlss::Style::Border"
|
7
11
|
before { @b = Xmlss::Style::Border.new }
|
8
12
|
subject { @b }
|
9
13
|
|
10
|
-
should
|
11
|
-
|
12
|
-
{
|
14
|
+
should have_enum :position, {
|
13
15
|
:left => "Left",
|
14
16
|
:top => "Top",
|
15
17
|
:right => "Right",
|
16
18
|
:bottom => "Bottom",
|
17
19
|
:diagonal_left => "DiagonalLeft",
|
18
20
|
:diagonal_right => "DiagonalRight"
|
19
|
-
}
|
20
|
-
should "provide the value for the '#{position}' position" do
|
21
|
-
assert_equal value, Border.position(position)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
should have_class_method :weight
|
21
|
+
}
|
26
22
|
|
27
|
-
{
|
23
|
+
should have_enum :weight, {
|
28
24
|
:hairline => 0,
|
29
25
|
:thin => 1,
|
30
26
|
:medium => 2,
|
31
27
|
:thick => 3
|
32
|
-
}
|
33
|
-
should "provide the value for the '#{weight}' weight" do
|
34
|
-
assert_equal value, Border.weight(weight)
|
35
|
-
end
|
36
|
-
end
|
28
|
+
}
|
37
29
|
|
38
|
-
should
|
39
|
-
|
40
|
-
{
|
30
|
+
should have_enum :line_style, {
|
41
31
|
:none => "None",
|
42
32
|
:continuous => "Continuous",
|
43
33
|
:dash => "Dash",
|
44
34
|
:dot => "Dot",
|
45
35
|
:dash_dot => "DashDot",
|
46
36
|
:dash_dot_dot => "DashDotDot"
|
47
|
-
}
|
48
|
-
|
49
|
-
assert_equal value, Border.line_style(style)
|
50
|
-
end
|
51
|
-
end
|
37
|
+
}
|
38
|
+
|
52
39
|
|
53
|
-
should have_accessors :color
|
40
|
+
should have_accessors :color
|
54
41
|
|
55
42
|
should "set it's defaults" do
|
56
43
|
assert_equal nil, subject.color
|
@@ -98,11 +85,4 @@ module Xmlss::Style
|
|
98
85
|
|
99
86
|
end
|
100
87
|
|
101
|
-
class BorderXmlTest < BorderTest
|
102
|
-
desc "for generating XML"
|
103
|
-
should have_reader :xml
|
104
|
-
should_build_node
|
105
|
-
|
106
|
-
end
|
107
|
-
|
108
88
|
end
|
data/test/style/font_test.rb
CHANGED
@@ -1,40 +1,32 @@
|
|
1
1
|
require "assert"
|
2
|
+
require 'enumeration/assert_macros'
|
3
|
+
|
2
4
|
require 'xmlss/style/font'
|
3
5
|
|
4
6
|
module Xmlss::Style
|
5
7
|
class FontTest < Assert::Context
|
8
|
+
include Enumeration::AssertMacros
|
9
|
+
|
6
10
|
desc "Xmlss::Style::Font"
|
7
11
|
before { @f = Font.new }
|
8
12
|
subject { @f }
|
9
13
|
|
10
|
-
should
|
11
|
-
|
12
|
-
{
|
14
|
+
should have_enum :underline, {
|
13
15
|
:single => 'Single',
|
14
16
|
:double => 'Double',
|
15
17
|
:single_accounting => 'SingleAccounting',
|
16
18
|
:double_accounting => 'DoubleAccounting'
|
17
|
-
}
|
18
|
-
should "provide the value for the '#{underline}' underline" do
|
19
|
-
assert_equal value, Xmlss::Style::Font.underline(underline)
|
20
|
-
end
|
21
|
-
end
|
19
|
+
}
|
22
20
|
|
23
|
-
should
|
24
|
-
|
25
|
-
{
|
21
|
+
should have_enum :alignment, {
|
26
22
|
:subscript => 'Subscript',
|
27
23
|
:superscript => 'Superscript'
|
28
|
-
}
|
29
|
-
should "provide the value for the '#{alignment}' alignment" do
|
30
|
-
assert_equal value, Xmlss::Style::Font.alignment(alignment)
|
31
|
-
end
|
32
|
-
end
|
24
|
+
}
|
33
25
|
|
34
|
-
should have_accessors :bold, :color, :italic, :size, :strike_through, :shadow
|
35
|
-
should have_accessors :underline, :alignment, :name
|
36
|
-
should have_instance_methods :bold?, :italic?, :strike_through?, :shadow?
|
37
26
|
should have_reader :vertical_align
|
27
|
+
should have_accessors :bold, :color, :italic, :size, :strike_through
|
28
|
+
should have_accessors :shadow, :underline, :alignment, :name
|
29
|
+
should have_instance_methods :bold?, :italic?, :strike_through?, :shadow?
|
38
30
|
|
39
31
|
should "set it's defaults" do
|
40
32
|
assert_equal false, subject.bold
|
@@ -68,30 +60,6 @@ module Xmlss::Style
|
|
68
60
|
assert_equal Font.alignment(:superscript), font.alignment
|
69
61
|
end
|
70
62
|
|
71
|
-
should "set attrs by key" do
|
72
|
-
subject.underline = :double
|
73
|
-
subject.alignment = :subscript
|
74
|
-
|
75
|
-
assert_equal Font.underline(:double), subject.underline
|
76
|
-
assert_equal Font.alignment(:subscript), subject.alignment
|
77
|
-
end
|
78
|
-
|
79
|
-
should "set attrs by value" do
|
80
|
-
subject.underline = Xmlss::Style::Font.underline(:double)
|
81
|
-
subject.alignment = Xmlss::Style::Font.alignment(:subscript)
|
82
|
-
|
83
|
-
assert_equal Xmlss::Style::Font.underline(:double), subject.underline
|
84
|
-
assert_equal Xmlss::Style::Font.alignment(:subscript), subject.alignment
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
class FontXmlTest < FontTest
|
90
|
-
desc "for generating XML"
|
91
|
-
|
92
|
-
should have_reader :xml
|
93
|
-
should_build_node
|
94
|
-
should_build_no_attributes_by_default(Xmlss::Style::Font)
|
95
63
|
end
|
96
64
|
|
97
65
|
end
|
data/test/style/interior_test.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
require "assert"
|
2
|
+
require 'enumeration/assert_macros'
|
3
|
+
|
2
4
|
require 'xmlss/style/interior'
|
3
5
|
|
4
6
|
module Xmlss::Style
|
5
7
|
|
6
8
|
class InteriorTest < Assert::Context
|
9
|
+
include Enumeration::AssertMacros
|
10
|
+
|
7
11
|
desc "Xmlss::Style::Interior"
|
8
12
|
before { @i = Interior.new }
|
9
13
|
subject { @i }
|
10
14
|
|
11
|
-
should
|
12
|
-
|
13
|
-
{
|
15
|
+
should have_enum :pattern, {
|
14
16
|
:none => "None",
|
15
17
|
:solid => "Solid",
|
16
18
|
:gray75 => "Gray75",
|
@@ -30,13 +32,9 @@ module Xmlss::Style
|
|
30
32
|
:thin_diag_stripe => "ThineDiagStripe",
|
31
33
|
:thin_horz_cross => "ThinHorzCross",
|
32
34
|
:thin_diag_cross => "ThinDiagCross"
|
33
|
-
}
|
34
|
-
should "provide the value for the '#{pattern}' pattern" do
|
35
|
-
assert_equal value, Xmlss::Style::Interior.pattern(pattern)
|
36
|
-
end
|
37
|
-
end
|
35
|
+
}
|
38
36
|
|
39
|
-
should have_accessor :color, :
|
37
|
+
should have_accessor :color, :pattern_color
|
40
38
|
|
41
39
|
should "set it's defaults" do
|
42
40
|
assert_equal nil, subject.color
|
@@ -55,24 +53,6 @@ module Xmlss::Style
|
|
55
53
|
assert_equal "#FF0000", i.pattern_color
|
56
54
|
end
|
57
55
|
|
58
|
-
should "set attrs by key" do
|
59
|
-
subject.pattern = :solid
|
60
|
-
assert_equal "Solid", subject.pattern
|
61
|
-
end
|
62
|
-
|
63
|
-
should "set attrs by value" do
|
64
|
-
subject.pattern = "Solid"
|
65
|
-
assert_equal "Solid", subject.pattern
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
class InteriorXmlTest < InteriorTest
|
71
|
-
desc "for generating XML"
|
72
|
-
|
73
|
-
should have_reader :xml
|
74
|
-
should_build_node
|
75
|
-
should_build_no_attributes_by_default(Xmlss::Style::Alignment)
|
76
56
|
end
|
77
57
|
|
78
58
|
end
|
@@ -1,8 +1,12 @@
|
|
1
1
|
require "assert"
|
2
|
+
require 'enumeration/assert_macros'
|
3
|
+
|
2
4
|
require 'xmlss/style/number_format'
|
3
5
|
|
4
6
|
module Xmlss::Style
|
5
7
|
class NumberFormatTest < Assert::Context
|
8
|
+
include Enumeration::AssertMacros
|
9
|
+
|
6
10
|
desc "Xmlss::Style::NumberFormat"
|
7
11
|
before { @nf = NumberFormat.new }
|
8
12
|
subject { @nf }
|
@@ -10,30 +14,10 @@ module Xmlss::Style
|
|
10
14
|
should have_accessor :format
|
11
15
|
|
12
16
|
should "set attributes at init" do
|
13
|
-
nf =
|
14
|
-
:format => "General"
|
15
|
-
})
|
17
|
+
nf = NumberFormat.new("General")
|
16
18
|
assert_equal "General", nf.format
|
17
19
|
end
|
18
20
|
|
19
|
-
should "set format by key" do
|
20
|
-
subject.format = "@"
|
21
|
-
assert_equal "@", subject.format
|
22
|
-
end
|
23
|
-
|
24
|
-
should "set format by value" do
|
25
|
-
subject.format = "True/False"
|
26
|
-
assert_equal "True/False", subject.format
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
class NumberFormatXmlTest < NumberFormatTest
|
32
|
-
desc "for generating XML"
|
33
|
-
|
34
|
-
should have_reader :xml
|
35
|
-
should_build_node
|
36
|
-
should_build_no_attributes_by_default(Xmlss::Style::Alignment)
|
37
21
|
end
|
38
22
|
|
39
23
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "assert"
|
2
|
+
|
2
3
|
require 'xmlss/style/protection'
|
3
4
|
|
4
5
|
module Xmlss::Style
|
@@ -16,9 +17,7 @@ module Xmlss::Style
|
|
16
17
|
end
|
17
18
|
|
18
19
|
should "set attrs at init time" do
|
19
|
-
sp = Xmlss::Style::Protection.new(
|
20
|
-
:protect => true
|
21
|
-
})
|
20
|
+
sp = Xmlss::Style::Protection.new(true)
|
22
21
|
assert sp.protected?
|
23
22
|
end
|
24
23
|
|
@@ -29,13 +28,4 @@ module Xmlss::Style
|
|
29
28
|
|
30
29
|
end
|
31
30
|
|
32
|
-
class ProtectionXmlTest < ProtectionTest
|
33
|
-
desc "for generating XML"
|
34
|
-
|
35
|
-
should have_reader :xml
|
36
|
-
should_build_node
|
37
|
-
should_build_no_attributes_by_default(Xmlss::Style::Alignment)
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
31
|
end
|