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
@@ -4,360 +4,328 @@ require 'osheet/xmlss_writer'
|
|
4
4
|
|
5
5
|
module Osheet
|
6
6
|
|
7
|
-
class
|
7
|
+
class XmlssWriterStylesTest < Assert::Context
|
8
8
|
before do
|
9
|
-
@writer = XmlssWriter
|
10
|
-
@
|
9
|
+
@writer = XmlssWriter.new
|
10
|
+
@workbook = Workbook.new(@writer)
|
11
11
|
end
|
12
12
|
subject { @writer }
|
13
13
|
|
14
|
+
should "not have a style cache until its bound to an osheet workbook" do
|
15
|
+
writer = XmlssWriter.new
|
16
|
+
assert_nil writer.style_cache
|
17
|
+
writer.bind(@workbook)
|
18
|
+
assert_not_nil writer.style_cache
|
19
|
+
end
|
20
|
+
|
14
21
|
end
|
15
22
|
|
16
|
-
class
|
23
|
+
class XmlssWriterStyleTests < XmlssWriterStylesTest
|
17
24
|
desc "Xmlss style writer"
|
18
25
|
before do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
style('.align.center') { align :center }
|
24
|
-
}
|
25
|
-
end
|
26
|
-
|
27
|
-
should "key styles based off class str and format" do
|
28
|
-
assert_equal '', subject.send(:style_key, '', nil)
|
29
|
-
assert_equal '.awesome', subject.send(:style_key, 'awesome', nil)
|
30
|
-
assert_equal '.awesome.thing', subject.send(:style_key, 'awesome thing', nil)
|
31
|
-
assert_equal '.awesome..something', subject.send(:style_key, 'awesome', 'something')
|
32
|
-
assert_equal '..something', subject.send(:style_key, '', 'something')
|
33
|
-
end
|
34
|
-
|
35
|
-
should "not build a style obj when writing styles with no class str or format" do
|
36
|
-
assert_equal nil, subject.send(:style, @xworkbook, '')
|
26
|
+
@workbook.style('.font.size') { @workbook.font 14 }
|
27
|
+
@workbook.style('.font.weight') { @workbook.font :bold }
|
28
|
+
@workbook.style('.font.style') { @workbook.font :italic }
|
29
|
+
@workbook.style('.align.center') { @workbook.align :center }
|
37
30
|
end
|
38
31
|
|
39
32
|
should "build a style obj and add it to the writers styles" do
|
40
|
-
xmlss_style = subject.
|
33
|
+
xmlss_style = subject.style('awesome')
|
41
34
|
assert_kind_of ::Xmlss::Style::Base, xmlss_style
|
42
35
|
assert_equal '.awesome', xmlss_style.id
|
43
|
-
assert_equal 1, subject.
|
44
|
-
assert_equal xmlss_style, subject.
|
36
|
+
assert_equal 1, subject.style_cache.size
|
37
|
+
assert_equal xmlss_style, subject.style_cache[xmlss_style.id]
|
45
38
|
end
|
46
39
|
|
47
40
|
should "write style markup from many matching osheet styles" do
|
48
|
-
xmlss_style = subject.
|
41
|
+
xmlss_style = subject.style('font size weight style align center')
|
49
42
|
assert_equal '.font.size.weight.style.align.center', xmlss_style.id
|
50
|
-
|
51
|
-
assert_equal(
|
52
|
-
"<Style ss:ID=\".font.size.weight.style.align.center\"><Alignment ss:Horizontal=\"Center\" /><Font ss:Bold=\"1\" ss:Italic=\"1\" ss:Size=\"14\" /><NumberFormat /></Style>",
|
53
|
-
xstyle_markup(@xworkbook)
|
54
|
-
)
|
55
|
-
end
|
56
|
-
|
57
|
-
should "provide style ids" do
|
58
|
-
assert_equal '', subject.send(:style_id, @xworkbook, '')
|
59
|
-
assert_equal '.awesome', subject.send(:style_id, @xworkbook, 'awesome')
|
60
|
-
assert_equal '..number_none_0_nocomma_black', subject.send(:style_id, @xworkbook, '', Osheet::Format.new(:number))
|
61
|
-
assert_equal 2, subject.used_xstyles.size
|
62
43
|
end
|
63
44
|
|
64
45
|
end
|
65
46
|
|
66
|
-
class
|
47
|
+
class XmlssWriterAlignmentTests < XmlssWriterStylesTest
|
67
48
|
desc "Alignment style writer"
|
68
49
|
before do
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
style('.align.rotate') { align 90 }
|
77
|
-
}
|
50
|
+
[ :left, :center, :right,
|
51
|
+
:top, :middle, :bottom,
|
52
|
+
:wrap
|
53
|
+
].each do |s|
|
54
|
+
@workbook.style(".align.#{s}") { @workbook.align s }
|
55
|
+
end
|
56
|
+
@workbook.style('.align.rotate') { @workbook.align 90 }
|
78
57
|
end
|
79
58
|
|
80
59
|
should "write style markup with no alignment settings if no alignment style match" do
|
81
|
-
subject.
|
60
|
+
subject.style('align')
|
82
61
|
assert_equal(
|
83
62
|
"<Style ss:ID=\".align\"><NumberFormat /></Style>",
|
84
|
-
|
63
|
+
xmlss_style_markup(subject)
|
85
64
|
)
|
86
65
|
end
|
87
66
|
|
88
67
|
should "write style markup for horizontal alignment settings" do
|
89
|
-
subject.
|
90
|
-
subject.
|
91
|
-
subject.
|
68
|
+
subject.style('align left')
|
69
|
+
subject.style('align center')
|
70
|
+
subject.style('align right')
|
92
71
|
assert_equal(
|
93
72
|
"<Style ss:ID=\".align.left\"><Alignment ss:Horizontal=\"Left\" /><NumberFormat /></Style><Style ss:ID=\".align.center\"><Alignment ss:Horizontal=\"Center\" /><NumberFormat /></Style><Style ss:ID=\".align.right\"><Alignment ss:Horizontal=\"Right\" /><NumberFormat /></Style>",
|
94
|
-
|
73
|
+
xmlss_style_markup(subject)
|
95
74
|
)
|
96
75
|
end
|
97
76
|
|
98
77
|
should "write style markup for vertical alignment settings" do
|
99
|
-
subject.
|
100
|
-
subject.
|
101
|
-
subject.
|
78
|
+
subject.style('align top')
|
79
|
+
subject.style('align middle')
|
80
|
+
subject.style('align bottom')
|
102
81
|
assert_equal(
|
103
82
|
"<Style ss:ID=\".align.top\"><Alignment ss:Vertical=\"Top\" /><NumberFormat /></Style><Style ss:ID=\".align.middle\"><Alignment ss:Vertical=\"Center\" /><NumberFormat /></Style><Style ss:ID=\".align.bottom\"><Alignment ss:Vertical=\"Bottom\" /><NumberFormat /></Style>",
|
104
|
-
|
83
|
+
xmlss_style_markup(subject)
|
105
84
|
)
|
106
85
|
end
|
107
86
|
|
108
87
|
should "write style markup for text wrap settings" do
|
109
|
-
subject.
|
88
|
+
subject.style('align wrap')
|
110
89
|
assert_equal(
|
111
90
|
"<Style ss:ID=\".align.wrap\"><Alignment ss:WrapText=\"1\" /><NumberFormat /></Style>",
|
112
|
-
|
91
|
+
xmlss_style_markup(subject)
|
113
92
|
)
|
114
93
|
end
|
115
94
|
|
116
95
|
should "write style markup for text rotation settings" do
|
117
|
-
subject.
|
96
|
+
subject.style('align rotate')
|
118
97
|
assert_equal(
|
119
98
|
"<Style ss:ID=\".align.rotate\"><Alignment ss:Rotate=\"90\" /><NumberFormat /></Style>",
|
120
|
-
|
99
|
+
xmlss_style_markup(subject)
|
121
100
|
)
|
122
101
|
end
|
123
102
|
|
124
103
|
end
|
125
104
|
|
126
|
-
class
|
105
|
+
class XmlssWriterFontTests < XmlssWriterStylesTest
|
127
106
|
desc "Font style writer"
|
128
107
|
before do
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
style('.font.name') { font 'Verdana' }
|
139
|
-
}
|
108
|
+
[ :underline, :double_underline, :accounting_underline, :double_accounting_underline,
|
109
|
+
:subscript, :superscript, :shadow, :strikethrough, :wrap,
|
110
|
+
:bold, :italic
|
111
|
+
].each do |s|
|
112
|
+
@workbook.style(".font.#{s}") { @workbook.font s }
|
113
|
+
end
|
114
|
+
@workbook.style('.font.size') { @workbook.font 14 }
|
115
|
+
@workbook.style('.font.color') { @workbook.font '#FF0000' }
|
116
|
+
@workbook.style('.font.name') { @workbook.font 'Verdana' }
|
140
117
|
end
|
141
118
|
|
142
119
|
should "write style markup with empty font settings if no match" do
|
143
|
-
subject.
|
120
|
+
subject.style('font')
|
144
121
|
assert_equal(
|
145
122
|
"<Style ss:ID=\".font\"><NumberFormat /></Style>",
|
146
|
-
|
123
|
+
xmlss_style_markup(subject)
|
147
124
|
)
|
148
125
|
end
|
149
126
|
|
150
127
|
should "write style markup for font underline settings" do
|
151
|
-
subject.
|
152
|
-
subject.
|
153
|
-
subject.
|
154
|
-
subject.
|
128
|
+
subject.style('font underline')
|
129
|
+
subject.style('font double_underline')
|
130
|
+
subject.style('font accounting_underline')
|
131
|
+
subject.style('font double_accounting_underline')
|
155
132
|
assert_equal(
|
156
133
|
"<Style ss:ID=\".font.underline\"><Font ss:Underline=\"Single\" /><NumberFormat /></Style><Style ss:ID=\".font.double_underline\"><Font ss:Underline=\"Double\" /><NumberFormat /></Style><Style ss:ID=\".font.accounting_underline\"><Font ss:Underline=\"SingleAccounting\" /><NumberFormat /></Style><Style ss:ID=\".font.double_accounting_underline\"><Font ss:Underline=\"DoubleAccounting\" /><NumberFormat /></Style>",
|
157
|
-
|
134
|
+
xmlss_style_markup(subject)
|
158
135
|
)
|
159
136
|
|
160
137
|
end
|
161
138
|
|
162
139
|
should "write style markup for font alignment settings" do
|
163
|
-
subject.
|
164
|
-
subject.
|
140
|
+
subject.style('font subscript')
|
141
|
+
subject.style('font superscript')
|
165
142
|
assert_equal(
|
166
143
|
"<Style ss:ID=\".font.subscript\"><Font ss:VerticalAlign=\"Subscript\" /><NumberFormat /></Style><Style ss:ID=\".font.superscript\"><Font ss:VerticalAlign=\"Superscript\" /><NumberFormat /></Style>",
|
167
|
-
|
144
|
+
xmlss_style_markup(subject)
|
168
145
|
)
|
169
146
|
end
|
170
147
|
|
171
148
|
should "write style markup for font style settings" do
|
172
|
-
subject.
|
173
|
-
subject.
|
174
|
-
subject.
|
175
|
-
subject.
|
149
|
+
subject.style('font bold')
|
150
|
+
subject.style('font italic')
|
151
|
+
subject.style('font strikethrough')
|
152
|
+
subject.style('font shadow')
|
176
153
|
assert_equal(
|
177
154
|
"<Style ss:ID=\".font.bold\"><Font ss:Bold=\"1\" /><NumberFormat /></Style><Style ss:ID=\".font.italic\"><Font ss:Italic=\"1\" /><NumberFormat /></Style><Style ss:ID=\".font.strikethrough\"><Font ss:StrikeThrough=\"1\" /><NumberFormat /></Style><Style ss:ID=\".font.shadow\"><Font ss:Shadow=\"1\" /><NumberFormat /></Style>",
|
178
|
-
|
155
|
+
xmlss_style_markup(subject)
|
179
156
|
)
|
180
157
|
end
|
181
158
|
|
182
159
|
should "write style markup for font size" do
|
183
|
-
subject.
|
160
|
+
subject.style('font size')
|
184
161
|
assert_equal(
|
185
162
|
"<Style ss:ID=\".font.size\"><Font ss:Size=\"14\" /><NumberFormat /></Style>",
|
186
|
-
|
163
|
+
xmlss_style_markup(subject)
|
187
164
|
)
|
188
165
|
end
|
189
166
|
|
190
167
|
should "write style markup for font color" do
|
191
|
-
subject.
|
168
|
+
subject.style('font color')
|
192
169
|
assert_equal(
|
193
170
|
"<Style ss:ID=\".font.color\"><Font ss:Color=\"#FF0000\" /><NumberFormat /></Style>",
|
194
|
-
|
171
|
+
xmlss_style_markup(subject)
|
195
172
|
)
|
196
173
|
end
|
197
174
|
|
198
175
|
should "write style markup for font name" do
|
199
|
-
subject.
|
176
|
+
subject.style('font name')
|
200
177
|
assert_equal(
|
201
178
|
"<Style ss:ID=\".font.name\"><Font ss:FontName=\"Verdana\" /><NumberFormat /></Style>",
|
202
|
-
|
179
|
+
xmlss_style_markup(subject)
|
203
180
|
)
|
204
181
|
end
|
205
182
|
|
206
183
|
end
|
207
184
|
|
208
|
-
class
|
185
|
+
class XmlssWriterBgTests < XmlssWriterStylesTest
|
209
186
|
desc "Bg writer"
|
210
187
|
before do
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
style('.bg.pattern-first') { bg({:horz_stripe => '#0000FF'}, '#00FF00') }
|
217
|
-
}
|
188
|
+
@workbook.style('.bg.color') { @workbook.bg '#FF0000' }
|
189
|
+
@workbook.style('.bg.pattern-only') { @workbook.bg :solid }
|
190
|
+
@workbook.style('.bg.pattern-color') { @workbook.bg :horz_stripe => '#0000FF' }
|
191
|
+
@workbook.style('.bg.color-first') { @workbook.bg '#00FF00', {:horz_stripe => '#0000FF'} }
|
192
|
+
@workbook.style('.bg.pattern-first') { @workbook.bg({:horz_stripe => '#0000FF'}, '#00FF00') }
|
218
193
|
end
|
219
194
|
|
220
195
|
should "write style markup with empty bg settings when no match" do
|
221
|
-
subject.
|
222
|
-
# assert_equal nil, .interior
|
196
|
+
subject.style('bg')
|
223
197
|
assert_equal(
|
224
198
|
"<Style ss:ID=\".bg\"><NumberFormat /></Style>",
|
225
|
-
|
199
|
+
xmlss_style_markup(subject)
|
226
200
|
)
|
227
201
|
end
|
228
202
|
|
229
203
|
should "write style markup for bg color and auto set the pattern to solid" do
|
230
|
-
subject.
|
231
|
-
# assert_equal '#FF0000', .interior.color
|
204
|
+
subject.style('bg color')
|
232
205
|
assert_equal(
|
233
206
|
"<Style ss:ID=\".bg.color\"><Interior ss:Color=\"#FF0000\" ss:Pattern=\"Solid\" /><NumberFormat /></Style>",
|
234
|
-
|
207
|
+
xmlss_style_markup(subject)
|
235
208
|
)
|
236
209
|
end
|
237
210
|
|
238
211
|
should "write style markup for bg pattern settings" do
|
239
|
-
subject.
|
240
|
-
subject.
|
241
|
-
subject.
|
242
|
-
subject.
|
212
|
+
subject.style('bg pattern-only')
|
213
|
+
subject.style('bg pattern-only')
|
214
|
+
subject.style('bg pattern-color')
|
215
|
+
subject.style('bg pattern-color')
|
243
216
|
assert_equal(
|
244
217
|
"<Style ss:ID=\".bg.pattern-only\"><Interior ss:Pattern=\"Solid\" /><NumberFormat /></Style><Style ss:ID=\".bg.pattern-color\"><Interior ss:Color=\"#FF0000\" ss:Pattern=\"HorzStripe\" ss:PatternColor=\"#0000FF\" /><NumberFormat /></Style>",
|
245
|
-
|
218
|
+
xmlss_style_markup(subject)
|
246
219
|
)
|
247
220
|
end
|
248
221
|
|
249
222
|
should "write style markup setting pattern to solid when setting bg color" do
|
250
|
-
subject.
|
223
|
+
subject.style('bg color')
|
251
224
|
assert_equal(
|
252
225
|
"<Style ss:ID=\".bg.color\"><Interior ss:Color=\"#FF0000\" ss:Pattern=\"Solid\" /><NumberFormat /></Style>",
|
253
|
-
|
226
|
+
xmlss_style_markup(subject)
|
254
227
|
)
|
255
228
|
end
|
256
229
|
|
257
230
|
should "write style markup setting pattern to pattern setting when first setting bg color then pattern" do
|
258
|
-
subject.
|
231
|
+
subject.style('bg color-first')
|
259
232
|
assert_equal(
|
260
233
|
"<Style ss:ID=\".bg.color-first\"><Interior ss:Color=\"#00FF00\" ss:Pattern=\"HorzStripe\" ss:PatternColor=\"#0000FF\" /><NumberFormat /></Style>",
|
261
|
-
|
234
|
+
xmlss_style_markup(subject)
|
262
235
|
)
|
263
236
|
end
|
264
237
|
|
265
238
|
should "write style markup setting pattern to pattern setting when first setting bg pattern then color" do
|
266
|
-
subject.
|
239
|
+
subject.style('bg pattern-first')
|
267
240
|
assert_equal(
|
268
241
|
"<Style ss:ID=\".bg.pattern-first\"><Interior ss:Color=\"#00FF00\" ss:Pattern=\"HorzStripe\" ss:PatternColor=\"#0000FF\" /><NumberFormat /></Style>",
|
269
|
-
|
242
|
+
xmlss_style_markup(subject)
|
270
243
|
)
|
271
244
|
end
|
272
245
|
|
273
246
|
end
|
274
247
|
|
275
|
-
class
|
248
|
+
class XmlssWriterBorderTests < XmlssWriterStylesTest
|
276
249
|
desc "Font border writer"
|
277
250
|
before do
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
style('.border.all') { border :thick, :dash, '#FF0000' }
|
290
|
-
}
|
251
|
+
::Osheet::Style::BORDER_POSITIONS.each do |p|
|
252
|
+
@workbook.style(".border.#{p}") { @workbook.send("border_#{p}", :thin) }
|
253
|
+
end
|
254
|
+
[:hairline, :thin, :medium, :thick].each do |w|
|
255
|
+
@workbook.style(".border.#{w}") { @workbook.border_top w }
|
256
|
+
end
|
257
|
+
[:none, :continuous, :dash, :dot, :dash_dot, :dash_dot_dot].each do |s|
|
258
|
+
@workbook.style(".border.#{s}") { @workbook.border_top s }
|
259
|
+
end
|
260
|
+
@workbook.style('.border.color') { @workbook.border_top '#FF0000' }
|
261
|
+
@workbook.style('.border.all') { @workbook.border :thick, :dash, '#FF0000' }
|
291
262
|
end
|
292
263
|
|
293
264
|
should "write style markup with empty border settings when no match" do
|
294
|
-
subject.
|
265
|
+
subject.style('border')
|
295
266
|
assert_equal(
|
296
267
|
"<Style ss:ID=\".border\"><NumberFormat /></Style>",
|
297
|
-
|
268
|
+
xmlss_style_markup(subject)
|
298
269
|
)
|
299
270
|
end
|
300
271
|
|
301
272
|
should "write style markup with identical settings for all positions when using 'border'" do
|
302
|
-
subject.
|
273
|
+
subject.style('border all')
|
303
274
|
assert_equal(
|
304
275
|
"<Style ss:ID=\".border.all\"><Borders><Border ss:Color=\"#FF0000\" ss:LineStyle=\"Dash\" ss:Position=\"Top\" ss:Weight=\"3\" /><Border ss:Color=\"#FF0000\" ss:LineStyle=\"Dash\" ss:Position=\"Right\" ss:Weight=\"3\" /><Border ss:Color=\"#FF0000\" ss:LineStyle=\"Dash\" ss:Position=\"Bottom\" ss:Weight=\"3\" /><Border ss:Color=\"#FF0000\" ss:LineStyle=\"Dash\" ss:Position=\"Left\" ss:Weight=\"3\" /></Borders><NumberFormat /></Style>",
|
305
|
-
|
276
|
+
xmlss_style_markup(subject)
|
306
277
|
)
|
307
278
|
end
|
308
279
|
|
309
280
|
should "write style markup for border specific positions" do
|
310
281
|
::Osheet::Style::BORDER_POSITIONS.each do |p|
|
311
|
-
subject.
|
282
|
+
subject.style("border #{p}")
|
312
283
|
end
|
313
284
|
assert_equal(
|
314
285
|
"<Style ss:ID=\".border.top\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.right\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Right\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.bottom\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Bottom\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.left\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Left\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style>",
|
315
|
-
|
286
|
+
xmlss_style_markup(subject)
|
316
287
|
)
|
317
288
|
end
|
318
289
|
|
319
290
|
should "write style markup for border weight settings" do
|
320
291
|
[:hairline, :thin, :medium, :thick].each do |w|
|
321
|
-
subject.
|
292
|
+
subject.style("border #{w}")
|
322
293
|
end
|
323
294
|
assert_equal(
|
324
295
|
"<Style ss:ID=\".border.hairline\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Top\" ss:Weight=\"0\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.thin\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.medium\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Top\" ss:Weight=\"2\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.thick\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Top\" ss:Weight=\"3\" /></Borders><NumberFormat /></Style>",
|
325
|
-
|
296
|
+
xmlss_style_markup(subject)
|
326
297
|
)
|
327
298
|
end
|
328
299
|
|
329
300
|
should "write style markup for border style settings" do
|
330
301
|
[:none, :continuous, :dash, :dot, :dash_dot, :dash_dot_dot].each do |s|
|
331
|
-
subject.
|
302
|
+
subject.style("border #{s}")
|
332
303
|
end
|
333
304
|
assert_equal(
|
334
305
|
"<Style ss:ID=\".border.none\"><Borders><Border ss:LineStyle=\"None\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.continuous\"><Borders><Border ss:LineStyle=\"Continuous\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.dash\"><Borders><Border ss:LineStyle=\"Dash\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.dot\"><Borders><Border ss:LineStyle=\"Dot\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.dash_dot\"><Borders><Border ss:LineStyle=\"DashDot\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style><Style ss:ID=\".border.dash_dot_dot\"><Borders><Border ss:LineStyle=\"DashDotDot\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style>",
|
335
|
-
|
306
|
+
xmlss_style_markup(subject)
|
336
307
|
)
|
337
308
|
end
|
338
309
|
|
339
310
|
should "write style markup for border color" do
|
340
|
-
subject.
|
311
|
+
subject.style('border color')
|
341
312
|
assert_equal(
|
342
313
|
"<Style ss:ID=\".border.color\"><Borders><Border ss:Color=\"#FF0000\" ss:LineStyle=\"Continuous\" ss:Position=\"Top\" ss:Weight=\"1\" /></Borders><NumberFormat /></Style>",
|
343
|
-
|
314
|
+
xmlss_style_markup(subject)
|
344
315
|
)
|
345
316
|
end
|
346
317
|
|
347
318
|
end
|
348
319
|
|
349
|
-
class
|
320
|
+
class XmlssWriterNumberFormatTests < XmlssWriterStylesTest
|
350
321
|
desc "Xmlss style number format writer"
|
351
|
-
before do
|
352
|
-
subject.oworkbook = Workbook.new {}
|
353
|
-
end
|
354
322
|
|
355
323
|
should "write style markup with formatting" do
|
356
|
-
subject.
|
357
|
-
subject.
|
324
|
+
subject.style('', Osheet::Format.new(:text))
|
325
|
+
subject.style('', Osheet::Format.new(:datetime, 'mm/dd/yy'))
|
358
326
|
assert_equal(
|
359
327
|
"<Style ss:ID=\"..text\"><NumberFormat ss:Format=\"@\" /></Style><Style ss:ID=\"..datetime_mm/dd/yy\"><NumberFormat ss:Format=\"mm/dd/yy\" /></Style>",
|
360
|
-
|
328
|
+
xmlss_style_markup(subject)
|
361
329
|
)
|
362
330
|
end
|
363
331
|
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require "assert"
|
2
|
+
require 'osheet/xmlss_writer'
|
3
|
+
|
4
|
+
module Osheet
|
5
|
+
|
6
|
+
class XmlssWriterTest < Assert::Context
|
7
|
+
desc "the xmlss writer"
|
8
|
+
before do
|
9
|
+
@writer = XmlssWriter.new
|
10
|
+
@workbook = Workbook.new(@writer)
|
11
|
+
end
|
12
|
+
subject { @writer }
|
13
|
+
|
14
|
+
should have_reader :style_cache, :xmlss_workbook
|
15
|
+
should have_instance_methods :bind, :to_s, :to_data, :to_file
|
16
|
+
|
17
|
+
should have_instance_methods :worksheet, :column, :row, :cell
|
18
|
+
should have_instance_methods :style
|
19
|
+
should have_instance_methods :name
|
20
|
+
should have_instance_methods :width, :height
|
21
|
+
should have_instance_methods :autofit, :autofit?, :hidden, :hidden?
|
22
|
+
should have_instance_methods :data, :format, :href, :formula
|
23
|
+
should have_instance_methods :index, :rowspan, :colspan
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
class XmlssWriterWorkbookTests < XmlssWriterTest
|
28
|
+
before do
|
29
|
+
@workbook.worksheet("testsheet1")
|
30
|
+
end
|
31
|
+
|
32
|
+
should "not allow multiple worksheets with the same name" do
|
33
|
+
assert_raises ArgumentError do
|
34
|
+
subject.worksheet(Worksheet.new("testsheet1"))
|
35
|
+
end
|
36
|
+
assert_nothing_raised do
|
37
|
+
subject.worksheet(Worksheet.new("testsheet2"))
|
38
|
+
subject.worksheet(Worksheet.new) {
|
39
|
+
subject.name 'testsheet3'
|
40
|
+
}
|
41
|
+
subject.worksheet(Worksheet.new) {
|
42
|
+
subject.name 'testsheet4'
|
43
|
+
}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
class XmlssWriterToFileTests < XmlssWriterTest
|
50
|
+
desc "used with a workbook"
|
51
|
+
before do
|
52
|
+
Workbook.new(@writer) {
|
53
|
+
title "written"
|
54
|
+
worksheet {
|
55
|
+
name "Test!"
|
56
|
+
column
|
57
|
+
row {
|
58
|
+
cell {
|
59
|
+
data 1
|
60
|
+
format :number
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
should "write workbook markup" do
|
68
|
+
assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\"><Styles><Style ss:ID=\"..number_none_0_nocomma_black\"><NumberFormat ss:Format=\"0\" /></Style></Styles><Worksheet ss:Name=\"Test!\"><Table><Column /><Row><Cell ss:StyleID=\"..number_none_0_nocomma_black\"><Data ss:Type=\"Number\">1</Data></Cell></Row></Table></Worksheet></Workbook>", @writer.to_s
|
69
|
+
end
|
70
|
+
|
71
|
+
should "return string xml data" do
|
72
|
+
xml_data = subject.to_s
|
73
|
+
assert_kind_of ::String, xml_data
|
74
|
+
assert_match /^<\?xml/, xml_data
|
75
|
+
assert_equal xml_data, subject.to_data
|
76
|
+
end
|
77
|
+
|
78
|
+
should "write xml data to a file path" do
|
79
|
+
path = subject.to_file("./tmp/base_test.xls")
|
80
|
+
assert_kind_of ::String, path
|
81
|
+
assert_equal './tmp/base_test.xls', path
|
82
|
+
assert File.exists?(path)
|
83
|
+
|
84
|
+
File.open(path) do |f|
|
85
|
+
assert_equal subject.to_data, f.read
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|