osheet 0.10.0 → 1.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/Gemfile.lock +9 -6
- data/Rakefile +35 -19
- data/bench/bench_runner.rb +91 -0
- data/bench/profiler_runner.rb +1 -0
- data/examples/basic.rb +1 -1
- data/examples/basic.xls +2 -1
- data/examples/basic_with_templates.rb +2 -2
- data/examples/basic_with_templates.xls +3 -3
- data/examples/formats.rb +2 -2
- data/examples/formats.xls +46 -46
- data/examples/formula.rb +2 -2
- data/examples/styles.rb +2 -2
- data/examples/styles.xls +5 -5
- data/examples/trivial.rb +2 -2
- data/lib/osheet/cell.rb +48 -46
- data/lib/osheet/column.rb +23 -29
- data/lib/osheet/format.rb +3 -3
- data/lib/osheet/meta_element.rb +2 -1
- data/lib/osheet/mixin.rb +21 -9
- data/lib/osheet/partial.rb +5 -9
- data/lib/osheet/row.rb +28 -32
- data/lib/osheet/style.rb +11 -25
- data/lib/osheet/styled_element.rb +9 -1
- data/lib/osheet/template.rb +3 -8
- data/lib/osheet/version.rb +1 -1
- data/lib/osheet/workbook.rb +135 -43
- data/lib/osheet/workbook_api.rb +208 -0
- data/lib/osheet/workbook_element.rb +225 -8
- data/lib/osheet/worksheet.rb +22 -28
- data/lib/osheet/xmlss_writer/style_cache.rb +64 -0
- data/lib/osheet/xmlss_writer/style_settings.rb +148 -0
- data/lib/osheet/xmlss_writer.rb +143 -1
- data/lib/osheet.rb +3 -29
- data/osheet.gemspec +4 -1
- data/test/cell_test.rb +33 -98
- data/test/column_test.rb +20 -88
- data/test/{mixins.rb → fixtures/mixins.rb} +6 -4
- data/test/fixtures/test_writer.rb +68 -0
- data/test/format_test.rb +2 -2
- data/test/helper.rb +34 -68
- data/test/mixin_test.rb +37 -43
- data/test/partial_test.rb +3 -26
- data/test/row_test.rb +32 -85
- data/test/style_test.rb +9 -26
- data/test/template_test.rb +5 -6
- data/test/workbook_element_test.rb +231 -0
- data/test/workbook_test.rb +225 -116
- data/test/worksheet_test.rb +51 -98
- data/test/xmlss_writer/api_test.rb +139 -0
- data/test/xmlss_writer/style_cache_test.rb +65 -0
- data/test/xmlss_writer/style_settings_test.rb +263 -0
- data/test/xmlss_writer/styles_test.rb +121 -153
- data/test/xmlss_writer_test.rb +91 -0
- metadata +75 -50
- data/lib/osheet/associations.rb +0 -58
- data/lib/osheet/instance.rb +0 -30
- data/lib/osheet/markup_element.rb +0 -22
- data/lib/osheet/partial_set.rb +0 -57
- data/lib/osheet/railtie.rb +0 -9
- data/lib/osheet/style_set.rb +0 -39
- data/lib/osheet/template_set.rb +0 -51
- data/lib/osheet/view_handler/rails.rb +0 -44
- data/lib/osheet/view_handler/tilt.rb +0 -42
- data/lib/osheet/view_handler.rb +0 -2
- data/lib/osheet/worksheet_element.rb +0 -17
- data/lib/osheet/xmlss_writer/base.rb +0 -49
- data/lib/osheet/xmlss_writer/elements.rb +0 -56
- data/lib/osheet/xmlss_writer/styles.rb +0 -216
- data/test/osheet_test.rb +0 -13
- data/test/partial_set_test.rb +0 -64
- data/test/style_set_test.rb +0 -47
- data/test/template_set_test.rb +0 -74
- data/test/xmlss_writer/base_test.rb +0 -103
- data/test/xmlss_writer/elements_test.rb +0 -172
data/test/worksheet_test.rb
CHANGED
@@ -1,134 +1,87 @@
|
|
1
1
|
require "assert"
|
2
|
+
|
3
|
+
require 'osheet/column'
|
4
|
+
require 'osheet/row'
|
2
5
|
require 'osheet/worksheet'
|
3
6
|
|
4
7
|
module Osheet
|
5
8
|
|
6
|
-
class
|
7
|
-
desc "
|
9
|
+
class WorksheetTests < Assert::Context
|
10
|
+
desc "a Worksheet"
|
8
11
|
before { @wksht = Worksheet.new }
|
9
12
|
subject { @wksht }
|
10
13
|
|
11
|
-
|
14
|
+
should be_a_meta_element
|
12
15
|
|
13
|
-
should have_instance_methods :name
|
16
|
+
should have_instance_methods :name
|
17
|
+
should have_instance_methods :columns, :column
|
18
|
+
should have_instance_methods :rows, :row
|
14
19
|
|
15
20
|
should "set it's defaults" do
|
16
|
-
assert_equal nil, subject.
|
17
|
-
assert_equal [],
|
18
|
-
assert_equal [],
|
19
|
-
|
20
|
-
assert_equal nil, subject.meta
|
21
|
-
end
|
22
|
-
|
23
|
-
should_hm(Worksheet, :columns, Column)
|
24
|
-
should_hm(Worksheet, :rows, Row)
|
25
|
-
|
26
|
-
should "know it's attribute(s)" do
|
27
|
-
subject.send(:name, "Poo!")
|
28
|
-
[:name].each do |a|
|
29
|
-
assert subject.attributes.has_key?(a)
|
30
|
-
end
|
31
|
-
assert_equal "Poo!", subject.attributes[:name]
|
21
|
+
assert_equal nil, subject.name
|
22
|
+
assert_equal [], subject.columns
|
23
|
+
assert_equal [], subject.rows
|
32
24
|
end
|
33
25
|
|
34
26
|
end
|
35
27
|
|
36
|
-
class
|
37
|
-
desc "
|
38
|
-
before
|
39
|
-
@
|
40
|
-
|
41
|
-
|
42
|
-
}
|
43
|
-
end
|
44
|
-
|
45
|
-
should "know it's name and meta" do
|
46
|
-
assert_equal "Poo!", subject.send(:get_ivar, "name")
|
47
|
-
assert_equal({}, subject.meta)
|
48
|
-
end
|
49
|
-
|
50
|
-
should "set it's name" do
|
51
|
-
subject.name(false)
|
52
|
-
assert_equal 'false', subject.name
|
53
|
-
subject.name('la')
|
54
|
-
assert_equal 'la', subject.name
|
55
|
-
subject.name(nil)
|
56
|
-
assert_equal 'la', subject.name
|
57
|
-
end
|
28
|
+
class WorksheetColumnTests < WorksheetTests
|
29
|
+
desc "with columns"
|
30
|
+
before {
|
31
|
+
@col = Column.new
|
32
|
+
@wksht.column(@col)
|
33
|
+
}
|
58
34
|
|
59
|
-
should "
|
60
|
-
|
61
|
-
|
62
|
-
end
|
63
|
-
assert_nothing_raised do
|
64
|
-
subject.name('a'*31)
|
65
|
-
end
|
35
|
+
should "know its cols" do
|
36
|
+
assert_equal 1, subject.columns.size
|
37
|
+
assert_same @col, subject.columns.first
|
66
38
|
end
|
67
39
|
|
68
40
|
end
|
69
41
|
|
70
|
-
class
|
71
|
-
desc "
|
72
|
-
before
|
73
|
-
@
|
74
|
-
|
75
|
-
|
76
|
-
format :number
|
77
|
-
data 1
|
78
|
-
} }
|
79
|
-
}
|
80
|
-
end
|
42
|
+
class WorksheetRowTests < WorksheetTests
|
43
|
+
desc "with rows"
|
44
|
+
before {
|
45
|
+
@row = Row.new
|
46
|
+
@wksht.row(@row)
|
47
|
+
}
|
81
48
|
|
82
|
-
should "
|
83
|
-
|
84
|
-
|
85
|
-
assert_kind_of Column, columns.first
|
86
|
-
assert_equal subject.columns, columns.first.columns
|
49
|
+
should "know its rows" do
|
50
|
+
assert_equal 1, subject.rows.size
|
51
|
+
assert_same @row, subject.rows.first
|
87
52
|
end
|
88
53
|
|
89
|
-
should "
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
assert_equal subject.
|
94
|
-
|
54
|
+
should "only keep the latest row" do
|
55
|
+
new_row = Row.new(120)
|
56
|
+
subject.row(new_row)
|
57
|
+
|
58
|
+
assert_equal 1, subject.rows.size
|
59
|
+
assert_same new_row, subject.rows.last
|
95
60
|
end
|
96
61
|
|
97
62
|
end
|
98
63
|
|
99
|
-
class
|
100
|
-
desc "
|
64
|
+
class WorksheetNameTests < WorksheetTests
|
65
|
+
desc "with a name"
|
101
66
|
before do
|
102
|
-
@wksht =
|
103
|
-
partial(:worksheet_stuff) {
|
104
|
-
row {}
|
105
|
-
row {}
|
106
|
-
}
|
107
|
-
|
108
|
-
worksheet {
|
109
|
-
add :worksheet_stuff
|
110
|
-
}
|
111
|
-
}
|
67
|
+
@wksht = Worksheet.new("fun")
|
112
68
|
end
|
113
69
|
|
114
|
-
should "
|
115
|
-
assert_equal
|
70
|
+
should "know it's name" do
|
71
|
+
assert_equal "fun", subject.name
|
116
72
|
end
|
117
73
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
74
|
+
should "set it's name" do
|
75
|
+
subject.name(false)
|
76
|
+
assert_equal 'false', subject.name
|
77
|
+
subject.name('la')
|
78
|
+
assert_equal 'la', subject.name
|
79
|
+
subject.name(nil)
|
80
|
+
assert_equal 'la', subject.name
|
81
|
+
end
|
126
82
|
|
127
|
-
|
128
|
-
assert_equal
|
129
|
-
assert_equal @test.object_id, @worksheet.send(:instance_variable_get, "@test").object_id
|
130
|
-
assert_equal @test, @worksheet.attributes[:name]
|
131
|
-
assert_equal @test.object_id, @worksheet.attributes[:name].object_id
|
83
|
+
should "set it's name with an init parameter" do
|
84
|
+
assert_equal "more fun", Worksheet.new("more fun").name
|
132
85
|
end
|
133
86
|
|
134
87
|
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require "assert"
|
2
|
+
|
3
|
+
require 'osheet/xmlss_writer'
|
4
|
+
|
5
|
+
module Osheet
|
6
|
+
|
7
|
+
class XmlssWriter::ApiTest < Assert::Context
|
8
|
+
before do
|
9
|
+
@writer = XmlssWriter.new
|
10
|
+
@workbook = Workbook.new(@writer)
|
11
|
+
end
|
12
|
+
subject { @writer }
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
class XmlssWriter::CellTests < XmlssWriter::ApiTest
|
17
|
+
desc "when writing a cell"
|
18
|
+
before do
|
19
|
+
@cell = Osheet::Cell.new(100)
|
20
|
+
@cell.style_class "awesome thing"
|
21
|
+
@cell.format :number
|
22
|
+
@cell.href 'http://example.com'
|
23
|
+
@cell.rowspan 2
|
24
|
+
@cell.colspan 5
|
25
|
+
@cell.index 3
|
26
|
+
@cell.formula "=R1C1"
|
27
|
+
@xmlss_cell = subject.cell(@cell)
|
28
|
+
end
|
29
|
+
|
30
|
+
should "create an Xmlss::Cell with correct attributes" do
|
31
|
+
assert_kind_of ::Xmlss::Element::Cell, @xmlss_cell
|
32
|
+
assert_equal 100, @xmlss_cell.data
|
33
|
+
assert_equal 'http://example.com', @xmlss_cell.href
|
34
|
+
assert_equal 3, @xmlss_cell.index
|
35
|
+
assert_equal "=R1C1", @xmlss_cell.formula
|
36
|
+
assert_equal 1, @xmlss_cell.merge_down
|
37
|
+
assert_equal 4, @xmlss_cell.merge_across
|
38
|
+
end
|
39
|
+
|
40
|
+
should "style the cell" do
|
41
|
+
assert_equal ".awesome.thing..number_none_0_nocomma_black", @xmlss_cell.style_id
|
42
|
+
assert_equal 1, subject.style_cache.size
|
43
|
+
end
|
44
|
+
|
45
|
+
should "write cell element markup" do
|
46
|
+
assert_equal(
|
47
|
+
"<Cell ss:Formula=\"=R1C1\" ss:HRef=\"http://example.com\" ss:Index=\"3\" ss:MergeAcross=\"4\" ss:MergeDown=\"1\" ss:StyleID=\".awesome.thing..number_none_0_nocomma_black\"><Data ss:Type=\"Number\">100</Data></Cell>",
|
48
|
+
xmlss_element_markup(subject)
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
class XmlssWriter::RowTests < XmlssWriter::ApiTest
|
55
|
+
desc "when writing a row"
|
56
|
+
before do
|
57
|
+
@row = Osheet::Row.new
|
58
|
+
@row.style_class "awesome thing"
|
59
|
+
@row.height 100
|
60
|
+
@row.autofit true
|
61
|
+
@row.hidden true
|
62
|
+
@xmlss_row = subject.row(@row)
|
63
|
+
end
|
64
|
+
|
65
|
+
should "create an Xmlss::Row with correct attributes" do
|
66
|
+
assert_kind_of ::Xmlss::Element::Row, @xmlss_row
|
67
|
+
assert_equal 100, @xmlss_row.height
|
68
|
+
assert_equal true, @xmlss_row.auto_fit_height
|
69
|
+
assert_equal true, @xmlss_row.hidden
|
70
|
+
end
|
71
|
+
|
72
|
+
should "style the row" do
|
73
|
+
assert_equal ".awesome.thing", @xmlss_row.style_id
|
74
|
+
assert_equal 1, subject.style_cache.size
|
75
|
+
end
|
76
|
+
|
77
|
+
should "write row element markup" do
|
78
|
+
assert_equal(
|
79
|
+
"<Row ss:AutoFitHeight=\"1\" ss:Height=\"100\" ss:Hidden=\"1\" ss:StyleID=\".awesome.thing\" />",
|
80
|
+
xmlss_element_markup(subject)
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
class XmlssWriter::ColumnTests < XmlssWriter::ApiTest
|
87
|
+
desc "when writing a column"
|
88
|
+
before do
|
89
|
+
@column = Osheet::Column.new
|
90
|
+
@column.style_class "awesome"
|
91
|
+
@column.width 100
|
92
|
+
@column.autofit true
|
93
|
+
@column.hidden true
|
94
|
+
@xmlss_column = subject.column(@column)
|
95
|
+
end
|
96
|
+
|
97
|
+
should "create an Xmlss::Column with correct attributes" do
|
98
|
+
assert_kind_of ::Xmlss::Element::Column, @xmlss_column
|
99
|
+
assert_equal 100, @xmlss_column.width
|
100
|
+
assert_equal true, @xmlss_column.auto_fit_width
|
101
|
+
assert_equal true, @xmlss_column.hidden
|
102
|
+
end
|
103
|
+
|
104
|
+
should "style an Xmlss column" do
|
105
|
+
assert_equal ".awesome", @xmlss_column.style_id
|
106
|
+
assert_equal 1, subject.style_cache.size
|
107
|
+
end
|
108
|
+
|
109
|
+
should "write column element markup" do
|
110
|
+
assert_equal(
|
111
|
+
"<Column ss:AutoFitWidth=\"1\" ss:Hidden=\"1\" ss:StyleID=\".awesome\" ss:Width=\"100\" />",
|
112
|
+
xmlss_element_markup(subject)
|
113
|
+
)
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
class XmlssWriter::WorksheetTests < XmlssWriter::ApiTest
|
119
|
+
desc "when writing a worksheet"
|
120
|
+
before do
|
121
|
+
@worksheet = Worksheet.new("testsheet2")
|
122
|
+
@xmlss_worksheet = subject.worksheet(@worksheet)
|
123
|
+
end
|
124
|
+
|
125
|
+
should "create an Xmlss::Worksheet with correct attributes" do
|
126
|
+
assert_kind_of ::Xmlss::Element::Worksheet, @xmlss_worksheet
|
127
|
+
assert_equal "testsheet2", @xmlss_worksheet.name
|
128
|
+
end
|
129
|
+
|
130
|
+
should "write worksheet element markup" do
|
131
|
+
assert_equal(
|
132
|
+
"<Worksheet ss:Name=\"testsheet2\"><Table /></Worksheet>",
|
133
|
+
xmlss_element_markup(subject)
|
134
|
+
)
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "assert"
|
2
|
+
|
3
|
+
require 'osheet/xmlss_writer/style_cache'
|
4
|
+
|
5
|
+
module Osheet
|
6
|
+
|
7
|
+
class XmlssWriterStyleCacheTests < Assert::Context
|
8
|
+
desc "the style cache"
|
9
|
+
before do
|
10
|
+
@workbook = Workbook.new
|
11
|
+
@workbook.style('.align.center') { @workbook.align :center }
|
12
|
+
@workbook.style('.font.size') { @workbook.font 14 }
|
13
|
+
@workbook.style('.font.weight') { @workbook.font :bold }
|
14
|
+
@workbook.style('.font.style') { @workbook.font :italic }
|
15
|
+
@workbook.style('.bg.color') { @workbook.bg '#FF0000' }
|
16
|
+
@workbook.style('.border.color') { @workbook.border '#FF0000', :thin }
|
17
|
+
@xmlss_workbook = Xmlss::Workbook.new(Xmlss::Writer.new)
|
18
|
+
|
19
|
+
@cache = XmlssWriter::StyleCache.new(@workbook, @xmlss_workbook)
|
20
|
+
end
|
21
|
+
subject { @cache }
|
22
|
+
|
23
|
+
should have_reader :styles
|
24
|
+
should have_instance_method :get, :keys, :empty?, :size, :[]
|
25
|
+
|
26
|
+
should "have no cached styles by default" do
|
27
|
+
assert_empty subject
|
28
|
+
end
|
29
|
+
|
30
|
+
should "key based off class value and format key" do
|
31
|
+
assert_equal '', subject.send(:key, '', nil)
|
32
|
+
assert_equal '.awesome', subject.send(:key, 'awesome', nil)
|
33
|
+
assert_equal '.awesome.thing', subject.send(:key, 'awesome thing', nil)
|
34
|
+
assert_equal '.awesome..something', subject.send(:key, 'awesome', 'something')
|
35
|
+
assert_equal '..something', subject.send(:key, '', 'something')
|
36
|
+
end
|
37
|
+
|
38
|
+
should "return nil if trying to get the style for an empty class and general format" do
|
39
|
+
assert_not_nil subject.get('font', Osheet::Format.new(:general))
|
40
|
+
assert_nil subject.get('', Osheet::Format.new(:general))
|
41
|
+
end
|
42
|
+
|
43
|
+
should "build and cache styles if not already cached" do
|
44
|
+
assert_equal 0, subject.size
|
45
|
+
subject.get('font', Osheet::Format.new(:currency))
|
46
|
+
assert_equal 1, subject.size
|
47
|
+
end
|
48
|
+
|
49
|
+
should "return cached style if requesting an already cached style" do
|
50
|
+
assert_equal 0, subject.size
|
51
|
+
subject.get('font', Osheet::Format.new(:currency))
|
52
|
+
subject.get('font', Osheet::Format.new(:currency))
|
53
|
+
assert_equal 1, subject.size
|
54
|
+
end
|
55
|
+
|
56
|
+
should "build styles with ids matching the cache key" do
|
57
|
+
key = subject.send(:key, 'font', Osheet::Format.new(:currency).key)
|
58
|
+
assert_equal key, subject.get('font', Osheet::Format.new(:currency)).id
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,263 @@
|
|
1
|
+
require "assert"
|
2
|
+
|
3
|
+
require 'osheet/xmlss_writer/style_settings'
|
4
|
+
|
5
|
+
module Osheet
|
6
|
+
|
7
|
+
class XmlssWriterStyleSettingsTests < Assert::Context
|
8
|
+
desc "the style writer when building"
|
9
|
+
before do
|
10
|
+
@settings = XmlssWriter::StyleSettings.new([])
|
11
|
+
@workbook = Workbook.new
|
12
|
+
@workbook.style('.align.center') { @workbook.align :center }
|
13
|
+
@workbook.style('.font.size') { @workbook.font 14 }
|
14
|
+
@workbook.style('.font.weight') { @workbook.font :bold }
|
15
|
+
@workbook.style('.font.style') { @workbook.font :italic }
|
16
|
+
@workbook.style('.bg.color') { @workbook.bg '#FF0000' }
|
17
|
+
@workbook.style('.border.color') { @workbook.border '#FF0000', :thin }
|
18
|
+
end
|
19
|
+
subject { @settings }
|
20
|
+
|
21
|
+
should have_reader :styles, :value
|
22
|
+
should have_instance_method :setting, :[]
|
23
|
+
|
24
|
+
should "be empty if no styles given" do
|
25
|
+
assert_equal({}, subject.value)
|
26
|
+
end
|
27
|
+
|
28
|
+
should "conditionally run a block if the setting exists and is not empty" do
|
29
|
+
settings = XmlssWriter::StyleSettings.new([@workbook.styles.first])
|
30
|
+
@something = ''
|
31
|
+
|
32
|
+
settings.setting(:font) { @something = 'i should be empty' }
|
33
|
+
assert_empty @something
|
34
|
+
|
35
|
+
settings.setting(:align) { @something = 'i should not be empty' }
|
36
|
+
assert_not_empty @something
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
class XmlssWriterAlignmentSettingsTests < XmlssWriterStyleSettingsTests
|
44
|
+
desc "align settings"
|
45
|
+
|
46
|
+
should "translate horizontal directives" do
|
47
|
+
assert_equal({:horizontal => :left}, subject.send(:align_settings, [:left]))
|
48
|
+
assert_equal({:horizontal => :center}, subject.send(:align_settings, [:center]))
|
49
|
+
assert_equal({:horizontal => :right}, subject.send(:align_settings, [:right]))
|
50
|
+
end
|
51
|
+
|
52
|
+
should "translate vertical directives" do
|
53
|
+
assert_equal({:vertical => :top}, subject.send(:align_settings, [:top]))
|
54
|
+
assert_equal({:vertical => :center}, subject.send(:align_settings, [:middle]))
|
55
|
+
assert_equal({:vertical => :bottom}, subject.send(:align_settings, [:bottom]))
|
56
|
+
end
|
57
|
+
|
58
|
+
should "translate wrap text and rotate directives" do
|
59
|
+
assert_equal({:wrap_text => true}, subject.send(:align_settings, [:wrap]))
|
60
|
+
assert_equal({:rotate => 90}, subject.send(:align_settings, [90]))
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
class XmlssWriterFontSettingsTests < XmlssWriterStyleSettingsTests
|
68
|
+
desc "font settings"
|
69
|
+
|
70
|
+
should "translate size, color and name directives" do
|
71
|
+
assert_equal({:size => 12}, subject.send(:font_settings, [12]))
|
72
|
+
assert_equal({:color => '#FFFFFF'}, subject.send(:font_settings, ['#FFFFFF']))
|
73
|
+
assert_equal({:name => 'Arial'}, subject.send(:font_settings, ['Arial']))
|
74
|
+
end
|
75
|
+
|
76
|
+
should "translate style directives" do
|
77
|
+
assert_equal({:bold => true}, subject.send(:font_settings, [:bold]))
|
78
|
+
assert_equal({:italic => true}, subject.send(:font_settings, [:italic]))
|
79
|
+
assert_equal({:shadow => true}, subject.send(:font_settings, [:shadow]))
|
80
|
+
assert_equal({:alignment => :subscript}, subject.send(:font_settings, [:subscript]))
|
81
|
+
assert_equal({:alignment => :superscript}, subject.send(:font_settings, [:superscript]))
|
82
|
+
assert_equal({:strike_through => true}, subject.send(:font_settings, [:strikethrough]))
|
83
|
+
end
|
84
|
+
|
85
|
+
should "translate underline directives" do
|
86
|
+
assert_equal({:underline => :single}, subject.send(:font_settings, [:underline]))
|
87
|
+
assert_equal({:underline => :double}, subject.send(:font_settings, [:double_underline]))
|
88
|
+
assert_equal({:underline => :single_accounting}, subject.send(:font_settings, [:accounting_underline]))
|
89
|
+
assert_equal({:underline => :double_accounting}, subject.send(:font_settings, [:double_accounting_underline]))
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
class XmlssWriterBgSettingsTests < XmlssWriterStyleSettingsTests
|
98
|
+
desc "bg settings"
|
99
|
+
|
100
|
+
should "translate color directives" do
|
101
|
+
assert_equal({:color => '#FFFFFF', :pattern => :solid}, subject.send(:bg_settings, ['#FFFFFF']))
|
102
|
+
end
|
103
|
+
|
104
|
+
should "translate pattern directives" do
|
105
|
+
assert_equal({:pattern => :solid}, subject.send(:bg_settings, [:solid]))
|
106
|
+
assert_equal({
|
107
|
+
:pattern => :horz_stripe,
|
108
|
+
:pattern_color => '#0000FF'
|
109
|
+
}, subject.send(:bg_settings, [{:horz_stripe => '#0000FF'}]))
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
class XmlssWriterBorderSettingsTests < XmlssWriterStyleSettingsTests
|
119
|
+
desc "border settings"
|
120
|
+
|
121
|
+
should "translate color directives" do
|
122
|
+
assert_equal({:color => '#FFFFFF'}, subject.send(:border_settings, ['#FFFFFF']))
|
123
|
+
end
|
124
|
+
|
125
|
+
should "translate position directives" do
|
126
|
+
assert_equal({:position => :top}, subject.send(:border_settings, [:top]))
|
127
|
+
end
|
128
|
+
|
129
|
+
should "translate weight directives" do
|
130
|
+
assert_equal({:weight => :thick}, subject.send(:border_settings, [:thick]))
|
131
|
+
end
|
132
|
+
|
133
|
+
should "translate line_style directives" do
|
134
|
+
assert_equal({:line_style => :dot}, subject.send(:border_settings, [:dot]))
|
135
|
+
end
|
136
|
+
|
137
|
+
should "translate position specific directives" do
|
138
|
+
assert_equal({
|
139
|
+
:position => :left,
|
140
|
+
:color => '#FFFFFF',
|
141
|
+
:weight => :thin
|
142
|
+
}, subject.send(:border_left_settings, ['#FFFFFF', :thin]))
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
class XmlssWriterParseSettingsTests < XmlssWriterStyleSettingsTests
|
150
|
+
desc "settings"
|
151
|
+
|
152
|
+
should "parse Osheet style objs for their settings" do
|
153
|
+
assert_equal({
|
154
|
+
:align => {
|
155
|
+
:horizontal => :center
|
156
|
+
}
|
157
|
+
}, subject.send(:style_settings, @workbook.styles.first))
|
158
|
+
|
159
|
+
assert_equal({
|
160
|
+
:border_top => {
|
161
|
+
:position=>:top,
|
162
|
+
:color=>"#FF0000",
|
163
|
+
:weight=>:thin
|
164
|
+
},
|
165
|
+
:border_right => {
|
166
|
+
:position=>:right,
|
167
|
+
:color=>"#FF0000",
|
168
|
+
:weight=>:thin
|
169
|
+
},
|
170
|
+
:border_bottom => {
|
171
|
+
:position=>:bottom,
|
172
|
+
:color=>"#FF0000",
|
173
|
+
:weight=>:thin
|
174
|
+
},
|
175
|
+
:border_left => {
|
176
|
+
:position=>:left,
|
177
|
+
:color=>"#FF0000",
|
178
|
+
:weight=>:thin
|
179
|
+
}
|
180
|
+
}, subject.send(:style_settings, @workbook.styles.last))
|
181
|
+
end
|
182
|
+
|
183
|
+
should "merge style settings from multiple Osheet style objs" do
|
184
|
+
set1 = {
|
185
|
+
:font => {
|
186
|
+
:color => '#FF0000',
|
187
|
+
:name => "Arial"
|
188
|
+
}
|
189
|
+
}
|
190
|
+
set2 = {
|
191
|
+
:font => {
|
192
|
+
:color => '#0000FF',
|
193
|
+
:size => 12
|
194
|
+
}
|
195
|
+
}
|
196
|
+
set3 = {
|
197
|
+
:align => {
|
198
|
+
:horizontal => :center
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
202
|
+
# should concat keys in both sets
|
203
|
+
assert_equal({
|
204
|
+
:font => {
|
205
|
+
:color => '#0000FF',
|
206
|
+
:name => "Arial",
|
207
|
+
:size => 12
|
208
|
+
}
|
209
|
+
}, subject.send(:merged_settings, set1.dup, set2.dup))
|
210
|
+
|
211
|
+
# should add keys not in first set
|
212
|
+
assert_equal({
|
213
|
+
:font => {
|
214
|
+
:color => '#0000FF',
|
215
|
+
:size => 12
|
216
|
+
},
|
217
|
+
:align => {
|
218
|
+
:horizontal => :center
|
219
|
+
}
|
220
|
+
}, subject.send(:merged_settings, set2.dup, set3.dup))
|
221
|
+
|
222
|
+
end
|
223
|
+
|
224
|
+
should "set its value given its set of styles" do
|
225
|
+
assert_equal({
|
226
|
+
:align => {
|
227
|
+
:horizontal => :center
|
228
|
+
},
|
229
|
+
:font => {
|
230
|
+
:bold => true,
|
231
|
+
:italic => true,
|
232
|
+
:size => 14
|
233
|
+
},
|
234
|
+
:bg => {
|
235
|
+
:pattern => :solid,
|
236
|
+
:color => "#FF0000"
|
237
|
+
},
|
238
|
+
:border_top => {
|
239
|
+
:position => :top,
|
240
|
+
:color => "#FF0000",
|
241
|
+
:weight => :thin
|
242
|
+
},
|
243
|
+
:border_right => {
|
244
|
+
:position => :right,
|
245
|
+
:color => "#FF0000",
|
246
|
+
:weight => :thin
|
247
|
+
},
|
248
|
+
:border_bottom => {
|
249
|
+
:position => :bottom,
|
250
|
+
:color => "#FF0000",
|
251
|
+
:weight => :thin
|
252
|
+
},
|
253
|
+
:border_left => {
|
254
|
+
:position => :left,
|
255
|
+
:color => "#FF0000",
|
256
|
+
:weight => :thin
|
257
|
+
}
|
258
|
+
}, XmlssWriter::StyleSettings.new(@workbook.styles).value)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
|