osheet 0.10.0 → 1.0.0.rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'osheet/style'
|
2
|
+
require 'osheet/xmlss_writer'
|
3
|
+
|
4
|
+
class Osheet::XmlssWriter
|
5
|
+
class StyleSettings
|
6
|
+
|
7
|
+
attr_reader :styles, :value
|
8
|
+
|
9
|
+
def initialize(styles)
|
10
|
+
@styles = styles
|
11
|
+
@value = @styles.inject({}) do |value, style|
|
12
|
+
merged_settings(value, style_settings(style))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def [](setting); @value[setting]; end
|
17
|
+
|
18
|
+
# call the given block passing it the setting if that setting
|
19
|
+
# exists and is not empty
|
20
|
+
def setting(s, &block)
|
21
|
+
block.call if self.value[s] && !self.value[s].empty?
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def merged_settings(current, add)
|
27
|
+
# concat values for keys in both sets
|
28
|
+
current.keys.each do |k|
|
29
|
+
current[k].merge!(add.delete(k) || {})
|
30
|
+
end
|
31
|
+
# merge keys for anything not in the current
|
32
|
+
current.merge(add)
|
33
|
+
end
|
34
|
+
|
35
|
+
def style_settings(osheet_style_obj)
|
36
|
+
settings = {}
|
37
|
+
Osheet::Style::SETTINGS.each do |setting|
|
38
|
+
if !(v = osheet_style_obj.send(setting)).empty?
|
39
|
+
settings[setting] = self.send("#{setting}_settings", v)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
settings
|
43
|
+
end
|
44
|
+
|
45
|
+
def align_settings(osheet_align_directives)
|
46
|
+
osheet_align_directives.inject({}) do |settings, directive|
|
47
|
+
case directive
|
48
|
+
when :left, :center, :right
|
49
|
+
settings[:horizontal] = directive
|
50
|
+
when :top, :bottom
|
51
|
+
settings[:vertical] = directive
|
52
|
+
when :middle
|
53
|
+
settings[:vertical] = :center
|
54
|
+
when :wrap
|
55
|
+
settings[:wrap_text] = true
|
56
|
+
when ::Fixnum
|
57
|
+
settings[:rotate] = directive
|
58
|
+
end
|
59
|
+
settings
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def font_settings(osheet_font_directives)
|
64
|
+
osheet_font_directives.inject({}) do |settings, directive|
|
65
|
+
case directive
|
66
|
+
when ::Fixnum
|
67
|
+
settings[:size] = directive
|
68
|
+
when ::String
|
69
|
+
if directive =~ /^#/
|
70
|
+
settings[:color] = directive
|
71
|
+
else
|
72
|
+
settings[:name] = directive
|
73
|
+
end
|
74
|
+
when :bold, :italic, :shadow
|
75
|
+
settings[directive] = true
|
76
|
+
when :subscript, :superscript
|
77
|
+
settings[:alignment] = directive
|
78
|
+
when :strikethrough
|
79
|
+
settings[:strike_through] = true
|
80
|
+
when :underline
|
81
|
+
settings[:underline] = :single
|
82
|
+
when :double_underline
|
83
|
+
settings[:underline] = :double
|
84
|
+
when :accounting_underline
|
85
|
+
settings[:underline] = :single_accounting
|
86
|
+
when :double_accounting_underline
|
87
|
+
settings[:underline] = :double_accounting
|
88
|
+
end
|
89
|
+
settings
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def bg_settings(osheet_bg_directives)
|
94
|
+
osheet_bg_directives.inject({}) do |settings, directive|
|
95
|
+
case directive
|
96
|
+
when ::String
|
97
|
+
if directive =~ /^#/
|
98
|
+
settings[:color] = directive
|
99
|
+
end
|
100
|
+
when ::Symbol
|
101
|
+
if ::Xmlss::Style::Interior.pattern_set.include?(directive)
|
102
|
+
settings[:pattern] = directive
|
103
|
+
end
|
104
|
+
when ::Hash
|
105
|
+
directive.each do |pattern, color|
|
106
|
+
if ::Xmlss::Style::Interior.pattern_set.include?(pattern) && color =~ /^#/
|
107
|
+
settings[:pattern] = pattern
|
108
|
+
settings[:pattern_color] = color
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
if !settings[:color].nil? && settings[:pattern].nil?
|
114
|
+
settings[:pattern] = :solid
|
115
|
+
end
|
116
|
+
|
117
|
+
settings
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def border_settings(osheet_border_directives)
|
122
|
+
osheet_border_directives.inject({}) do |settings, directive|
|
123
|
+
case directive
|
124
|
+
when ::String
|
125
|
+
if directive =~ /^#/
|
126
|
+
settings[:color] = directive
|
127
|
+
end
|
128
|
+
when ::Symbol
|
129
|
+
if ::Xmlss::Style::Border.position_set.include?(directive)
|
130
|
+
settings[:position] = directive
|
131
|
+
elsif ::Xmlss::Style::Border.weight_set.include?(directive)
|
132
|
+
settings[:weight] = directive
|
133
|
+
elsif ::Xmlss::Style::Border.line_style_set.include?(directive)
|
134
|
+
settings[:line_style] = directive
|
135
|
+
end
|
136
|
+
end
|
137
|
+
settings
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
::Osheet::Style::BORDER_POSITIONS.each do |p|
|
142
|
+
define_method("border_#{p}_settings") do |cmds|
|
143
|
+
border_settings(cmds+[p])
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
end
|
data/lib/osheet/xmlss_writer.rb
CHANGED
@@ -1 +1,143 @@
|
|
1
|
-
require 'osheet
|
1
|
+
require 'osheet'
|
2
|
+
require 'xmlss'
|
3
|
+
|
4
|
+
require 'osheet/xmlss_writer/style_cache'
|
5
|
+
|
6
|
+
module Osheet
|
7
|
+
class XmlssWriter
|
8
|
+
|
9
|
+
# The Osheet::XmlssWriter provides the logic/translation needed to drive
|
10
|
+
# an xmlss workbook using the Osheet API. The writer creates an xmlss
|
11
|
+
# workbook and uses the builder approach to drive the workbook creation.
|
12
|
+
|
13
|
+
# The writer maintains a set of used xmlss styles and handles creating
|
14
|
+
# xmlss style objects as needed and manages style keys
|
15
|
+
|
16
|
+
attr_reader :style_cache, :xmlss_workbook
|
17
|
+
|
18
|
+
def initialize(*args, &block)
|
19
|
+
@xmlss_workbook = Xmlss::Workbook.new(Xmlss::Writer.new(*args, &block))
|
20
|
+
@osheet_workbook = nil
|
21
|
+
@osheet_worksheet_names = []
|
22
|
+
@style_cache = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def bind(osheet_workbook)
|
26
|
+
@osheet_workbook = osheet_workbook
|
27
|
+
@style_cache = StyleCache.new(@osheet_workbook, @xmlss_workbook)
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
@xmlss_workbook.to_s
|
32
|
+
end
|
33
|
+
alias_method :to_data, :to_s
|
34
|
+
|
35
|
+
def to_file(file_path)
|
36
|
+
@xmlss_workbook.to_file(file_path)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Element writers
|
40
|
+
|
41
|
+
def worksheet(worksheet, &build)
|
42
|
+
if @osheet_workbook && @osheet_worksheet_names.include?(worksheet.name.to_s)
|
43
|
+
raise ArgumentError, "you can't write two worksheets with the same name ('#{worksheet.name}')"
|
44
|
+
end
|
45
|
+
@osheet_worksheet_names << worksheet.name.to_s
|
46
|
+
@xmlss_workbook.worksheet(worksheet.name, &build)
|
47
|
+
end
|
48
|
+
|
49
|
+
def column(column, &build)
|
50
|
+
attrs = {
|
51
|
+
:width => column.width,
|
52
|
+
:auto_fit_width => column.autofit,
|
53
|
+
:hidden => column.hidden
|
54
|
+
}
|
55
|
+
if s = @style_cache.get(column.style_class, column.format)
|
56
|
+
attrs[:style_id] = s.id
|
57
|
+
end
|
58
|
+
@xmlss_workbook.column(attrs, &build)
|
59
|
+
end
|
60
|
+
|
61
|
+
def row(row, &build)
|
62
|
+
attrs = {
|
63
|
+
:height => row.height,
|
64
|
+
:auto_fit_height => row.autofit,
|
65
|
+
:hidden => row.hidden
|
66
|
+
}
|
67
|
+
if s = @style_cache.get(row.style_class, row.format)
|
68
|
+
attrs[:style_id] = s.id
|
69
|
+
end
|
70
|
+
@xmlss_workbook.row(attrs, &build)
|
71
|
+
end
|
72
|
+
|
73
|
+
def cell(cell, &build)
|
74
|
+
attrs = {
|
75
|
+
:href => cell.href,
|
76
|
+
:index => cell.index,
|
77
|
+
:merge_across => cell_merge(cell.colspan),
|
78
|
+
:merge_down => cell_merge(cell.rowspan),
|
79
|
+
:formula => cell.formula
|
80
|
+
}
|
81
|
+
if s = @style_cache.get(cell.style_class, cell.format)
|
82
|
+
attrs[:style_id] = s.id
|
83
|
+
end
|
84
|
+
@xmlss_workbook.cell(cell.data, attrs, &build)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Element style writers
|
88
|
+
|
89
|
+
# given an elements style_class or format attributes:
|
90
|
+
# 1) write a new xmlss style object and
|
91
|
+
# 2) set the current element's style_id attribute
|
92
|
+
|
93
|
+
def style(style_class, format=nil)
|
94
|
+
@style_cache.get(
|
95
|
+
style_class,
|
96
|
+
format || Osheet::Format.new(:general)
|
97
|
+
).tap do |xmlss_style|
|
98
|
+
@xmlss_workbook.style_id(xmlss_style.id)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def colspan(count)
|
103
|
+
@xmlss_workbook.merge_across(cell_merge(count))
|
104
|
+
end
|
105
|
+
|
106
|
+
def rowspan(count)
|
107
|
+
@xmlss_workbook.merge_down(cell_merge(count))
|
108
|
+
end
|
109
|
+
|
110
|
+
def name(value)
|
111
|
+
@osheet_worksheet_names.pop
|
112
|
+
@osheet_worksheet_names << value
|
113
|
+
@xmlss_workbook.name(value)
|
114
|
+
end
|
115
|
+
|
116
|
+
# Element attribute writers
|
117
|
+
|
118
|
+
[ :width, # column
|
119
|
+
:height, # row
|
120
|
+
:autofit, # column, row
|
121
|
+
:autofit?, # column, row
|
122
|
+
:hidden, # column, row
|
123
|
+
:hidden?, # column, row
|
124
|
+
:data, # cell
|
125
|
+
:format, # cell
|
126
|
+
:href, # cell
|
127
|
+
:formula, # cell
|
128
|
+
:index # cell
|
129
|
+
].each do |meth|
|
130
|
+
define_method(meth) do |*args, &block|
|
131
|
+
@xmlss_workbook.send(meth, *args, &block)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
protected
|
136
|
+
|
137
|
+
# convert osheet col/row span value to xmlss merge value
|
138
|
+
def cell_merge(span)
|
139
|
+
span.kind_of?(::Fixnum) && span > 1 ? span-1 : 0
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
data/lib/osheet.rb
CHANGED
@@ -1,31 +1,5 @@
|
|
1
|
-
module Osheet
|
2
|
-
|
3
|
-
MIME_TYPE = "application/vnd.ms-excel"
|
4
|
-
|
5
|
-
class << self
|
6
|
-
# used to register an appropriate view handler
|
7
|
-
# and register a mime type if necessary
|
8
|
-
def register
|
9
|
-
::Mime::Type.register MIME_TYPE, :xls if defined? ::Mime::Type
|
10
|
-
require 'osheet/view_handler'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
require 'osheet/instance'
|
17
|
-
require 'osheet/partial'
|
18
|
-
require 'osheet/associations'
|
19
|
-
require 'osheet/mixin'
|
20
|
-
|
21
|
-
require 'osheet/markup_element'
|
22
|
-
require 'osheet/styled_element'
|
23
|
-
require 'osheet/meta_element'
|
24
|
-
require 'osheet/workbook_element'
|
25
|
-
require 'osheet/worksheet_element'
|
26
|
-
|
27
|
-
if defined? Rails::Railtie
|
28
|
-
require 'osheet/railtie'
|
29
|
-
end
|
1
|
+
module Osheet; end
|
30
2
|
|
31
3
|
require 'osheet/workbook'
|
4
|
+
require 'osheet/xmlss_writer'
|
5
|
+
|
data/osheet.gemspec
CHANGED
@@ -19,7 +19,10 @@ Gem::Specification.new do |s|
|
|
19
19
|
|
20
20
|
s.add_development_dependency("bundler", ["~> 1.0"])
|
21
21
|
s.add_development_dependency("assert", ["~> 0.3"])
|
22
|
+
s.add_development_dependency("whysoslow", ["~> 0.0"])
|
23
|
+
s.add_development_dependency("ruby-prof")
|
24
|
+
|
22
25
|
s.add_dependency("enumeration", ["~> 1.3"])
|
23
|
-
s.add_dependency("xmlss", ["~> 0.
|
26
|
+
s.add_dependency("xmlss", ["~> 1.0.0.rc"])
|
24
27
|
|
25
28
|
end
|
data/test/cell_test.rb
CHANGED
@@ -3,133 +3,68 @@ require 'osheet/cell'
|
|
3
3
|
|
4
4
|
module Osheet
|
5
5
|
|
6
|
-
class
|
7
|
-
desc "
|
6
|
+
class CellTests < Assert::Context
|
7
|
+
desc "a Cell"
|
8
8
|
before { @c = Cell.new }
|
9
9
|
subject { @c }
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
should_be_a_workbook_element(Cell)
|
11
|
+
should be_a_styled_element
|
12
|
+
should be_a_meta_element
|
14
13
|
|
15
|
-
should have_instance_methods :data, :format, :
|
14
|
+
should have_instance_methods :data, :format, :href, :index
|
15
|
+
should have_instance_methods :colspan, :rowspan
|
16
16
|
|
17
17
|
should "set it's defaults" do
|
18
|
-
assert_equal nil, subject.
|
19
|
-
|
20
|
-
assert_equal 1, subject.
|
21
|
-
assert_equal
|
22
|
-
assert_equal nil,
|
23
|
-
assert_equal nil,
|
24
|
-
|
18
|
+
assert_equal nil, subject.data
|
19
|
+
assert_equal 1, subject.colspan
|
20
|
+
assert_equal 1, subject.rowspan
|
21
|
+
assert_equal nil, subject.href
|
22
|
+
assert_equal nil, subject.index
|
23
|
+
assert_equal nil, subject.formula
|
24
|
+
assert_kind_of Format::General, subject.format
|
25
|
+
end
|
26
|
+
|
27
|
+
should "set its data from an init arg" do
|
28
|
+
assert_equal "something", Cell.new("something").data
|
25
29
|
end
|
26
30
|
|
27
31
|
should "type cast data strings/symbols" do
|
28
32
|
['a string', :symbol].each do |thing|
|
29
|
-
|
30
|
-
assert_kind_of ::String,
|
33
|
+
subject.data thing
|
34
|
+
assert_kind_of ::String, subject.data
|
35
|
+
assert_kind_of ::String, Cell.new(thing).data
|
31
36
|
end
|
32
37
|
end
|
33
38
|
|
34
39
|
should "type cast data dates" do
|
35
|
-
|
36
|
-
assert_kind_of ::Date,
|
40
|
+
subject.data Date.today
|
41
|
+
assert_kind_of ::Date, subject.data
|
42
|
+
assert_kind_of ::Date, Cell.new(Date.today).data
|
37
43
|
end
|
38
44
|
|
39
45
|
should "type cast data numerics" do
|
40
46
|
[1, 1.0].each do |thing|
|
41
|
-
|
42
|
-
assert_kind_of ::Numeric,
|
47
|
+
subject.data thing
|
48
|
+
assert_kind_of ::Numeric, subject.data
|
49
|
+
assert_kind_of ::Numeric, Cell.new(thing).data
|
43
50
|
end
|
44
51
|
end
|
45
52
|
|
46
53
|
should "type cast all other data to string" do
|
47
54
|
[Osheet, [:a, 'Aye'], {:a => 'Aye'}].each do |thing|
|
48
|
-
|
49
|
-
assert_kind_of ::String,
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
class CellAttributeTest < CellTest
|
56
|
-
desc "a celll that has attributes"
|
57
|
-
before do
|
58
|
-
@c = Cell.new do
|
59
|
-
style_class 'more poo'
|
60
|
-
data "Poo"
|
61
|
-
format :number
|
62
|
-
colspan 4
|
63
|
-
rowspan 2
|
64
|
-
index 3
|
65
|
-
formula "=R1C1"
|
66
|
-
href "http://www.google.com"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
should "should set them correctly" do
|
71
|
-
assert_equal "Poo", subject.send(:get_ivar, "data")
|
72
|
-
assert_kind_of Format::Number, subject.send(:get_ivar, "format")
|
73
|
-
assert_equal 4, subject.send(:get_ivar, "colspan")
|
74
|
-
assert_equal 2, subject.send(:get_ivar, "rowspan")
|
75
|
-
assert_equal 3, subject.send(:get_ivar, "index")
|
76
|
-
assert_equal "=R1C1", subject.send(:get_ivar, "formula")
|
77
|
-
assert_equal "http://www.google.com", subject.send(:get_ivar, "href")
|
78
|
-
end
|
79
|
-
|
80
|
-
should "know it's attribute(s)" do
|
81
|
-
[:style_class, :data, :format, :rowspan, :colspan, :index, :href].each do |a|
|
82
|
-
assert subject.attributes.has_key?(a)
|
55
|
+
subject.data thing
|
56
|
+
assert_kind_of ::String, subject.data
|
57
|
+
assert_kind_of ::String, Cell.new(thing).data
|
83
58
|
end
|
84
|
-
|
85
|
-
assert_equal "more poo", subject.attributes[:style_class]
|
86
|
-
assert_equal "Poo", subject.attributes[:data]
|
87
|
-
assert_kind_of Format::Number, subject.attributes[:format]
|
88
|
-
assert_equal 4, subject.attributes[:colspan]
|
89
|
-
assert_equal 2, subject.attributes[:rowspan]
|
90
|
-
assert_equal 3, subject.attributes[:index]
|
91
|
-
assert_equal "=R1C1", subject.attributes[:formula]
|
92
|
-
assert_equal "http://www.google.com", subject.attributes[:href]
|
93
59
|
end
|
94
60
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
desc "A workbook that defines column partials"
|
99
|
-
before do
|
100
|
-
@wkbk = Workbook.new {
|
101
|
-
partial(:cell_stuff) {
|
102
|
-
style_class 'more poo'
|
103
|
-
data "Poo"
|
104
|
-
}
|
105
|
-
|
106
|
-
worksheet { row { cell {
|
107
|
-
add :cell_stuff
|
108
|
-
} } }
|
109
|
-
}
|
110
|
-
end
|
111
|
-
subject { @wkbk }
|
61
|
+
should "format data explicitly" do
|
62
|
+
subject.data Time.now
|
63
|
+
subject.format :datetime, 'mm/dd/yyyy'
|
112
64
|
|
113
|
-
|
114
|
-
assert_equal 'more poo', subject.worksheets.first.rows.first.cells.first.attributes[:style_class]
|
115
|
-
assert_equal 'Poo', subject.worksheets.first.rows.first.cells.first.attributes[:data]
|
65
|
+
assert_kind_of Format::Datetime, subject.format
|
116
66
|
end
|
117
67
|
|
118
68
|
end
|
119
69
|
|
120
|
-
class CellBindingTest < Assert::Context
|
121
|
-
desc "a cell defined w/ a block"
|
122
|
-
|
123
|
-
should "access instance vars from that block's binding" do
|
124
|
-
@test = 'test'
|
125
|
-
@cell = Cell.new { data @test}
|
126
|
-
|
127
|
-
assert !@cell.send(:instance_variable_get, "@test").nil?
|
128
|
-
assert_equal @test, @cell.send(:instance_variable_get, "@test")
|
129
|
-
assert_equal @test.object_id, @cell.send(:instance_variable_get, "@test").object_id
|
130
|
-
assert_equal @test, @cell.attributes[:data]
|
131
|
-
assert_equal @test.object_id, @cell.attributes[:data].object_id
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
70
|
end
|
data/test/column_test.rb
CHANGED
@@ -1,119 +1,51 @@
|
|
1
1
|
require "assert"
|
2
|
+
|
2
3
|
require "osheet/column"
|
3
4
|
|
4
5
|
module Osheet
|
5
6
|
|
6
|
-
class
|
7
|
-
desc "
|
7
|
+
class ColumnTests < Assert::Context
|
8
|
+
desc "a Column"
|
8
9
|
before { @c = Column.new }
|
9
10
|
subject { @c }
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
should_be_a_workbook_element(Column)
|
12
|
+
should be_a_styled_element
|
13
|
+
should be_a_meta_element
|
14
14
|
|
15
|
-
should
|
15
|
+
should have_reader :format
|
16
|
+
should have_instance_methods :width
|
16
17
|
should have_instance_methods :autofit, :autofit?
|
17
18
|
should have_instance_methods :hidden, :hidden?
|
18
|
-
should have_instance_method :meta
|
19
19
|
|
20
20
|
should "set it's defaults" do
|
21
|
-
assert_equal nil, subject.
|
22
|
-
assert_equal false, subject.
|
21
|
+
assert_equal nil, subject.width
|
22
|
+
assert_equal false, subject.autofit
|
23
23
|
assert !subject.autofit?
|
24
|
-
assert_equal false, subject.
|
24
|
+
assert_equal false, subject.hidden
|
25
25
|
assert !subject.hidden?
|
26
|
-
|
27
|
-
assert_equal nil, subject.meta
|
26
|
+
assert_kind_of Format::General, subject.format
|
28
27
|
end
|
29
28
|
|
30
29
|
should "set it's width" do
|
31
30
|
subject.width(false)
|
32
31
|
assert_equal false, subject.width
|
32
|
+
|
33
33
|
subject.width(180)
|
34
34
|
assert_equal 180, subject.width
|
35
|
+
|
35
36
|
subject.width(nil)
|
36
37
|
assert_equal 180, subject.width
|
37
|
-
end
|
38
38
|
|
39
|
-
|
40
|
-
col = Column.new { autofit :true; hidden 'false'}
|
41
|
-
assert_kind_of ::TrueClass, col.send(:get_ivar, "autofit")
|
42
|
-
assert_kind_of ::TrueClass, col.send(:get_ivar, "hidden")
|
39
|
+
assert_equal 200, Column.new(200).width
|
43
40
|
end
|
44
41
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
before do
|
50
|
-
@c = Column.new do
|
51
|
-
style_class "more poo"
|
52
|
-
width 100
|
53
|
-
autofit true
|
54
|
-
hidden true
|
55
|
-
meta(
|
56
|
-
{}
|
57
|
-
)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
should "should set them correctly" do
|
62
|
-
assert_equal 100, subject.send(:get_ivar, "width")
|
63
|
-
assert_equal true, subject.send(:get_ivar, "autofit")
|
64
|
-
assert subject.autofit?
|
65
|
-
assert_equal true, subject.send(:get_ivar, "hidden")
|
66
|
-
assert subject.hidden?
|
67
|
-
assert_equal({}, subject.meta)
|
68
|
-
end
|
69
|
-
|
70
|
-
should "know it's attribute(s)" do
|
71
|
-
[:style_class, :width, :autofit, :hidden].each do |a|
|
72
|
-
assert subject.attributes.has_key?(a)
|
73
|
-
end
|
74
|
-
assert_equal 'more poo', subject.attributes[:style_class]
|
75
|
-
assert_equal 100, subject.attributes[:width]
|
76
|
-
assert_equal true, subject.attributes[:autofit]
|
77
|
-
assert_equal true, subject.attributes[:hidden]
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
|
82
|
-
class ColumnPartialTest < Assert::Context
|
83
|
-
desc "A workbook that defines column partials"
|
84
|
-
before do
|
85
|
-
@wkbk = Workbook.new {
|
86
|
-
partial(:column_stuff) {
|
87
|
-
width 200
|
88
|
-
meta(:label => 'awesome')
|
89
|
-
}
|
90
|
-
|
91
|
-
worksheet { column {
|
92
|
-
add :column_stuff
|
93
|
-
} }
|
94
|
-
}
|
95
|
-
end
|
96
|
-
subject { @wkbk }
|
97
|
-
|
98
|
-
should "add it's partials to it's markup" do
|
99
|
-
assert_equal 200, subject.worksheets.first.columns.first.width
|
100
|
-
assert_equal({:label => 'awesome'}, subject.worksheets.first.columns.first.meta)
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
class ColumnBindingTest < Assert::Context
|
106
|
-
desc "a column defined w/ a block"
|
107
|
-
|
108
|
-
should "access instance vars from that block's binding" do
|
109
|
-
@test = 50
|
110
|
-
@col = Column.new { width @test }
|
42
|
+
should "cast autofit and hidden to bool" do
|
43
|
+
col = Column.new
|
44
|
+
col.autofit :true
|
45
|
+
col.hidden 'false'
|
111
46
|
|
112
|
-
|
113
|
-
assert_equal
|
114
|
-
assert_equal @test.object_id, @col.send(:instance_variable_get, "@test").object_id
|
115
|
-
assert_equal @test, @col.attributes[:width]
|
116
|
-
assert_equal @test.object_id, @col.attributes[:width].object_id
|
47
|
+
assert_equal true, col.autofit
|
48
|
+
assert_equal true, col.hidden
|
117
49
|
end
|
118
50
|
|
119
51
|
end
|
@@ -9,7 +9,9 @@ class StyledMixin
|
|
9
9
|
include Osheet::Mixin
|
10
10
|
|
11
11
|
style('.test')
|
12
|
-
style('.test.awesome')
|
12
|
+
style('.test.awesome') {
|
13
|
+
align :left
|
14
|
+
}
|
13
15
|
|
14
16
|
end
|
15
17
|
|
@@ -39,10 +41,10 @@ class PartialedMixin
|
|
39
41
|
row { }
|
40
42
|
}
|
41
43
|
|
42
|
-
partial(:two_cells_in_a_row) {
|
44
|
+
partial(:two_cells_in_a_row) { |data_one, data_two|
|
43
45
|
row {
|
44
|
-
cell { data
|
45
|
-
cell { data
|
46
|
+
cell { data data_one.to_s }
|
47
|
+
cell { data data_two.to_s }
|
46
48
|
}
|
47
49
|
}
|
48
50
|
end
|