osheet 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/osheet/cell.rb +5 -1
- data/lib/osheet/column.rb +1 -0
- data/lib/osheet/markup_element.rb +22 -0
- data/lib/osheet/meta_element.rb +1 -1
- data/lib/osheet/partial.rb +24 -0
- data/lib/osheet/partial_set.rb +57 -0
- data/lib/osheet/row.rb +1 -0
- data/lib/osheet/template.rb +10 -24
- data/lib/osheet/template_set.rb +6 -12
- data/lib/osheet/version.rb +1 -1
- data/lib/osheet/{template_handler → view_handler}/rails.rb +0 -0
- data/lib/osheet/{template_handler → view_handler}/tilt.rb +0 -0
- data/lib/osheet/view_handler.rb +2 -0
- data/lib/osheet/workbook.rb +9 -0
- data/lib/osheet/worksheet.rb +5 -1
- data/lib/osheet/xmlss_writer/elements.rb +1 -0
- data/lib/osheet.rb +9 -6
- data/test/cell_test.rb +69 -29
- data/test/column_test.rb +67 -36
- data/test/env.rb +1 -0
- data/test/partial_set_test.rb +84 -0
- data/test/partial_test.rb +66 -0
- data/test/rails/three/Gemfile.lock +1 -1
- data/test/rails/three/app/views/things/index.xls.osheet +0 -2
- data/test/rails/two/Gemfile.lock +1 -1
- data/test/row_test.rb +69 -38
- data/test/style_test.rb +37 -16
- data/test/template_set_test.rb +34 -15
- data/test/template_test.rb +28 -44
- data/test/workbook_test.rb +143 -97
- data/test/worksheet_test.rb +87 -47
- data/test/xmlss_writer/elements_test.rb +3 -1
- metadata +14 -7
- data/lib/osheet/template_handler.rb +0 -2
data/Gemfile.lock
CHANGED
data/lib/osheet/cell.rb
CHANGED
@@ -7,6 +7,7 @@ module Osheet
|
|
7
7
|
include WorkbookElement
|
8
8
|
include WorksheetElement
|
9
9
|
include StyledElement
|
10
|
+
include MarkupElement
|
10
11
|
|
11
12
|
def initialize(workbook=nil, worksheet=nil, *args, &block)
|
12
13
|
set_ivar(:workbook, workbook)
|
@@ -16,6 +17,7 @@ module Osheet
|
|
16
17
|
set_ivar(:rowspan, 1)
|
17
18
|
set_ivar(:colspan, 1)
|
18
19
|
set_ivar(:href, nil)
|
20
|
+
set_ivar(:index, nil)
|
19
21
|
if block_given?
|
20
22
|
set_binding_ivars(block.binding)
|
21
23
|
instance_exec(*args, &block)
|
@@ -40,6 +42,7 @@ module Osheet
|
|
40
42
|
def rowspan(value); set_ivar(:rowspan, value); end
|
41
43
|
def colspan(value); set_ivar(:colspan, value); end
|
42
44
|
def href(value); set_ivar(:href, value); end
|
45
|
+
def index(value); set_ivar(:index, value); end
|
43
46
|
|
44
47
|
def attributes
|
45
48
|
{
|
@@ -48,7 +51,8 @@ module Osheet
|
|
48
51
|
:format => get_ivar(:format),
|
49
52
|
:colspan => get_ivar(:colspan),
|
50
53
|
:rowspan => get_ivar(:rowspan),
|
51
|
-
:href => get_ivar(:href)
|
54
|
+
:href => get_ivar(:href),
|
55
|
+
:index => get_ivar(:index)
|
52
56
|
}
|
53
57
|
end
|
54
58
|
|
data/lib/osheet/column.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Osheet
|
2
|
+
module MarkupElement
|
3
|
+
|
4
|
+
# markup elements can add partial markup to themselves
|
5
|
+
def add(partial_name, *args)
|
6
|
+
if self.kind_of?(Workbook)
|
7
|
+
# on: workbook
|
8
|
+
if (partial = self.partials.get(partial_name))
|
9
|
+
# add partial
|
10
|
+
instance_exec(*args, &partial)
|
11
|
+
end
|
12
|
+
else
|
13
|
+
# on: worksheet, column, row
|
14
|
+
if self.workbook && (partial = self.workbook.partials.get(partial_name))
|
15
|
+
# add partial
|
16
|
+
instance_exec(*args, &partial)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/osheet/meta_element.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Osheet
|
2
|
+
class Partial < ::Proc
|
3
|
+
|
4
|
+
# this class is essentially a way to define a named definition
|
5
|
+
# block with arguments. If the partial is added to an element,
|
6
|
+
# any markup in it's definition block is applied to the element.
|
7
|
+
# ie. the definition block will be instance_eval'd on the element.
|
8
|
+
|
9
|
+
include Instance
|
10
|
+
|
11
|
+
def initialize(name)
|
12
|
+
unless name.kind_of?(::String) || name.kind_of?(::Symbol)
|
13
|
+
raise ArgumentError, "please use a string or symbol for the partial name."
|
14
|
+
end
|
15
|
+
|
16
|
+
set_ivar(:name, name.to_s)
|
17
|
+
super()
|
18
|
+
end
|
19
|
+
|
20
|
+
def name; get_ivar(:name); end
|
21
|
+
def name=(v); set_ivar(:name, v); end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'osheet/partial'
|
2
|
+
|
3
|
+
module Osheet
|
4
|
+
class PartialSet < ::Hash
|
5
|
+
|
6
|
+
# this class is a Hash that behaves kinda like a set. I want to
|
7
|
+
# push partials into the set using the '<<' operator, only allow
|
8
|
+
# Osheet::Partial objs to be pushed, and then be able to reference
|
9
|
+
# a particular partial using a key
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def <<(partial)
|
16
|
+
if (key = verify(partial))
|
17
|
+
push(key, partial)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# return the named partial
|
22
|
+
def get(name)
|
23
|
+
lookup(key(name.to_s))
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def lookup(key)
|
29
|
+
self[key]
|
30
|
+
end
|
31
|
+
|
32
|
+
# push the partial onto the key
|
33
|
+
def push(key, partial)
|
34
|
+
self[key] = partial
|
35
|
+
end
|
36
|
+
|
37
|
+
# verify the partial, init and return the key
|
38
|
+
# otherwise ArgumentError it up
|
39
|
+
def verify(partial)
|
40
|
+
unless partial.kind_of?(Partial)
|
41
|
+
raise ArgumentError, 'you can only push Osheet::Partial objs to the partial set'
|
42
|
+
end
|
43
|
+
pkey = partial_key(partial)
|
44
|
+
self[pkey] ||= nil
|
45
|
+
pkey
|
46
|
+
end
|
47
|
+
|
48
|
+
def partial_key(partial)
|
49
|
+
key(partial.name)
|
50
|
+
end
|
51
|
+
|
52
|
+
def key(name)
|
53
|
+
name.to_s
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
data/lib/osheet/row.rb
CHANGED
data/lib/osheet/template.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
require 'osheet/partial'
|
2
|
+
|
1
3
|
module Osheet
|
2
|
-
class Template <
|
4
|
+
class Template < Partial
|
3
5
|
|
4
|
-
# this class is
|
5
|
-
# block and associate that with an osheet element
|
6
|
+
# this class is a partial that is associated with an osheet element
|
6
7
|
# if an element is initialized from a template, the template
|
7
8
|
# block will be instance_eval'd for the element being initialized
|
8
9
|
|
@@ -11,31 +12,16 @@ module Osheet
|
|
11
12
|
ELEMENTS = ['worksheet', 'column', 'row', 'cell']
|
12
13
|
|
13
14
|
def initialize(element, name)
|
14
|
-
verify(element, name)
|
15
|
-
set_ivar(:element, element.to_s)
|
16
|
-
set_ivar(:name, name.to_s)
|
17
|
-
super()
|
18
|
-
end
|
19
|
-
|
20
|
-
[:element, :name].each do |meth|
|
21
|
-
define_method(meth) do
|
22
|
-
get_ivar(meth)
|
23
|
-
end
|
24
|
-
define_method("#{meth}=") do |value|
|
25
|
-
set_ivar(meth, value)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def verify(element, name)
|
32
15
|
unless element.respond_to?(:to_s) && ELEMENTS.include?(element.to_s)
|
33
16
|
raise ArgumentError, "you can only define a template for #{ELEMENTS.join(', ')} elements."
|
34
17
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
18
|
+
|
19
|
+
set_ivar(:element, element.to_s)
|
20
|
+
super(name)
|
38
21
|
end
|
39
22
|
|
23
|
+
def element; get_ivar(:element); end
|
24
|
+
def element=(v); set_ivar(:element, v); end
|
25
|
+
|
40
26
|
end
|
41
27
|
end
|
data/lib/osheet/template_set.rb
CHANGED
@@ -1,23 +1,17 @@
|
|
1
|
+
require 'osheet/partial_set'
|
1
2
|
require 'osheet/template'
|
2
3
|
|
3
4
|
module Osheet
|
4
|
-
class TemplateSet <
|
5
|
+
class TemplateSet < PartialSet
|
5
6
|
|
6
|
-
# this class is a
|
7
|
-
#
|
8
|
-
#
|
9
|
-
# a particular set of templates using a key
|
7
|
+
# this class is a PartialSet that keys off of the template element
|
8
|
+
# and name. Only Osheet::Template objs can be pushed, and you reference
|
9
|
+
# a particular template using a key of
|
10
10
|
|
11
11
|
def initialize
|
12
12
|
super
|
13
13
|
end
|
14
14
|
|
15
|
-
def <<(template)
|
16
|
-
if (key = verify(template))
|
17
|
-
push(key, template)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
15
|
# return the template set for the named element
|
22
16
|
def get(element, name)
|
23
17
|
lookup(key(element.to_s, name.to_s))
|
@@ -51,7 +45,7 @@ module Osheet
|
|
51
45
|
end
|
52
46
|
|
53
47
|
def key(element, name)
|
54
|
-
[element, name]
|
48
|
+
[element.to_s, name.to_s]
|
55
49
|
end
|
56
50
|
end
|
57
51
|
end
|
data/lib/osheet/version.rb
CHANGED
File without changes
|
File without changes
|
data/lib/osheet/workbook.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'osheet/instance'
|
2
|
+
require 'osheet/associations'
|
3
|
+
require 'osheet/markup_element'
|
2
4
|
require 'osheet/style_set'
|
3
5
|
require 'osheet/template_set'
|
6
|
+
require 'osheet/partial_set'
|
4
7
|
require 'osheet/worksheet'
|
5
8
|
require 'osheet/xmlss_writer'
|
6
9
|
|
@@ -8,6 +11,7 @@ module Osheet
|
|
8
11
|
class Workbook
|
9
12
|
include Instance
|
10
13
|
include Associations
|
14
|
+
include MarkupElement
|
11
15
|
|
12
16
|
hm :worksheets
|
13
17
|
|
@@ -15,6 +19,7 @@ module Osheet
|
|
15
19
|
set_ivar(:title, nil)
|
16
20
|
set_ivar(:styles, StyleSet.new)
|
17
21
|
set_ivar(:templates, TemplateSet.new)
|
22
|
+
set_ivar(:partials, PartialSet.new)
|
18
23
|
if block_given?
|
19
24
|
set_binding_ivars(block.binding)
|
20
25
|
instance_eval(&block)
|
@@ -33,6 +38,10 @@ module Osheet
|
|
33
38
|
def templates
|
34
39
|
get_ivar(:templates)
|
35
40
|
end
|
41
|
+
def partial(name, &block); push_ivar(:partials, Partial.new(name, &block)); end
|
42
|
+
def partials
|
43
|
+
get_ivar(:partials)
|
44
|
+
end
|
36
45
|
|
37
46
|
def attributes
|
38
47
|
{ :title => get_ivar(:title) }
|
data/lib/osheet/worksheet.rb
CHANGED
@@ -7,6 +7,7 @@ module Osheet
|
|
7
7
|
include Associations
|
8
8
|
include WorkbookElement
|
9
9
|
include MetaElement
|
10
|
+
include MarkupElement
|
10
11
|
|
11
12
|
hm :columns
|
12
13
|
hm :rows
|
@@ -34,7 +35,10 @@ module Osheet
|
|
34
35
|
if get_ivar(:workbook) && get_ivar(:workbook).worksheets.collect{|ws| ws.name}.include?(name_value)
|
35
36
|
raise ArgumentError, "the sheet name '#{name_value}' is already in use. choose a sheet name that is not used by another sheet"
|
36
37
|
end
|
37
|
-
name_value
|
38
|
+
if name_value.to_s.length > 31
|
39
|
+
raise ArgumentError, "worksheet names must be less than 32 characters long"
|
40
|
+
end
|
41
|
+
name_value.to_s
|
38
42
|
end
|
39
43
|
|
40
44
|
end
|
@@ -53,6 +53,7 @@ module Osheet::XmlssWriter::Elements
|
|
53
53
|
::Xmlss::Cell.new({
|
54
54
|
:style_id => style_id(ocell.attributes[:style_class], ocell.attributes[:format]),
|
55
55
|
:href => ocell.attributes[:href],
|
56
|
+
:index => ocell.attributes[:index],
|
56
57
|
:merge_across => cell_merge(ocell.attributes[:colspan]),
|
57
58
|
:merge_down => cell_merge(ocell.attributes[:rowspan]),
|
58
59
|
:data => data(ocell.attributes[:data])
|
data/lib/osheet.rb
CHANGED
@@ -3,23 +3,26 @@ module Osheet
|
|
3
3
|
MIME_TYPE = "application/vnd.ms-excel"
|
4
4
|
|
5
5
|
class << self
|
6
|
-
# used to register an appropriate
|
6
|
+
# used to register an appropriate view handler
|
7
7
|
# and register a mime type if necessary
|
8
8
|
def register
|
9
9
|
::Mime::Type.register MIME_TYPE, :xls if defined? ::Mime::Type
|
10
|
-
require 'osheet/
|
10
|
+
require 'osheet/view_handler'
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
end
|
15
15
|
|
16
|
+
require 'osheet/instance'
|
17
|
+
require 'osheet/partial'
|
16
18
|
require 'osheet/associations'
|
17
|
-
require 'osheet/
|
18
|
-
|
19
|
+
require 'osheet/mixin'
|
20
|
+
|
21
|
+
require 'osheet/markup_element'
|
19
22
|
require 'osheet/styled_element'
|
20
23
|
require 'osheet/meta_element'
|
21
|
-
require 'osheet/
|
22
|
-
require 'osheet/
|
24
|
+
require 'osheet/workbook_element'
|
25
|
+
require 'osheet/worksheet_element'
|
23
26
|
|
24
27
|
if defined? Rails::Railtie
|
25
28
|
require 'osheet/railtie'
|
data/test/cell_test.rb
CHANGED
@@ -2,8 +2,8 @@ require "test/helper"
|
|
2
2
|
require 'osheet/cell'
|
3
3
|
|
4
4
|
module Osheet
|
5
|
-
class CellTest < Test::Unit::TestCase
|
6
5
|
|
6
|
+
class CellTest < Test::Unit::TestCase
|
7
7
|
context "Osheet::Cell" do
|
8
8
|
subject { Cell.new }
|
9
9
|
|
@@ -11,7 +11,7 @@ module Osheet
|
|
11
11
|
should_be_a_worksheet_element(Cell)
|
12
12
|
should_be_a_workbook_element(Cell)
|
13
13
|
|
14
|
-
should_have_instance_methods :data, :format, :colspan, :rowspan, :href
|
14
|
+
should_have_instance_methods :data, :format, :colspan, :rowspan, :href, :index
|
15
15
|
|
16
16
|
should "set it's defaults" do
|
17
17
|
assert_equal nil, subject.send(:get_ivar, "data")
|
@@ -19,57 +19,75 @@ module Osheet
|
|
19
19
|
assert_equal 1, subject.send(:get_ivar, "colspan")
|
20
20
|
assert_equal 1, subject.send(:get_ivar, "rowspan")
|
21
21
|
assert_equal nil, subject.send(:get_ivar, "href")
|
22
|
+
assert_equal nil, subject.send(:get_ivar, "index")
|
22
23
|
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
Cell.new do
|
27
|
-
style_class 'more poo'
|
28
|
-
data "Poo"
|
29
|
-
format :number
|
30
|
-
colspan 4
|
31
|
-
rowspan 2
|
32
|
-
href "http://www.google.com"
|
33
|
-
end
|
34
|
-
end
|
25
|
+
end
|
26
|
+
end
|
35
27
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
28
|
+
class CellAttributeTest < Test::Unit::TestCase
|
29
|
+
context "a celll that has attributes" do
|
30
|
+
subject do
|
31
|
+
Cell.new do
|
32
|
+
style_class 'more poo'
|
33
|
+
data "Poo"
|
34
|
+
format :number
|
35
|
+
colspan 4
|
36
|
+
rowspan 2
|
37
|
+
index 3
|
38
|
+
href "http://www.google.com"
|
42
39
|
end
|
40
|
+
end
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
42
|
+
should "should set them correctly" do
|
43
|
+
assert_equal "Poo", subject.send(:get_ivar, "data")
|
44
|
+
assert_kind_of Format::Number, subject.send(:get_ivar, "format")
|
45
|
+
assert_equal 4, subject.send(:get_ivar, "colspan")
|
46
|
+
assert_equal 2, subject.send(:get_ivar, "rowspan")
|
47
|
+
assert_equal 3, subject.send(:get_ivar, "index")
|
48
|
+
assert_equal "http://www.google.com", subject.send(:get_ivar, "href")
|
49
|
+
end
|
50
|
+
|
51
|
+
should "know it's attribute(s)" do
|
52
|
+
[:style_class, :data, :format, :rowspan, :colspan, :index, :href].each do |a|
|
53
|
+
assert subject.attributes.has_key?(a)
|
54
54
|
end
|
55
|
+
|
56
|
+
assert_equal "more poo", subject.attributes[:style_class]
|
57
|
+
assert_equal "Poo", subject.attributes[:data]
|
58
|
+
assert_kind_of Format::Number, subject.attributes[:format]
|
59
|
+
assert_equal 4, subject.attributes[:colspan]
|
60
|
+
assert_equal 2, subject.attributes[:rowspan]
|
61
|
+
assert_equal 3, subject.attributes[:index]
|
62
|
+
assert_equal "http://www.google.com", subject.attributes[:href]
|
55
63
|
end
|
56
64
|
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class CellDataTest < Test::Unit::TestCase
|
69
|
+
context "A cell" do
|
70
|
+
subject { Cell.new }
|
71
|
+
|
57
72
|
should "type cast data strings/symbols" do
|
58
73
|
['a string', :symbol].each do |thing|
|
59
74
|
cell = Cell.new{data thing}
|
60
75
|
assert_kind_of ::String, cell.send(:get_ivar, "data")
|
61
76
|
end
|
62
77
|
end
|
78
|
+
|
63
79
|
should "type cast data dates" do
|
64
80
|
cell = Cell.new{data Date.today}
|
65
81
|
assert_kind_of ::Date, cell.send(:get_ivar, "data")
|
66
82
|
end
|
83
|
+
|
67
84
|
should "type cast data numerics" do
|
68
85
|
[1, 1.0].each do |thing|
|
69
86
|
cell = Cell.new{data thing}
|
70
87
|
assert_kind_of ::Numeric, cell.send(:get_ivar, "data")
|
71
88
|
end
|
72
89
|
end
|
90
|
+
|
73
91
|
should "type cast all other data to string" do
|
74
92
|
[Osheet, [:a, 'Aye'], {:a => 'Aye'}].each do |thing|
|
75
93
|
cell = Cell.new{data thing}
|
@@ -78,7 +96,29 @@ module Osheet
|
|
78
96
|
end
|
79
97
|
|
80
98
|
end
|
99
|
+
end
|
81
100
|
|
101
|
+
class CellPartialTest < Test::Unit::TestCase
|
102
|
+
context "A workbook that defines column partials" do
|
103
|
+
subject do
|
104
|
+
Workbook.new {
|
105
|
+
partial(:cell_stuff) {
|
106
|
+
style_class 'more poo'
|
107
|
+
data "Poo"
|
108
|
+
}
|
109
|
+
|
110
|
+
worksheet { row { cell {
|
111
|
+
add :cell_stuff
|
112
|
+
} } }
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
should "add it's partials to it's markup" do
|
117
|
+
assert_equal 'more poo', subject.worksheets.first.rows.first.cells.first.attributes[:style_class]
|
118
|
+
assert_equal 'Poo', subject.worksheets.first.rows.first.cells.first.attributes[:data]
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
82
122
|
end
|
83
123
|
|
84
124
|
class CellBindingTest < Test::Unit::TestCase
|
data/test/column_test.rb
CHANGED
@@ -2,8 +2,8 @@ require "test/helper"
|
|
2
2
|
require "osheet/column"
|
3
3
|
|
4
4
|
module Osheet
|
5
|
-
class ColumnTest < Test::Unit::TestCase
|
6
5
|
|
6
|
+
class ColumnTest < Test::Unit::TestCase
|
7
7
|
context "Osheet::Column" do
|
8
8
|
subject { Column.new }
|
9
9
|
|
@@ -26,47 +26,56 @@ module Osheet
|
|
26
26
|
assert_equal nil, subject.meta
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
Column.new do
|
32
|
-
style_class "more poo"
|
33
|
-
width 100
|
34
|
-
autofit true
|
35
|
-
hidden true
|
36
|
-
meta(
|
37
|
-
{}
|
38
|
-
)
|
39
|
-
end
|
40
|
-
end
|
29
|
+
end
|
30
|
+
end
|
41
31
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
32
|
+
class ColumnAttributesTest < Test::Unit::TestCase
|
33
|
+
context "that has attributes" do
|
34
|
+
subject do
|
35
|
+
Column.new do
|
36
|
+
style_class "more poo"
|
37
|
+
width 100
|
38
|
+
autofit true
|
39
|
+
hidden true
|
40
|
+
meta(
|
41
|
+
{}
|
42
|
+
)
|
49
43
|
end
|
44
|
+
end
|
50
45
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
46
|
+
should "should set them correctly" do
|
47
|
+
assert_equal 100, subject.send(:get_ivar, "width")
|
48
|
+
assert_equal true, subject.send(:get_ivar, "autofit")
|
49
|
+
assert subject.autofit?
|
50
|
+
assert_equal true, subject.send(:get_ivar, "hidden")
|
51
|
+
assert subject.hidden?
|
52
|
+
assert_equal({}, subject.meta)
|
53
|
+
end
|
59
54
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
64
|
-
assert_equal 'more poo', subject.attributes[:style_class]
|
65
|
-
assert_equal 100, subject.attributes[:width]
|
66
|
-
assert_equal true, subject.attributes[:autofit]
|
67
|
-
assert_equal true, subject.attributes[:hidden]
|
55
|
+
should "know it's attribute(s)" do
|
56
|
+
[:style_class, :width, :autofit, :hidden].each do |a|
|
57
|
+
assert subject.attributes.has_key?(a)
|
68
58
|
end
|
59
|
+
assert_equal 'more poo', subject.attributes[:style_class]
|
60
|
+
assert_equal 100, subject.attributes[:width]
|
61
|
+
assert_equal true, subject.attributes[:autofit]
|
62
|
+
assert_equal true, subject.attributes[:hidden]
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
69
67
|
|
68
|
+
class ColumnDataTest < Test::Unit::TestCase
|
69
|
+
context "A column" do
|
70
|
+
subject { Column.new }
|
71
|
+
|
72
|
+
should "set it's width" do
|
73
|
+
subject.width(false)
|
74
|
+
assert_equal false, subject.width
|
75
|
+
subject.width(180)
|
76
|
+
assert_equal 180, subject.width
|
77
|
+
subject.width(nil)
|
78
|
+
assert_equal 180, subject.width
|
70
79
|
end
|
71
80
|
|
72
81
|
should "cast autofit and hidden to bool" do
|
@@ -76,7 +85,29 @@ module Osheet
|
|
76
85
|
end
|
77
86
|
|
78
87
|
end
|
88
|
+
end
|
79
89
|
|
90
|
+
class ColumnPartialTest < Test::Unit::TestCase
|
91
|
+
context "A workbook that defines column partials" do
|
92
|
+
subject do
|
93
|
+
Workbook.new {
|
94
|
+
partial(:column_stuff) {
|
95
|
+
width 200
|
96
|
+
meta(:label => 'awesome')
|
97
|
+
}
|
98
|
+
|
99
|
+
worksheet { column {
|
100
|
+
add :column_stuff
|
101
|
+
} }
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
should "add it's partials to it's markup" do
|
106
|
+
assert_equal 200, subject.worksheets.first.columns.first.width
|
107
|
+
assert_equal({:label => 'awesome'}, subject.worksheets.first.columns.first.meta)
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
80
111
|
end
|
81
112
|
|
82
113
|
class ColumnBindingTest < Test::Unit::TestCase
|