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,68 @@
|
|
1
|
+
class TestWriter
|
2
|
+
|
3
|
+
attr_accessor :styles, :worksheets, :columns, :rows, :cells
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@styles = []
|
7
|
+
@worksheets = []
|
8
|
+
@columns = []
|
9
|
+
@rows = []
|
10
|
+
@cells = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def bind(workbook)
|
14
|
+
workbook
|
15
|
+
end
|
16
|
+
|
17
|
+
def style(obj, &block)
|
18
|
+
@styles << obj
|
19
|
+
block.call if !block.nil?
|
20
|
+
end
|
21
|
+
|
22
|
+
def worksheet(obj, &block)
|
23
|
+
@worksheets << obj
|
24
|
+
block.call if !block.nil?
|
25
|
+
end
|
26
|
+
|
27
|
+
def column(obj, &block)
|
28
|
+
@columns << obj
|
29
|
+
block.call if !block.nil?
|
30
|
+
end
|
31
|
+
|
32
|
+
def row(obj, &block)
|
33
|
+
@rows << obj
|
34
|
+
block.call if !block.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
def cell(obj, &block)
|
38
|
+
@cells << obj
|
39
|
+
block.call if !block.nil?
|
40
|
+
end
|
41
|
+
|
42
|
+
def style(*args)
|
43
|
+
return *args
|
44
|
+
end
|
45
|
+
|
46
|
+
[ :title, # workbook_element
|
47
|
+
:name, # worksheet
|
48
|
+
:meta, # worksheet, column, row, cell
|
49
|
+
:width, # column
|
50
|
+
:height, # row
|
51
|
+
:autofit, # column, row
|
52
|
+
:autofit?, # column, row
|
53
|
+
:hidden, # column, row
|
54
|
+
:hidden?, # column, row
|
55
|
+
:data, # cell
|
56
|
+
:href, # cell
|
57
|
+
:formula, # cell
|
58
|
+
:index, # cell
|
59
|
+
:rowspan, # cell
|
60
|
+
:colspan, # cell
|
61
|
+
].each do |meth|
|
62
|
+
define_method(meth) do |*args|
|
63
|
+
# cool story bro (don't do anything, just allow)
|
64
|
+
return *args
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
data/test/format_test.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -3,104 +3,70 @@
|
|
3
3
|
# add root dir to the load path
|
4
4
|
$LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
|
5
5
|
|
6
|
-
require 'osheet'
|
7
|
-
|
8
6
|
class Assert::Context
|
9
7
|
|
10
|
-
def
|
11
|
-
|
8
|
+
def xmlss_style_markup(writer)
|
9
|
+
Xmlss::Workbook.writer(writer.xmlss_workbook).styles_markup.flush.to_s
|
12
10
|
end
|
13
11
|
|
14
|
-
def
|
15
|
-
|
12
|
+
def xmlss_element_markup(writer)
|
13
|
+
Xmlss::Workbook.writer(writer.xmlss_workbook).worksheets_markup.flush.to_s
|
16
14
|
end
|
17
15
|
|
18
|
-
|
19
|
-
|
16
|
+
# Macros
|
20
17
|
|
21
|
-
|
22
|
-
|
18
|
+
def self.be_a_meta_element(*args)
|
19
|
+
called_from = caller.first
|
20
|
+
macro_name = "be a meta element"
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
template(:column, :thing) {}
|
27
|
-
template(:row, :empty) {}
|
28
|
-
style('.title') {
|
29
|
-
font 14
|
30
|
-
}
|
31
|
-
style('.title', '.header') {
|
32
|
-
font :bold
|
33
|
-
}
|
34
|
-
}
|
35
|
-
klass = klass.new(wkbk)
|
22
|
+
Assert::Macro.new(macro_name) do
|
23
|
+
should have_instance_method :meta, [called_from]
|
36
24
|
|
37
|
-
|
38
|
-
assert_equal
|
39
|
-
assert_equal wkbk.templates, klass.templates
|
25
|
+
should "default an empty meta value", called_from do
|
26
|
+
assert_equal nil, subject.class.new.meta
|
40
27
|
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def should_be_a_worksheet_element(klass)
|
44
|
-
should have_instance_methods :worksheet, :columns
|
45
28
|
|
46
|
-
should "
|
47
|
-
|
48
|
-
column {}
|
49
|
-
column {}
|
50
|
-
column {}
|
51
|
-
}
|
52
|
-
klass = klass.new(nil, wksht)
|
29
|
+
should "set meta info", called_from do
|
30
|
+
meta_elem = subject.class.new
|
53
31
|
|
54
|
-
|
55
|
-
assert_equal
|
32
|
+
meta_elem.meta({:key => "value"})
|
33
|
+
assert_equal({:key => "value"}, meta_elem.meta)
|
56
34
|
end
|
57
35
|
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.be_a_styled_element(*args)
|
39
|
+
called_from = caller.first
|
40
|
+
macro_name = "be a styled element"
|
58
41
|
|
59
|
-
|
60
|
-
should
|
42
|
+
Assert::Macro.new(macro_name) do
|
43
|
+
should have_instance_method :style_class, [called_from]
|
61
44
|
|
62
|
-
should "default an empty style class" do
|
63
|
-
|
64
|
-
assert_equal nil, default.send(:get_ivar, "style_class")
|
45
|
+
should "default an empty style class", called_from do
|
46
|
+
assert_equal nil, subject.class.new.style_class
|
65
47
|
end
|
66
48
|
|
67
|
-
should "set a style class" do
|
68
|
-
styled =
|
69
|
-
|
49
|
+
should "set a style class", called_from do
|
50
|
+
styled = subject.class.new
|
51
|
+
styled.style_class("awesome thing")
|
52
|
+
assert_equal "awesome thing", styled.style_class
|
70
53
|
end
|
71
54
|
|
72
|
-
should "
|
55
|
+
should "validate the style class string", called_from do
|
73
56
|
['.thing', 'thing.thing', 'thing .thing > thing', 'thin>g'].each do |s|
|
74
57
|
assert_raises ArgumentError do
|
75
|
-
|
58
|
+
subject.class.new.style_class(s)
|
76
59
|
end
|
77
60
|
end
|
61
|
+
|
78
62
|
['thing', '#thing 123', 'thing-one thing_one'].each do |s|
|
79
63
|
assert_nothing_raised do
|
80
|
-
|
64
|
+
subject.class.new.style_class(s)
|
81
65
|
end
|
82
66
|
end
|
83
67
|
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def should_hm(klass, collection, item_klass)
|
87
|
-
should have_reader collection
|
88
|
-
should have_instance_method collection.to_s.sub(/s$/, '')
|
89
|
-
|
90
|
-
should "should initialize #{collection} and add them to it's collection" do
|
91
|
-
singular = collection.to_s.sub(/s$/, '')
|
92
|
-
thing = klass.new do
|
93
|
-
self.send(singular) {}
|
94
|
-
end
|
95
|
-
|
96
|
-
items = thing.send(:get_ivar, collection)
|
97
|
-
assert_equal items, thing.send(collection)
|
98
|
-
assert !items.empty?
|
99
|
-
assert_equal 1, items.size
|
100
|
-
assert_kind_of item_klass, items.first
|
101
|
-
end
|
102
68
|
|
103
69
|
end
|
104
|
-
|
105
70
|
end
|
71
|
+
|
106
72
|
end
|
data/test/mixin_test.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require "assert"
|
2
|
-
require "test/mixins"
|
2
|
+
require "test/fixtures/mixins"
|
3
|
+
require 'osheet/workbook'
|
3
4
|
|
4
5
|
module Osheet
|
5
6
|
|
6
|
-
class
|
7
|
-
desc "
|
7
|
+
class MixinTests < Assert::Context
|
8
|
+
desc "a mixin"
|
8
9
|
subject { DefaultMixin }
|
9
10
|
|
10
11
|
should have_readers :styles, :templates, :partials
|
@@ -17,70 +18,63 @@ module Osheet
|
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
|
-
class
|
21
|
+
class MixinArgsTests < MixinTests
|
22
|
+
desc "args class"
|
23
|
+
before do
|
24
|
+
@build_block = Proc.new {}
|
25
|
+
@ma = Mixin::Args.new('some', 'args', 'here', &@build_block)
|
26
|
+
end
|
27
|
+
subject { @ma }
|
28
|
+
|
29
|
+
should have_readers :args, :build
|
30
|
+
|
31
|
+
should "collect arguments" do
|
32
|
+
assert_equal ['some', 'args', 'here'], subject.args
|
33
|
+
end
|
34
|
+
|
35
|
+
should "store a build block" do
|
36
|
+
assert_same @build_block, subject.build
|
37
|
+
end
|
38
|
+
|
39
|
+
should "default with empty args and an empty Proc build" do
|
40
|
+
default = Mixin::Args.new
|
41
|
+
|
42
|
+
assert_empty default.args
|
43
|
+
assert_kind_of Proc, default.build
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
class MixinStyleTests < Assert::Context
|
21
49
|
desc "that defines styles"
|
22
50
|
subject { StyledMixin }
|
23
51
|
|
24
52
|
should "have it's styles defined" do
|
25
53
|
assert_equal 2, subject.styles.size
|
26
|
-
|
27
|
-
assert_equal '.test', subject.styles.first.selectors.first
|
28
|
-
assert_equal 1, subject.styles.last.selectors.size
|
29
|
-
assert_equal '.test.awesome', subject.styles.last.selectors.first
|
54
|
+
assert_kind_of Mixin::Args, subject.styles.first
|
30
55
|
end
|
31
56
|
end
|
32
57
|
|
33
|
-
class
|
58
|
+
class MixinTemplateTests < Assert::Context
|
34
59
|
desc "that defines templates"
|
35
60
|
subject { TemplatedMixin }
|
36
61
|
|
37
62
|
should "have it's templates defined" do
|
38
63
|
assert subject.templates
|
39
64
|
assert_equal 3, subject.templates.size
|
40
|
-
assert_kind_of
|
65
|
+
assert_kind_of Mixin::Args, subject.templates.first
|
41
66
|
end
|
42
67
|
end
|
43
68
|
|
44
|
-
class
|
69
|
+
class MixinPartialTests < Assert::Context
|
45
70
|
desc "that defines partials"
|
46
71
|
subject { PartialedMixin }
|
47
72
|
|
48
73
|
should "have it's partials defined" do
|
49
74
|
assert subject.partials
|
50
75
|
assert_equal 2, subject.partials.size
|
51
|
-
assert_kind_of
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class MixinUseTest < Assert::Context
|
56
|
-
desc "A workbook that uses mixins"
|
57
|
-
setup do
|
58
|
-
@workbook = Osheet::Workbook.new do
|
59
|
-
use PartialedMixin
|
60
|
-
use TemplatedMixin
|
61
|
-
use StyledMixin
|
62
|
-
end
|
63
|
-
end
|
64
|
-
subject { @workbook }
|
65
|
-
|
66
|
-
should "have mixin partials" do
|
67
|
-
workbook_partials = @workbook.partials.values
|
68
|
-
PartialedMixin.partials.each do |partial|
|
69
|
-
assert workbook_partials.include?(partial)
|
70
|
-
end
|
76
|
+
assert_kind_of Mixin::Args, subject.partials.first
|
71
77
|
end
|
72
|
-
|
73
|
-
should "have mixin templates" do
|
74
|
-
workbook_templates = @workbook.templates.values.collect{ |t| t.values.first }
|
75
|
-
TemplatedMixin.templates.each do |template|
|
76
|
-
assert workbook_templates.include?(template)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
should "have mixin styles" do
|
81
|
-
assert_equal StyledMixin.styles, @workbook.styles
|
82
|
-
end
|
83
|
-
|
84
78
|
end
|
85
79
|
|
86
80
|
end
|
data/test/partial_test.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
require "assert"
|
2
|
+
|
2
3
|
require "osheet/partial"
|
3
4
|
|
4
5
|
module Osheet
|
5
6
|
class PartialTest < Assert::Context
|
6
|
-
desc "
|
7
|
+
desc "a Partial"
|
7
8
|
before { @p = Partial.new(:thing) {} }
|
8
9
|
subject { @p }
|
9
10
|
|
10
|
-
should have_accessor :name
|
11
|
-
|
12
11
|
should "be a Proc" do
|
13
12
|
assert_kind_of ::Proc, subject
|
14
13
|
end
|
15
14
|
|
16
15
|
should "convert the name arg to a string and store off" do
|
17
|
-
assert_equal 'thing', subject.name
|
16
|
+
assert_equal 'thing', subject.instance_variable_get("@name")
|
18
17
|
end
|
19
18
|
|
20
19
|
end
|
@@ -39,26 +38,4 @@ module Osheet
|
|
39
38
|
|
40
39
|
end
|
41
40
|
|
42
|
-
class PartialBindingTest < Assert::Context
|
43
|
-
desc "a partial defined w/ a block"
|
44
|
-
|
45
|
-
should "access instance vars from that block's binding" do
|
46
|
-
@test = 'test thing'
|
47
|
-
@workbook = Workbook.new {
|
48
|
-
partial(:stuff) {
|
49
|
-
worksheet(:thing) { name @test }
|
50
|
-
}
|
51
|
-
|
52
|
-
add(:stuff)
|
53
|
-
}
|
54
|
-
|
55
|
-
assert !@workbook.worksheets.first.send(:instance_variable_get, "@test").nil?
|
56
|
-
assert_equal @test, @workbook.worksheets.first.send(:instance_variable_get, "@test")
|
57
|
-
assert_equal @test.object_id, @workbook.worksheets.first.send(:instance_variable_get, "@test").object_id
|
58
|
-
assert_equal @test, @workbook.worksheets.first.attributes[:name]
|
59
|
-
assert_equal @test.object_id, @workbook.worksheets.first.attributes[:name].object_id
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
41
|
end
|
data/test/row_test.rb
CHANGED
@@ -1,124 +1,71 @@
|
|
1
1
|
require "assert"
|
2
|
+
|
3
|
+
require 'osheet/cell'
|
2
4
|
require 'osheet/row'
|
3
5
|
|
4
6
|
module Osheet
|
5
7
|
|
6
|
-
class
|
7
|
-
desc "
|
8
|
+
class RowTests < Assert::Context
|
9
|
+
desc "a Row"
|
8
10
|
before { @rw = Row.new }
|
9
11
|
subject { @rw }
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
should_be_a_workbook_element(Row)
|
13
|
+
should be_a_styled_element
|
14
|
+
should be_a_meta_element
|
14
15
|
|
15
|
-
should
|
16
|
+
should have_reader :format
|
17
|
+
should have_instance_methods :height
|
16
18
|
should have_instance_methods :autofit, :autofit?
|
17
19
|
should have_instance_methods :hidden, :hidden?
|
18
|
-
should
|
19
|
-
|
20
|
-
should_hm(Row, :cells, Cell)
|
20
|
+
should have_instance_methods :cells, :cell
|
21
21
|
|
22
22
|
should "set it's defaults" do
|
23
|
-
assert_equal nil, subject.
|
24
|
-
assert_equal false, subject.
|
23
|
+
assert_equal nil, subject.height
|
24
|
+
assert_equal false, subject.autofit
|
25
25
|
assert !subject.autofit?
|
26
|
-
assert_equal false, subject.
|
26
|
+
assert_equal false, subject.hidden
|
27
27
|
assert !subject.hidden?
|
28
|
-
|
29
|
-
assert_equal [], subject.cells
|
30
|
-
assert_equal nil, subject.meta
|
28
|
+
assert_kind_of Format::General, subject.format
|
31
29
|
end
|
32
30
|
|
33
|
-
should "set it's
|
31
|
+
should "set it's width" do
|
34
32
|
subject.height(false)
|
35
33
|
assert_equal false, subject.height
|
34
|
+
|
36
35
|
subject.height(180)
|
37
36
|
assert_equal 180, subject.height
|
37
|
+
|
38
38
|
subject.height(nil)
|
39
39
|
assert_equal 180, subject.height
|
40
|
-
end
|
41
|
-
|
42
|
-
should "cast autofit and hidden to bool" do
|
43
|
-
rw = Row.new { autofit :true; hidden 'false'}
|
44
|
-
assert_kind_of ::TrueClass, rw.send(:get_ivar, "autofit")
|
45
|
-
assert_kind_of ::TrueClass, rw.send(:get_ivar, "hidden")
|
46
|
-
end
|
47
40
|
|
48
|
-
|
49
|
-
|
50
|
-
class RowAttributeTest < RowTest
|
51
|
-
desc "a row that has attributes"
|
52
|
-
before do
|
53
|
-
@rw = Row.new do
|
54
|
-
style_class "poo"
|
55
|
-
height 100
|
56
|
-
autofit true
|
57
|
-
hidden true
|
58
|
-
meta(
|
59
|
-
{}
|
60
|
-
)
|
61
|
-
end
|
41
|
+
assert_equal 200, Row.new(200).height
|
62
42
|
end
|
63
43
|
|
64
|
-
should "
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
assert_equal true, subject.send(:get_ivar, "hidden")
|
69
|
-
assert subject.hidden?
|
70
|
-
assert_equal({}, subject.meta)
|
71
|
-
end
|
44
|
+
should "cast autofit and hidden to bool" do
|
45
|
+
row = Row.new
|
46
|
+
row.autofit :true
|
47
|
+
row.hidden 'false'
|
72
48
|
|
73
|
-
|
74
|
-
|
75
|
-
assert subject.attributes.has_key?(a)
|
76
|
-
end
|
77
|
-
assert_equal 'poo', subject.attributes[:style_class]
|
78
|
-
assert_equal 100, subject.attributes[:height]
|
79
|
-
assert_equal true, subject.attributes[:autofit]
|
80
|
-
assert_equal true, subject.attributes[:hidden]
|
49
|
+
assert_equal true, row.autofit
|
50
|
+
assert_equal true, row.hidden
|
81
51
|
end
|
82
52
|
|
83
53
|
end
|
84
54
|
|
85
|
-
class
|
86
|
-
desc "
|
87
|
-
before
|
88
|
-
@
|
89
|
-
|
90
|
-
|
91
|
-
meta 'awesome'
|
92
|
-
}
|
93
|
-
|
94
|
-
worksheet { row {
|
95
|
-
add :row_stuff
|
96
|
-
} }
|
97
|
-
}
|
98
|
-
end
|
99
|
-
subject { @wkbk }
|
55
|
+
class RowCellTests < RowTests
|
56
|
+
desc "with cells"
|
57
|
+
before {
|
58
|
+
@cell = Cell.new
|
59
|
+
@rw.cell(@cell)
|
60
|
+
}
|
100
61
|
|
101
|
-
should "
|
102
|
-
assert_equal
|
103
|
-
|
62
|
+
should "know its cells" do
|
63
|
+
assert_equal 1, subject.cells.size
|
64
|
+
assert_same @cell, subject.cells.first
|
104
65
|
end
|
105
66
|
|
106
67
|
end
|
107
68
|
|
108
|
-
class RowBindingTest < Assert::Context
|
109
|
-
desc "a row defined w/ a block"
|
110
69
|
|
111
|
-
should "access instance vars from that block's binding" do
|
112
|
-
@test = 50
|
113
|
-
@row = Row.new { height @test }
|
114
|
-
|
115
|
-
assert !@row.send(:instance_variable_get, "@test").nil?
|
116
|
-
assert_equal @test, @row.send(:instance_variable_get, "@test")
|
117
|
-
assert_equal @test.object_id, @row.send(:instance_variable_get, "@test").object_id
|
118
|
-
assert_equal @test, @row.attributes[:height]
|
119
|
-
assert_equal @test.object_id, @row.attributes[:height].object_id
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
123
70
|
|
124
71
|
end
|
data/test/style_test.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
require "assert"
|
2
|
+
|
2
3
|
require "osheet/style"
|
3
4
|
|
4
5
|
module Osheet
|
5
6
|
|
6
7
|
class StyleTest < Assert::Context
|
7
|
-
desc "
|
8
|
+
desc "a Style"
|
8
9
|
before { @st = Style.new('.test') }
|
9
10
|
subject { @st }
|
10
11
|
|
11
|
-
should have_reader :selectors
|
12
|
-
should have_instance_methods :align, :font, :bg
|
13
|
-
should have_instance_methods :
|
12
|
+
should have_reader :selectors, :build
|
13
|
+
should have_instance_methods :align, :font, :bg, :border
|
14
|
+
should have_instance_methods :border_left, :border_top
|
15
|
+
should have_instance_methods :border_right, :border_bottom
|
14
16
|
should have_instance_method :match?
|
15
17
|
|
16
18
|
should "set it's defaults" do
|
@@ -19,15 +21,7 @@ module Osheet
|
|
19
21
|
[ :align, :font, :bg,
|
20
22
|
:border_left, :border_top, :border_right, :border_bottom
|
21
23
|
].each do |a|
|
22
|
-
assert_equal [], subject.send(
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
should "know it's attribute(s)" do
|
27
|
-
[ :align, :font, :bg,
|
28
|
-
:border_left, :border_top, :border_right, :border_bottom
|
29
|
-
].each do |a|
|
30
|
-
assert subject.attributes.has_key?(a)
|
24
|
+
assert_equal [], subject.send(a)
|
31
25
|
end
|
32
26
|
end
|
33
27
|
|
@@ -53,7 +47,7 @@ module Osheet
|
|
53
47
|
should "collect styles for #{a}" do
|
54
48
|
args = [1, "#FF0000", "Verdana", :love, 1.2]
|
55
49
|
subject.send(a, *args)
|
56
|
-
assert_equal args, subject.send(
|
50
|
+
assert_equal args, subject.send(a)
|
57
51
|
end
|
58
52
|
end
|
59
53
|
|
@@ -61,7 +55,7 @@ module Osheet
|
|
61
55
|
args = [:thick, '#FF00FF', :dot]
|
62
56
|
subject.border *args
|
63
57
|
[ :border_left, :border_top, :border_right, :border_bottom].each do |a|
|
64
|
-
assert_equal args, subject.send(
|
58
|
+
assert_equal args, subject.send(a)
|
65
59
|
end
|
66
60
|
end
|
67
61
|
|
@@ -88,17 +82,6 @@ module Osheet
|
|
88
82
|
assert_equal false, a.match?('stupid')
|
89
83
|
end
|
90
84
|
|
91
|
-
should "access instance vars from that block's binding" do
|
92
|
-
@test = 20
|
93
|
-
@style = Style.new('.test') { font @test }
|
94
|
-
|
95
|
-
assert !@style.send(:instance_variable_get, "@test").nil?
|
96
|
-
assert_equal @test, @style.send(:instance_variable_get, "@test")
|
97
|
-
assert_equal @test.object_id, @style.send(:instance_variable_get, "@test").object_id
|
98
|
-
assert_equal @test, @style.attributes[:font].first
|
99
|
-
assert_equal @test.object_id, @style.attributes[:font].first.object_id
|
100
|
-
end
|
101
|
-
|
102
85
|
end
|
103
86
|
|
104
87
|
end
|
data/test/template_test.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require "assert"
|
2
|
+
|
2
3
|
require "osheet/template"
|
3
4
|
|
4
5
|
module Osheet
|
5
6
|
|
6
|
-
class
|
7
|
-
desc "
|
7
|
+
class TemplateTests < Assert::Context
|
8
|
+
desc "a Template"
|
8
9
|
before do
|
9
10
|
@tmpl = Template.new('column', :thing) {}
|
10
11
|
end
|
@@ -14,19 +15,17 @@ module Osheet
|
|
14
15
|
assert_equal ['worksheet', 'column', 'row', 'cell'], Template::ELEMENTS
|
15
16
|
end
|
16
17
|
|
17
|
-
should have_accessor :element
|
18
|
-
|
19
18
|
should "be a Partial" do
|
20
19
|
assert_kind_of Partial, subject
|
21
20
|
end
|
22
21
|
|
23
22
|
should "convert the element ars to string and store off" do
|
24
|
-
assert_equal 'column', subject.element
|
23
|
+
assert_equal 'column', subject.instance_variable_get("@element")
|
25
24
|
end
|
26
25
|
|
27
26
|
end
|
28
27
|
|
29
|
-
class TemplateElementTest <
|
28
|
+
class TemplateElementTest < TemplateTests
|
30
29
|
desc "a template"
|
31
30
|
|
32
31
|
should "verify the element argument" do
|