htmlgrid 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
data/lib/htmlgrid/list.rb CHANGED
@@ -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
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
  module HtmlGrid
4
- VERSION = '1.1.1'
4
+ VERSION = '1.1.2'
5
5
  end
data/test/suite.rb CHANGED
@@ -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
  }
data/test/test_add_row.rb CHANGED
@@ -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
@@ -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
@@ -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,215 @@ 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
136
-
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))
73
+ class StubComposite2 < HtmlGrid::Composite
74
+ COMPONENTS = {
75
+ [0, 0] => StubCompositeComponent,
76
+ }
181
77
  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)
78
+ class StubComposite3 < StubComposite2
79
+ COMPONENT_CSS_MAP = {[0, 0, 4, 4] => 'standard'}
203
80
  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)
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
+ end
92
+ class StubCompositeLookandfeel
93
+ def event_url(one)
94
+ return 'event_url'
95
+ end
96
+ def attributes(key)
97
+ {}
98
+ end
99
+ def lookup(key)
100
+ end
101
+ def base_url
102
+ 'http://www.oddb.org/de/gcc'
103
+ end
104
+ end
105
+ class StubCompositeSession
106
+ def lookandfeel
107
+ StubCompositeLookandfeel.new
108
+ end
109
+ def error(key)
110
+ end
111
+ end
112
+ class StubCompositeForm < HtmlGrid::Form
113
+ COMPONENTS = {
114
+ [0, 0] => StubComposite
115
+ }
116
+ EVENT = :foo
117
+ end
118
+ class StubCompositeColspan1 < HtmlGrid::Composite
119
+ COMPONENTS = {}
120
+ end
121
+ class StubCompositeColspan2 < HtmlGrid::Composite
122
+ COMPONENTS = {
123
+ [0, 0] => :foo,
124
+ }
125
+ end
126
+ class StubCompositeColspan3 < HtmlGrid::Composite
127
+ COMPONENTS = {
128
+ [0, 0] => :foo,
129
+ [1, 0] => :bar,
130
+ }
131
+ end
132
+ class StubCompositeColspan4 < HtmlGrid::Composite
133
+ COMPONENTS = {
134
+ [0, 0] => :foo,
135
+ [2, 0] => :bar,
136
+ }
137
+ end
138
+
139
+ class TestComposite < Minitest::Test
140
+ def setup
141
+ @composite = StubComposite.new(
142
+ StubCompositeModel.new, StubCompositeSession.new)
143
+ end
144
+ def test_create_method
145
+ foo = nil
146
+ foo = @composite.create(:foo, @composite.model)
147
+ assert_equal("Foo", foo)
148
+ end
149
+ def test_create_symbol
150
+ bar = nil
151
+ bar = @composite.create(:bar, @composite.model)
152
+ assert_equal(HtmlGrid::InputText, bar.class)
153
+ end
154
+ def test_full_colspan1
155
+ composite = StubCompositeColspan1.new(
156
+ StubCompositeModel.new, StubCompositeSession.new)
157
+ composite.full_colspan
158
+ assert_equal(nil, composite.full_colspan)
159
+ end
160
+ def test_full_colspan2
161
+ composite = StubCompositeColspan2.new(
162
+ StubCompositeModel.new, StubCompositeSession.new)
163
+ composite.full_colspan
164
+ assert_equal(nil, composite.full_colspan)
165
+ end
166
+ def test_full_colspan3
167
+ composite = StubCompositeColspan3.new(
168
+ StubCompositeModel.new, StubCompositeSession.new)
169
+ composite.full_colspan
170
+ assert_equal(2, composite.full_colspan)
171
+ end
172
+ def test_full_colspan4
173
+ composite = StubCompositeColspan4.new(
174
+ StubCompositeModel.new, StubCompositeSession.new)
175
+ composite.full_colspan
176
+ assert_equal(3, composite.full_colspan)
177
+ end
178
+ def test_labels1
179
+ composite = StubCompositeNoLabel.new(
180
+ StubCompositeModel.new, StubCompositeSession.new)
181
+ assert_equal(false, composite.labels?)
182
+ end
183
+ def test_labels2
184
+ assert_equal(true, @composite.labels?)
185
+ end
186
+ def test_to_html
187
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), @composite.to_html(CGI.new))
188
+ <TABLE cellspacing="0">
189
+ <TR><TD>Baz1FooBaz2</TD></TR><TR><TD>Baz3Baz4</TD></TR>
190
+ </TABLE>
191
+ EXP
192
+ end
193
+ def test_resolve_offset
194
+ matrix = [1,2,3,4]
195
+ assert_equal(matrix, @composite.resolve_offset(matrix))
196
+ offset = [5,6]
197
+ expected = [6,8,3,4]
198
+ assert_equal(expected, @composite.resolve_offset(matrix, offset))
199
+ end
200
+ def test_event
201
+ @composite.event
202
+ @composite.container = StubCompositeForm.new(
203
+ @composite.model, @composite.session)
204
+ assert_equal(:foo, @composite.event)
205
+ end
206
+ def test_component_css_map
207
+ table = StubComposite2.new(
208
+ StubCompositeModel.new, StubCompositeSession.new)
209
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), table.to_html(CGI.new))
210
+ <TABLE cellspacing="0">
211
+ <TR><TD><A>brafoo</A></TD></TR>
212
+ </TABLE>
213
+ EXP
214
+ table = StubComposite3.new(
215
+ StubCompositeModel.new, StubCompositeSession.new)
216
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), table.to_html(CGI.new))
217
+ <TABLE cellspacing="0">
218
+ <TR><TD><A class="standard">brafoo</A></TD></TR>
219
+ </TABLE>
220
+ EXP
221
+ table = StubComposite4.new(
222
+ StubCompositeModel.new, StubCompositeSession.new)
223
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), table.to_html(CGI.new))
224
+ <TABLE cellspacing="0">
225
+ <TR><TD><A class="standard">brafoo</A></TD></TR>
226
+ </TABLE>
227
+ EXP
228
+ end
229
+ def test_to_back
230
+ if RUBY_VERSION.split(".").first.eql?('1')
231
+ expected = <<-EXP.gsub(/\n|^\s{10}/, '')
232
+ <INPUT type="button" name="back"
233
+ onClick="document.location.href='event_url';">
234
+ EXP
235
+ else
236
+ # It looks like Ruby 2.x escapes the ' which is not strictly necessary
237
+ expected = <<-EXP.gsub(/\n|^\s{10}/, '')
238
+ <INPUT type="button" name="back"
239
+ onClick="document.location.href=&#39;event_url&#39;;">
240
+ EXP
241
+ end
242
+ html = @composite.back().to_html(CGI.new)
243
+ assert_equal(expected, html)
244
+ end
213
245
  end
214
246
  end