htmlgrid 1.1.0 → 1.1.5

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.
@@ -71,20 +71,20 @@ module HtmlGrid
71
71
  yield self if(@component.respond_to?(:label?) && @component.label?)
72
72
  yield @component
73
73
  end
74
- def to_html(context)
75
- key = @label_key
76
- label = @lookandfeel.lookup(key)
77
- if(!label && @component.respond_to?(:name))
78
- key = @component.name
79
- label = @lookandfeel.lookup(key)
80
- end
74
+ def to_html(context)
75
+ key = @label_key
76
+ label = @lookandfeel.lookup(key)
77
+ if !label && @component.respond_to?(:name)
78
+ key = @component.name
79
+ label = @lookandfeel.lookup(key)
80
+ end
81
81
  state = @session.state
82
- if(label && state.respond_to?(:mandatory?) && state.mandatory?(key))
83
- label += "*"
84
- end
85
- if(label)
86
- context.label(@attributes) { label }
87
- end
88
- end
82
+ if label && state.respond_to?(:mandatory?) && state.mandatory?(key)
83
+ label += '*'
84
+ end
85
+ if label
86
+ context.label(@attributes) { label }
87
+ end
88
+ end
89
89
  end
90
90
  end
@@ -143,28 +143,28 @@ module HtmlGrid
143
143
  end
144
144
  link
145
145
  end
146
- def sort_model
147
- block = self::class::SORT_DEFAULT
148
- if(block && (@session.event != :sort))
149
- begin
150
- if(block == :self)
151
- @model = @model.sort
152
- else
153
- unless(block.is_a?(Proc))
154
- block = Proc.new { |item|
155
- begin
156
- item.send(self::class::SORT_DEFAULT)
157
- rescue RuntimeError => e
158
- item.to_s
159
- end
160
- }
161
- end
162
- @model = @model.sort_by(&block)
163
- end
164
- rescue StandardError => e
165
- puts "could not sort: #{e.message}"
166
- end
167
- end
168
- end
146
+ def sort_model
147
+ block = self::class::SORT_DEFAULT
148
+ if block && (@session.event != :sort)
149
+ begin
150
+ if block == :self
151
+ @model = @model.sort
152
+ else
153
+ unless block.is_a?(Proc)
154
+ block = Proc.new { |item|
155
+ begin
156
+ item.send(self::class::SORT_DEFAULT)
157
+ rescue RuntimeError
158
+ item.to_s
159
+ end
160
+ }
161
+ end
162
+ @model = @model.sort_by(&block)
163
+ end
164
+ rescue StandardError => e
165
+ puts "could not sort: #{e.message}"
166
+ end
167
+ end
168
+ end
169
169
  end
170
170
  end
@@ -35,13 +35,29 @@ module HtmlGrid
35
35
  LEGACY_INTERFACE = true
36
36
  CSS_FILES = []
37
37
  JAVASCRIPTS = []
38
+ @@local_doc_dir = File.join(Dir.pwd, 'doc')
39
+ def get_inline(ressource)
40
+ local_file = File.join(@@local_doc_dir, URI(ressource).path)
41
+ if File.exist?(local_file)
42
+ # puts "Reading #{ressource} #{local_file} #{File.size(local_file)}"
43
+ File.read(local_file)
44
+ else
45
+ nil
46
+ end
47
+ end
38
48
  def css_link(context, path=@lookandfeel.resource(:css))
39
49
  properties = {
40
50
  "rel" => "stylesheet",
41
51
  "type" => "text/css",
42
- "href" => path,
52
+ "async" => "true",
53
+ 'href' => path,
43
54
  }
44
- context.link(properties)
55
+ if (content = get_inline(path))
56
+ properties.delete('href')
57
+ context.style(properties) { content }
58
+ else
59
+ context.link(properties)
60
+ end
45
61
  end
46
62
  def css_links(context, path=@lookandfeel.resource(:css))
