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.
Files changed (75) hide show
  1. data/Gemfile +0 -1
  2. data/Gemfile.lock +9 -6
  3. data/Rakefile +35 -19
  4. data/bench/bench_runner.rb +91 -0
  5. data/bench/profiler_runner.rb +1 -0
  6. data/examples/basic.rb +1 -1
  7. data/examples/basic.xls +2 -1
  8. data/examples/basic_with_templates.rb +2 -2
  9. data/examples/basic_with_templates.xls +3 -3
  10. data/examples/formats.rb +2 -2
  11. data/examples/formats.xls +46 -46
  12. data/examples/formula.rb +2 -2
  13. data/examples/styles.rb +2 -2
  14. data/examples/styles.xls +5 -5
  15. data/examples/trivial.rb +2 -2
  16. data/lib/osheet/cell.rb +48 -46
  17. data/lib/osheet/column.rb +23 -29
  18. data/lib/osheet/format.rb +3 -3
  19. data/lib/osheet/meta_element.rb +2 -1
  20. data/lib/osheet/mixin.rb +21 -9
  21. data/lib/osheet/partial.rb +5 -9
  22. data/lib/osheet/row.rb +28 -32
  23. data/lib/osheet/style.rb +11 -25
  24. data/lib/osheet/styled_element.rb +9 -1
  25. data/lib/osheet/template.rb +3 -8
  26. data/lib/osheet/version.rb +1 -1
  27. data/lib/osheet/workbook.rb +135 -43
  28. data/lib/osheet/workbook_api.rb +208 -0
  29. data/lib/osheet/workbook_element.rb +225 -8
  30. data/lib/osheet/worksheet.rb +22 -28
  31. data/lib/osheet/xmlss_writer/style_cache.rb +64 -0
  32. data/lib/osheet/xmlss_writer/style_settings.rb +148 -0
  33. data/lib/osheet/xmlss_writer.rb +143 -1
  34. data/lib/osheet.rb +3 -29
  35. data/osheet.gemspec +4 -1
  36. data/test/cell_test.rb +33 -98
  37. data/test/column_test.rb +20 -88
  38. data/test/{mixins.rb → fixtures/mixins.rb} +6 -4
  39. data/test/fixtures/test_writer.rb +68 -0
  40. data/test/format_test.rb +2 -2
  41. data/test/helper.rb +34 -68
  42. data/test/mixin_test.rb +37 -43
  43. data/test/partial_test.rb +3 -26
  44. data/test/row_test.rb +32 -85
  45. data/test/style_test.rb +9 -26
  46. data/test/template_test.rb +5 -6
  47. data/test/workbook_element_test.rb +231 -0
  48. data/test/workbook_test.rb +225 -116
  49. data/test/worksheet_test.rb +51 -98
  50. data/test/xmlss_writer/api_test.rb +139 -0
  51. data/test/xmlss_writer/style_cache_test.rb +65 -0
  52. data/test/xmlss_writer/style_settings_test.rb +263 -0
  53. data/test/xmlss_writer/styles_test.rb +121 -153
  54. data/test/xmlss_writer_test.rb +91 -0
  55. metadata +75 -50
  56. data/lib/osheet/associations.rb +0 -58
  57. data/lib/osheet/instance.rb +0 -30
  58. data/lib/osheet/markup_element.rb +0 -22
  59. data/lib/osheet/partial_set.rb +0 -57
  60. data/lib/osheet/railtie.rb +0 -9
  61. data/lib/osheet/style_set.rb +0 -39
  62. data/lib/osheet/template_set.rb +0 -51
  63. data/lib/osheet/view_handler/rails.rb +0 -44
  64. data/lib/osheet/view_handler/tilt.rb +0 -42
  65. data/lib/osheet/view_handler.rb +0 -2
  66. data/lib/osheet/worksheet_element.rb +0 -17
  67. data/lib/osheet/xmlss_writer/base.rb +0 -49
  68. data/lib/osheet/xmlss_writer/elements.rb +0 -56
  69. data/lib/osheet/xmlss_writer/styles.rb +0 -216
  70. data/test/osheet_test.rb +0 -13
  71. data/test/partial_set_test.rb +0 -64
  72. data/test/style_set_test.rb +0 -47
  73. data/test/template_set_test.rb +0 -74
  74. data/test/xmlss_writer/base_test.rb +0 -103
  75. 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 XmlssWriter::StylesTest < Assert::Context
7
+ class XmlssWriterStylesTest < Assert::Context
8
8
  before do
9
- @writer = XmlssWriter::Base.new
10
- @xworkbook = ::Xmlss::Workbook.new
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 XmlssWriter::StyleTests < XmlssWriter::StylesTest
23
+ class XmlssWriterStyleTests < XmlssWriterStylesTest
17
24
  desc "Xmlss style writer"
18
25
  before do
19
- subject.oworkbook = Workbook.new {
20
- style('.font.size') { font 14 }
21
- style('.font.weight') { font :bold }
22
- style('.font.style') { font :italic }
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.send(:style, @xworkbook, 'awesome')
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.used_xstyles.size
44
- assert_equal xmlss_style, subject.used_xstyles.first
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.send(:style, @xworkbook, 'font size weight style align center')
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 XmlssWriter::AlignmentTests < XmlssWriter::StylesTest
47
+ class XmlssWriterAlignmentTests < XmlssWriterStylesTest
67
48
  desc "Alignment style writer"
68
49
  before do
69
- subject.oworkbook = Workbook.new {
70
- [ :left, :center, :right,
71
- :top, :middle, :bottom,
72
- :wrap
73
- ].each do |s|
74
- style(".align.#{s}") { align s }
75
- end
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.send(:style, @xworkbook, 'align')
60
+ subject.style('align')
82
61
  assert_equal(
83
62
  "<Style ss:ID=\".align\"><NumberFormat /></Style>",
84
- xstyle_markup(@xworkbook)
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.send(:style, @xworkbook, 'align left')
90
- subject.send(:style, @xworkbook, 'align center')
91
- subject.send(:style, @xworkbook, 'align right')
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
- xstyle_markup(@xworkbook)
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.send(:style, @xworkbook, 'align top')
100
- subject.send(:style, @xworkbook, 'align middle')
101
- subject.send(:style, @xworkbook, 'align bottom')
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
- xstyle_markup(@xworkbook)
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.send(:style, @xworkbook, 'align wrap')
88
+ subject.style('align wrap')
110
89
  assert_equal(
111
90
  "<Style ss:ID=\".align.wrap\"><Alignment ss:WrapText=\"1\" /><NumberFormat /></Style>",
112
- xstyle_markup(@xworkbook)
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.send(:style, @xworkbook, 'align rotate')
96
+ subject.style('align rotate')
118
97
  assert_equal(
119
98
  "<Style ss:ID=\".align.rotate\"><Alignment ss:Rotate=\"90\" /><NumberFormat /></Style>",
120
- xstyle_markup(@xworkbook)
99
+ xmlss_style_markup(subject)
121
100
  )
122
101
  end
123
102
 
124
103
  end
125
104
 
126
- class XmlssWriter::FontTests < XmlssWriter::StylesTest
105
+ class XmlssWriterFontTests < XmlssWriterStylesTest
127
106
  desc "Font style writer"
128
107
  before do
129
- subject.oworkbook = Workbook.new {
130
- [ :underline, :double_underline, :accounting_underline, :double_accounting_underline,
131
- :subscript, :superscript, :shadow, :strikethrough, :wrap,
132
- :bold, :italic
133
- ].each do |s|
134
- style(".font.#{s}") { font s }
135
- end
136
- style('.font.size') { font 14 }
137
- style('.font.color') { font '#FF0000' }
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.send(:style, @xworkbook, 'font')
120
+ subject.style('font')
144
121
  assert_equal(
145
122
  "<Style ss:ID=\".font\"><NumberFormat /></Style>",
146
- xstyle_markup(@xworkbook)
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.send(:style, @xworkbook, 'font underline')
152
- subject.send(:style, @xworkbook, 'font double_underline')
153
- subject.send(:style, @xworkbook, 'font accounting_underline')
154
- subject.send(:style, @xworkbook, 'font double_accounting_underline')
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
- xstyle_markup(@xworkbook)
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.send(:style, @xworkbook, 'font subscript')
164
- subject.send(:style, @xworkbook, 'font superscript')
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
- xstyle_markup(@xworkbook)
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.send(:style, @xworkbook, 'font bold')
173
- subject.send(:style, @xworkbook, 'font italic')
174
- subject.send(:style, @xworkbook, 'font strikethrough')
175
- subject.send(:style, @xworkbook, 'font shadow')
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
- xstyle_markup(@xworkbook)
155
+ xmlss_style_markup(subject)
179
156
  )
180
157
  end
181
158
 
182
159
  should "write style markup for font size" do
183
- subject.send(:style, @xworkbook, 'font size')
160
+ subject.style('font size')
184
161
  assert_equal(
185
162
  "<Style ss:ID=\".font.size\"><Font ss:Size=\"14\" /><NumberFormat /></Style>",
186
- xstyle_markup(@xworkbook)
163
+ xmlss_style_markup(subject)
187
164
  )
188
165
  end
189
166
 
190
167
  should "write style markup for font color" do
191
- subject.send(:style, @xworkbook, 'font color')
168
+ subject.style('font color')
192
169
  assert_equal(
193
170
  "<Style ss:ID=\".font.color\"><Font ss:Color=\"#FF0000\" /><NumberFormat /></Style>",
194
- xstyle_markup(@xworkbook)
171
+ xmlss_style_markup(subject)
195
172
  )
196
173
  end
197
174
 
198
175
  should "write style markup for font name" do
199
- subject.send(:style, @xworkbook, 'font name')
176
+ subject.style('font name')
200
177
  assert_equal(
201
178
  "<Style ss:ID=\".font.name\"><Font ss:FontName=\"Verdana\" /><NumberFormat /></Style>",
202
- xstyle_markup(@xworkbook)
179
+ xmlss_style_markup(subject)
203
180
  )
204
181
  end
205
182
 
206
183
  end
207
184
 
208
- class XmlssWriter::BgTests < XmlssWriter::StylesTest
185
+ class XmlssWriterBgTests < XmlssWriterStylesTest
209
186
  desc "Bg writer"
210
187
  before do
211
- subject.oworkbook = Workbook.new {
212
- style('.bg.color') { bg '#FF0000' }
213
- style('.bg.pattern-only') { bg :solid }
214
- style('.bg.pattern-color') { bg :horz_stripe => '#0000FF' }
215
- style('.bg.color-first') { bg '#00FF00', {:horz_stripe => '#0000FF'} }
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.send(:style, @xworkbook, 'bg')
222
- # assert_equal nil, .interior
196
+ subject.style('bg')
223
197
  assert_equal(
224
198
  "<Style ss:ID=\".bg\"><NumberFormat /></Style>",
225
- xstyle_markup(@xworkbook)
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.send(:style, @xworkbook, 'bg color')
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
- xstyle_markup(@xworkbook)
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.send(:style, @xworkbook, 'bg pattern-only')
240
- subject.send(:style, @xworkbook, 'bg pattern-only')
241
- subject.send(:style, @xworkbook, 'bg pattern-color')
242
- subject.send(:style, @xworkbook, 'bg pattern-color')
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
- xstyle_markup(@xworkbook)
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.send(:style, @xworkbook, 'bg color')
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
- xstyle_markup(@xworkbook)
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.send(:style, @xworkbook, 'bg color-first')
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
- xstyle_markup(@xworkbook)
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.send(:style, @xworkbook, 'bg pattern-first')
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
- xstyle_markup(@xworkbook)
242
+ xmlss_style_markup(subject)
270
243
  )
271
244
  end
272
245
 
273
246
  end
274
247
 
275
- class XmlssWriter::BorderTests < XmlssWriter::StylesTest
248
+ class XmlssWriterBorderTests < XmlssWriterStylesTest
276
249
  desc "Font border writer"
277
250
  before do
278
- subject.oworkbook = Workbook.new {
279
- ::Osheet::Style::BORDER_POSITIONS.each do |p|
280
- style(".border.#{p}") { send("border_#{p}", :thin) }
281
- end
282
- [:hairline, :thin, :medium, :thick].each do |w|
283
- style(".border.#{w}") { border_top w }
284
- end
285
- [:none, :continuous, :dash, :dot, :dash_dot, :dash_dot_dot].each do |s|
286
- style(".border.#{s}") { border_top s }
287
- end
288
- style('.border.color') { border_top '#FF0000' }
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.send(:style, @xworkbook, 'border')
265
+ subject.style('border')
295
266
  assert_equal(
296
267
  "<Style ss:ID=\".border\"><NumberFormat /></Style>",
297
- xstyle_markup(@xworkbook)
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.send(:style, @xworkbook, 'border all')
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
- xstyle_markup(@xworkbook)
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.send(:style, @xworkbook, "border #{p}")
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
- xstyle_markup(@xworkbook)
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.send(:style, @xworkbook, "border #{w}")
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
- xstyle_markup(@xworkbook)
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.send(:style, @xworkbook, "border #{s}")
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
- xstyle_markup(@xworkbook)
306
+ xmlss_style_markup(subject)
336
307
  )
337
308
  end
338
309
 
339
310
  should "write style markup for border color" do
340
- subject.send(:style, @xworkbook, 'border color')
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
- xstyle_markup(@xworkbook)
314
+ xmlss_style_markup(subject)
344
315
  )
345
316
  end
346
317
 
347
318
  end
348
319
 
349
- class XmlssWriter::NumberFormatTests < XmlssWriter::StylesTest
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.send(:style, @xworkbook, '', Osheet::Format.new(:text))
357
- subject.send(:style, @xworkbook, '', Osheet::Format.new(:datetime, 'mm/dd/yy'))
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
- xstyle_markup(@xworkbook)
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