47
63
  links = self.class.const_get(:CSS_FILES).collect { |key|
@@ -71,8 +87,8 @@ module HtmlGrid
71
87
  context.head {
72
88
  if(block_given?)
73
89
  block.call
74
- end.to_s <<
75
- title(context) <<
90
+ end
91
+ context.head << title(context) <<
76
92
  meta_tags(context) <<
77
93
  other_html_headers(context) <<
78
94
  css_links(context) <<
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
  module HtmlGrid
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.5'
5
5
  end
@@ -25,8 +25,6 @@
25
25
 
26
26
  $: << File.expand_path(File.dirname(__FILE__))
27
27
 
28
- require 'rebuild'
29
-
30
28
  Dir.foreach(File.dirname(__FILE__)) { |file|
31
29
  require file if /^test_.*\.rb$/o.match(file)
32
30
  }
@@ -9,67 +9,86 @@ require 'htmlgrid/composite'
9
9
  require 'htmlgrid/inputtext'
10
10
  require 'htmlgrid/form'
11
11
 
12
- class StubComposite < HtmlGrid::Composite
13
- attr_writer :container
14
- COMPONENTS = {
15
- [0,0,1] => :foo,
16
- }
17
- LABELS = true
18
- SYMBOL_MAP = {
19
- :bar => HtmlGrid::InputText,
20
- }
21
- attr_reader :model, :session
22
- public :resolve_offset, :labels?
23
- def init
24
- @barcount=0
25
- super
26
- end
27
- def foo(model)
28
- 1.upto(2).each { |idx|
29
- @grid.add(baz(model), 0, idx, 0)
12
+ module RowTest
13
+ class StubComposite < HtmlGrid::Composite
14
+ attr_writer :container
15
+ COMPONENTS = {
16
+ [0, 0, 1] => :foo,
30
17
  }
31
- "Foo"
32
- end
33
- def baz(model)
34
- @barcount += 1
35
- "Baz#{@barcount}"
36
- end
37
- end
38
- class StubCompositeModel
39
- end
40
- class StubComposite2Model
41
- end
42
- class StubCompositeLookandfeel
43
- def attributes(key)
44
- {}
45
- end
46
- def lookup(key)
47
- end
48
- def base_url
49
- 'http://www.oddb.org/de/gcc'
18
+ LABELS = true
19
+ SYMBOL_MAP = {
20
+ :bar => HtmlGrid::InputText,
21
+ }
22
+ attr_reader :model, :session
23
+ public :resolve_offset, :labels?
24
+
25
+ def init
26
+ @barcount=0
27
+ super
28
+ end
29
+
30
+ def foo(session, model)
31
+ 1.upto(2).each { |idx|
32
+ @grid.add(baz(model), 0, idx, 0)
33
+ }
34
+ 'Foo'
35
+ end
36
+
37
+ private
38
+
39
+ def baz(model)
40
+ @barcount += 1
41
+ "Baz#{@barcount}"
42
+ end
50
43
  end
51
- end
52
- class StubCompositeSession
53
- def lookandfeel
54
- StubCompositeLookandfeel.new
44
+
45
+ class StubCompositeModel; end
46
+
47
+ class StubComposite2Model; end
48
+
49
+ class StubCompositeLookandfeel
50
+ def attributes(key)
51
+ {}
52
+ end
53
+
54
+ def lookup(key)
55
+ end
56
+
57
+ def base_url
58
+ 'http://www.oddb.org/de/gcc'
59
+ end
55
60
  end
56
- def error(key)
61
+
62
+ class StubCompositeSession
63
+ def lookandfeel
64
+ StubCompositeLookandfeel.new
65
+ end
66
+
67
+ def error(key)
68
+ end
57
69
  end
58
- end
59
- class StubCompositeForm < HtmlGrid::Form
60
- COMPONENTS = {
61
- [0,0] => StubComposite
62
- }
63
- EVENT = :foo
64
- end
65
70
 
66
- class TestComposite < Minitest::Test
67
- def setup
68
- @composite = StubComposite.new([StubComposite2Model.new, StubCompositeModel.new],
69
- StubCompositeSession.new)
71
+ class StubCompositeForm < HtmlGrid::Form
72
+ COMPONENTS = {
73
+ [0, 0] => StubComposite
74
+ }
75
+ EVENT = :foo
70
76
  end
71
- def test_to_html
72
- expected = '<TABLE cellspacing="0"><TR><TD>Foo</TD></TR><TR><TD>Baz1</TD></TR><TR><TD>Baz2</TD></TR></TABLE>'
73
- assert_equal(expected, @composite.to_html(CGI.new))
77
+
78
+ class TestComposite < Minitest::Test
79
+ def setup
80
+ @composite = StubComposite.new(
81
+ [StubComposite2Model.new, StubCompositeModel.new],
82
+ StubCompositeSession.new
83
+ )
84
+ end
85
+
86
+ def test_to_html
87
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), @composite.to_html(CGI.new))
88
+ <TABLE cellspacing="0">
89
+ <TR><TD>Foo</TD></TR><TR><TD>Baz1</TD></TR><TR><TD>Baz2</TD></TR>
90
+ </TABLE>
91
+ EXP
92
+ end
74
93
  end
75
94
  end
@@ -21,7 +21,7 @@
21
21
  # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
22
22
  # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
23
23
  #
24
- # TestComponent -- htmlgrid -- 26.11.2002 -- hwyss@ywesee.com
24
+ # TestComponent -- htmlgrid -- 26.11.2002 -- hwyss@ywesee.com
25
25
 
26
26
  $: << File.expand_path("../lib", File.dirname(__FILE__))
27
27
  $: << File.expand_path("../ext", File.dirname(__FILE__))
@@ -30,9 +30,9 @@ require 'minitest/autorun'
30
30
  require 'htmlgrid/component'
31
31
 
32
32
  module HtmlGrid
33
- class Component
34
- attr_reader :model, :session, :container
35
- end
33
+ class Component
34
+ attr_reader :session, :container
35
+ end
36
36
  end
37
37
 
38
38
  class TestComponent < Minitest::Test
@@ -59,7 +59,7 @@ class TestComponent < Minitest::Test
59
59
  comp = HtmlGrid::Component.new("foo", "bar")
60
60
  assert_equal("foo", comp.model)
61
61
  assert_equal("bar", comp.session)
62
- assert_equal(nil, comp.container)
62
+ assert_nil(comp.container)
63
63
  assert_equal(false, comp.label?)
64
64
  comp.label = true
65
65
  assert_equal(true, comp.label?)
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # HtmlGrid -- HyperTextMarkupLanguage Framework
4
- # Copyright (C) 2003 ywesee - intellectual capital connected
3
+ # HtmlGrid -- HyperTextMarkupLanguage Framework
4
+ # Copyright (C) 2003 ywesee - intellectual capital connected
5
5
  # Andreas Schrafl, Benjamin Fay, Hannes Wyss, Markus Huggler
6
6
  #
7
7
  # This library is free software; you can redistribute it and/or
@@ -18,10 +18,10 @@
18
18
  # License along with this library; if not, write to the Free Software
19
19
  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
20
  #
21
- # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
22
- # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
21
+ # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
22
+ # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
23
23
  #
24
- # TestComposite -- htmlgrid -- 24.10.2002 -- hwyss@ywesee.com
24
+ # TestComposite -- htmlgrid -- 24.10.2002 -- hwyss@ywesee.com
25
25
 
26
26
  $: << File.expand_path('../lib', File.dirname(__FILE__))
27
27
  $: << File.dirname(__FILE__)
@@ -32,183 +32,236 @@ require 'htmlgrid/composite'
32
32
  require 'htmlgrid/inputtext'
33
33
  require 'htmlgrid/form'
34
34
  require 'htmlgrid/button'
35
+ require 'test_helper'
35
36
 
36
- class StubComposite < HtmlGrid::Composite
37
- attr_writer :container
38
- COMPONENTS = {
39
- [0,0,0] => :baz,
40
- [0,0,1] => :foo,
41
- [0,0,2] => :baz,
42
- [0,1,0] => :baz,
43
- [0,1,1] => :baz,
44
- }
45
- LABELS = true
46
- SYMBOL_MAP = {
47
- :bar => HtmlGrid::InputText,
48
- }
49
- attr_reader :model, :session
50
- public :resolve_offset, :labels?
51
- def init
52
- @barcount=0
53
- super
54
- end
55
- def foo(model, lookandfeel)
56
- "Foo"
57
- end
58
- def baz(model, lookandfeel)
59
- @barcount += 1
60
- "Baz#{@barcount}"
61
- end
62
- def back
63
- super
37
+ module CompositeTest
38
+ class StubComposite < HtmlGrid::Composite
39
+ attr_writer :container
40
+ COMPONENTS = {
41
+ [0, 0, 0] => :baz,
42
+ [0, 0, 1] => :foo,
43
+ [0, 0, 2] => :baz,
44
+ [0, 1, 0] => :baz,
45
+ [0, 1, 1] => :baz,
46
+ }
47
+ LABELS = true
48
+ SYMBOL_MAP = {
49
+ :bar => HtmlGrid::InputText,
50
+ }
51
+ attr_reader :model, :session
52
+ public :resolve_offset, :labels?
53
+ def init
54
+ @barcount=0
55
+ super
56
+ end
57
+ def foo(model, lookandfeel)
58
+ "Foo"
59
+ end
60
+ def baz(model, lookandfeel)
61
+ @barcount += 1
62
+ "Baz#{@barcount}"
63
+ end
64
+ def back
65
+ super
66
+ end
64
67
  end
65
- end
66
- class StubCompositeComponent < HtmlGrid::Component
67
- def to_html(context)
68
- context.a(@attributes) { 'brafoo' }
69
- end
70
- end
71
- class StubComposite2 < HtmlGrid::Composite
72
- COMPONENTS = {
73
- [0,0] => StubCompositeComponent,
74
- }
75
- end
76
- class StubComposite3 < StubComposite2
77
- COMPONENT_CSS_MAP = {[0,0,4,4]=>'standard'}
78
- end
79
- class StubComposite4 < StubComposite3
80
- CSS_MAP = {[0,0]=>'dradnats'}
81
- COMPONENT_CSS_MAP = {[0,0,4,4]=>'standard'}
82
- end
83
- class StubCompositeNoLabel < HtmlGrid::Composite
84
- LABELS = false
85
- COMPONENTS = {}
86
- public :labels?
87
- end
88
- class StubCompositeModel
89
- end
90
- class StubCompositeLookandfeel
91
- def event_url(one)
92
- return 'event_url'
68
+ class StubCompositeComponent < HtmlGrid::Component
69
+ def to_html(context)
70
+ context.a(@attributes) { 'brafoo' }
71
+ end
93
72
  end
94
- def attributes(key)
95
- {}
96
- end
97
- def lookup(key)
98
- end
99
- def base_url
100
- 'http://www.oddb.org/de/gcc'
101
- end
102
- end
103
- class StubCompositeSession
104
- def lookandfeel
105
- StubCompositeLookandfeel.new
106
- end
107
- def error(key)
108
- end
109
- end
110
- class StubCompositeForm < HtmlGrid::Form
111
- COMPONENTS = {
112
- [0,0] => StubComposite
113
- }
114
- EVENT = :foo
115
- end
116
- class StubCompositeColspan1 < HtmlGrid::Composite
117
- COMPONENTS = {}
118
- end
119
- class StubCompositeColspan2 < HtmlGrid::Composite
120
- COMPONENTS = {
121
- [0,0] => :foo,
122
- }
123
- end
124
- class StubCompositeColspan3 < HtmlGrid::Composite
125
- COMPONENTS = {
126
- [0,0] => :foo,
127
- [1,0] => :bar,
128
- }
129
- end
130
- class StubCompositeColspan4 < HtmlGrid::Composite
131
- COMPONENTS = {
132
- [0,0] => :foo,
133
- [2,0] => :bar,
134
- }
135
- end
73
+ class StubComposite2 < HtmlGrid::Composite
74
+ COMPONENTS = {
75
+ [0, 0] => StubCompositeComponent,
76
+ }
77
+ end
78
+ class StubComposite3 < StubComposite2
79
+ COMPONENT_CSS_MAP = {[0, 0, 4, 4] => 'standard'}
80
+ end
81
+ class StubComposite4 < StubComposite3
82
+ CSS_MAP = {[0, 0] => 'dradnats'}
83
+ COMPONENT_CSS_MAP = {[0, 0, 4, 4] => 'standard'}
84
+ end
85
+ class StubCompositeNoLabel < HtmlGrid::Composite
86
+ LABELS = false
87
+ COMPONENTS = {}
88
+ public :labels?
89
+ end
90
+ class StubCompositeModel
91
+ def qux
92
+ 'qux'
93
+ end
94
+ end
95
+ class StubCompositeLookandfeel
96
+ def event_url(one)
97
+ return 'event_url'
98
+ end
99
+ def attributes(key)
100
+ {}
101
+ end
102
+ def lookup(key)
103
+ end
104
+ def base_url
105
+ 'http://www.oddb.org/de/gcc'
106
+ end
107
+ end
108
+ class StubCompositeSession
109
+ def lookandfeel
110
+ StubCompositeLookandfeel.new
111
+ end
112
+ def error(key)
113
+ end
114
+ end
115
+
116
+ class StubCompositeSession2 < StubCompositeSession; end
136
117
 
137
- class TestComposite < Minitest::Test
138
- def setup
139
- @composite = StubComposite.new(StubCompositeModel.new, StubCompositeSession.new)
140
- end
141
- def test_create_method
142
- foo = nil
143
- foo = @composite.create(:foo, @composite.model)
144
- assert_equal("Foo", foo)
145
- end
146
- def test_create_symbol
147
- bar = nil
148
- bar = @composite.create(:bar, @composite.model)
149
- assert_equal(HtmlGrid::InputText, bar.class)
150
- end
151
- def test_full_colspan1
152
- composite = StubCompositeColspan1.new(StubCompositeModel.new, StubCompositeSession.new)
153
- composite.full_colspan
154
- assert_equal(nil, composite.full_colspan)
155
- end
156
- def test_full_colspan2
157
- composite = StubCompositeColspan2.new(StubCompositeModel.new, StubCompositeSession.new)
158
- composite.full_colspan
159
- assert_equal(nil, composite.full_colspan)
160
- end
161
- def test_full_colspan3
162
- composite = StubCompositeColspan3.new(StubCompositeModel.new, StubCompositeSession.new)
163
- composite.full_colspan
164
- assert_equal(2, composite.full_colspan)
165
- end
166
- def test_full_colspan4
167
- composite = StubCompositeColspan4.new(StubCompositeModel.new, StubCompositeSession.new)
168
- composite.full_colspan
169
- assert_equal(3, composite.full_colspan)
170
- end
171
- def test_labels1
172
- composite = StubCompositeNoLabel.new(StubCompositeModel.new, StubCompositeSession.new)
173
- assert_equal(false, composite.labels?)
174
- end
175
- def test_labels2
176
- assert_equal(true, @composite.labels?)
177
- end
178
- def test_to_html
179
- expected = '<TABLE cellspacing="0"><TR><TD>Baz1FooBaz2</TD></TR><TR><TD>Baz3Baz4</TD></TR></TABLE>'
180
- assert_equal(expected, @composite.to_html(CGI.new))
118
+ class StubCompositeForm < HtmlGrid::Form
119
+ COMPONENTS = {
120
+ [0, 0] => StubComposite
121
+ }
122
+ EVENT = :foo
123
+ end
124
+ class StubCompositeColspan1 < HtmlGrid::Composite
125
+ COMPONENTS = {}
181
126
  end
182
- def test_resolve_offset
183
- matrix = [1,2,3,4]
184
- assert_equal(matrix, @composite.resolve_offset(matrix))
185
- offset = [5,6]
186
- expected = [6,8,3,4]
187
- assert_equal(expected, @composite.resolve_offset(matrix, offset))
188
- end
189
- def test_event
190
- @composite.event()
191
- form = StubCompositeForm.new(@composite.model, @composite.session)
192
- @composite.container = form
193
- assert_equal(:foo, @composite.event())
194
- end
195
- def test_component_css_map
196
- composite = StubComposite2.new(StubCompositeModel.new, StubCompositeSession.new)
197
- expected = '<TABLE cellspacing="0"><TR><TD><A>brafoo</A></TD></TR></TABLE>'
198
- assert_equal(expected, composite.to_html(CGI.new))
199
- composite = StubComposite3.new(StubCompositeModel.new, StubCompositeSession.new)
200
- expected = '<TABLE cellspacing="0"><TR><TD><A class="standard">brafoo</A></TD></TR></TABLE>'
201
- assert_equal(expected, composite.to_html(CGI.new))
202
- composite = StubComposite4.new(StubCompositeModel.new, StubCompositeSession.new)
127
+ class StubCompositeColspan2 < HtmlGrid::Composite
128
+ COMPONENTS = {
129
+ [0, 0] => :foo,
130
+ }
203
131
  end
204
- def test_to_back
205
- if RUBY_VERSION.split(".").first.eql?('1')
206
- expected = "<INPUT type=\"button\" name=\"back\" onClick=\"document.location.href='event_url';\">"
207
- else
208
- # It looks like Ruby 2.x escapes the ' which is not strictly necessary
209
- expected = "<INPUT type=\"button\" name=\"back\" onClick=\"document.location.href=&#39;event_url&#39;;\">"
210
- end
211
- html = @composite.back().to_html(CGI.new)
212
- assert_equal(expected, html)
132
+ class StubCompositeColspan3 < HtmlGrid::Composite
133
+ COMPONENTS = {
134
+ [0, 0] => :foo,
135
+ [1, 0] => :bar,
136
+ }
137
+ end
138
+ class StubCompositeColspan4 < HtmlGrid::Composite
139
+ COMPONENTS = {
140
+ [0, 0] => :foo,
141
+ [2, 0] => :bar,
142
+ }
143
+ end
144
+
145
+ class TestComposite < Minitest::Test
146
+ def setup
147
+ @composite = StubComposite.new(
148
+ StubCompositeModel.new, StubCompositeSession.new)
149
+ end
150
+
151
+ def test_component_session_fallback_assignment_without_session_argment
152
+ StubComposite.component(StubComposite, :qux)
153
+ model = StubCompositeModel.new
154
+ session1 = StubCompositeSession.new
155
+ composite = StubComposite.new(model, session1)
156
+ # via instance variable (without argument)
157
+ composite = composite.compositetest_stubcomposite_qux(model)
158
+ assert_kind_of(StubCompositeSession, composite.session)
159
+ assert_equal(session1, composite.session)
160
+ # via argument
161
+ session2 = StubCompositeSession2.new
162
+ composite = composite.compositetest_stubcomposite_qux(model, session2)
163
+ assert_kind_of(StubCompositeSession2, composite.session)
164
+ assert_equal(session2, composite.session)
165
+ end
166
+
167
+ def test_create_method
168
+ foo = nil
169
+ foo = @composite.create(:foo, @composite.model)
170
+ assert_equal("Foo", foo)
171
+ end
172
+ def test_create_symbol
173
+ bar = nil
174
+ bar = @composite.create(:bar, @composite.model)
175
+ assert_equal(HtmlGrid::InputText, bar.class)
176
+ end
177
+ def test_full_colspan1
178
+ composite = StubCompositeColspan1.new(
179
+ StubCompositeModel.new, StubCompositeSession.new)
180
+ composite.full_colspan
181
+ assert_nil(composite.full_colspan)
182
+ end
183
+ def test_full_colspan2
184
+ composite = StubCompositeColspan2.new(
185
+ StubCompositeModel.new, StubCompositeSession.new)
186
+ composite.full_colspan
187
+ assert_nil(composite.full_colspan)
188
+ end
189
+ def test_full_colspan3
190
+ composite = StubCompositeColspan3.new(
191
+ StubCompositeModel.new, StubCompositeSession.new)
192
+ composite.full_colspan
193
+ assert_equal(2, composite.full_colspan)
194
+ end
195
+ def test_full_colspan4
196
+ composite = StubCompositeColspan4.new(
197
+ StubCompositeModel.new, StubCompositeSession.new)
198
+ composite.full_colspan
199
+ assert_equal(3, composite.full_colspan)
200
+ end
201
+ def test_labels1
202
+ composite = StubCompositeNoLabel.new(
203
+ StubCompositeModel.new, StubCompositeSession.new)
204
+ assert_equal(false, composite.labels?)
205
+ end
206
+ def test_labels2
207
+ assert_equal(true, @composite.labels?)
208
+ end
209
+ def test_to_html
210
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), @composite.to_html(CGI.new))
211
+ <TABLE cellspacing="0">
212
+ <TR><TD>Baz1FooBaz2</TD></TR><TR><TD>Baz3Baz4</TD></TR>
213
+ </TABLE>
214
+ EXP
215
+ end
216
+ def test_resolve_offset
217
+ matrix = [1,2,3,4]
218
+ assert_equal(matrix, @composite.resolve_offset(matrix))
219
+ offset = [5,6]
220
+ expected = [6,8,3,4]
221
+ assert_equal(expected, @composite.resolve_offset(matrix, offset))
222
+ end
223
+ def test_event
224
+ @composite.event
225
+ @composite.container = StubCompositeForm.new(
226
+ @composite.model, @composite.session)
227
+ assert_equal(:foo, @composite.event)
228
+ end
229
+ def test_component_css_map
230
+ table = StubComposite2.new(
231
+ StubCompositeModel.new, StubCompositeSession.new)
232
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), table.to_html(CGI.new))
233
+ <TABLE cellspacing="0">
234
+ <TR><TD><A>brafoo</A></TD></TR>
235
+ </TABLE>
236
+ EXP
237
+ table = StubComposite3.new(
238
+ StubCompositeModel.new, StubCompositeSession.new)
239
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), table.to_html(CGI.new))
240
+ <TABLE cellspacing="0">
241
+ <TR><TD><A class="standard">brafoo</A></TD></TR>
242
+ </TABLE>
243
+ EXP
244
+ table = StubComposite4.new(
245
+ StubCompositeModel.new, StubCompositeSession.new)
246
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), table.to_html(CGI.new))
247
+ <TABLE cellspacing=\"0\"><TR><TD class=\"dradnats\"><A class=\"standard\">brafoo</A></TD></TR></TABLE>
248
+ EXP
249
+ end
250
+ def test_to_back
251
+ if RUBY_VERSION.split(".").first.eql?('1')
252
+ expected = <<-EXP.gsub(/\n|^\s{10}/, '')
253
+ <INPUT type="button" name="back"
254
+ onClick="document.location.href='event_url';">
255
+ EXP
256
+ else
257
+ # It looks like Ruby 2.x escapes the ' which is not strictly necessary
258
+ expected = <<-EXP.gsub(/\n|^\s{10}/, '')
259
+ <INPUT type="button" name="back"
260
+ onClick="document.location.href=&#39;event_url&#39;;">
261
+ EXP
262
+ end
263
+ html = @composite.back().to_html(CGI.new)
264
+ assert_equal(expected, html)
265
+ end
213
266
  end
214
267
  end