htmlgrid 1.1.7 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/htmlgrid/booleanvalue.rb +14 -14
  3. data/lib/htmlgrid/button.rb +9 -9
  4. data/lib/htmlgrid/centeredcomposite.rb +21 -20
  5. data/lib/htmlgrid/component.rb +214 -197
  6. data/lib/htmlgrid/composite.rb +332 -301
  7. data/lib/htmlgrid/datevalue.rb +12 -12
  8. data/lib/htmlgrid/div.rb +9 -9
  9. data/lib/htmlgrid/divcomposite.rb +44 -43
  10. data/lib/htmlgrid/divform.rb +8 -8
  11. data/lib/htmlgrid/divlist.rb +17 -19
  12. data/lib/htmlgrid/divtemplate.rb +6 -6
  13. data/lib/htmlgrid/dojotoolkit.rb +54 -48
  14. data/lib/htmlgrid/errormessage.rb +47 -43
  15. data/lib/htmlgrid/form.rb +70 -62
  16. data/lib/htmlgrid/formlist.rb +14 -14
  17. data/lib/htmlgrid/grid.rb +111 -67
  18. data/lib/htmlgrid/image.rb +17 -16
  19. data/lib/htmlgrid/infomessage.rb +15 -14
  20. data/lib/htmlgrid/input.rb +34 -32
  21. data/lib/htmlgrid/inputcheckbox.rb +13 -13
  22. data/lib/htmlgrid/inputcurrency.rb +9 -9
  23. data/lib/htmlgrid/inputdate.rb +11 -11
  24. data/lib/htmlgrid/inputfile.rb +13 -12
  25. data/lib/htmlgrid/inputradio.rb +9 -9
  26. data/lib/htmlgrid/inputtext.rb +10 -10
  27. data/lib/htmlgrid/javascript.rb +17 -16
  28. data/lib/htmlgrid/label.rb +53 -49
  29. data/lib/htmlgrid/labeltext.rb +8 -8
  30. data/lib/htmlgrid/link.rb +31 -27
  31. data/lib/htmlgrid/list.rb +121 -110
  32. data/lib/htmlgrid/namedcomponent.rb +28 -25
  33. data/lib/htmlgrid/pass.rb +11 -11
  34. data/lib/htmlgrid/passthru.rb +20 -17
  35. data/lib/htmlgrid/popuplink.rb +41 -39
  36. data/lib/htmlgrid/reset.rb +8 -8
  37. data/lib/htmlgrid/richtext.rb +22 -20
  38. data/lib/htmlgrid/select.rb +28 -26
  39. data/lib/htmlgrid/span.rb +9 -9
  40. data/lib/htmlgrid/spancomposite.rb +18 -18
  41. data/lib/htmlgrid/spanlist.rb +9 -9
  42. data/lib/htmlgrid/staticinput.rb +14 -13
  43. data/lib/htmlgrid/submit.rb +9 -9
  44. data/lib/htmlgrid/template.rb +121 -105
  45. data/lib/htmlgrid/text.rb +9 -9
  46. data/lib/htmlgrid/textarea.rb +19 -17
  47. data/lib/htmlgrid/ulcomposite.rb +22 -22
  48. data/lib/htmlgrid/ullist.rb +9 -9
  49. data/lib/htmlgrid/urllink.rb +38 -36
  50. data/lib/htmlgrid/value.rb +9 -9
  51. data/lib/htmlgrid/version.rb +2 -2
  52. data/test/stub/cgi.rb +10 -7
  53. data/test/suite.rb +3 -3
  54. data/test/test_add_row.rb +12 -13
  55. data/test/test_component.rb +141 -91
  56. data/test/test_composite.rb +85 -46
  57. data/test/test_datevalue.rb +28 -24
  58. data/test/test_divlist.rb +126 -0
  59. data/test/test_dojotoolkit.rb +41 -26
  60. data/test/test_form.rb +89 -73
  61. data/test/test_formlist.rb +77 -65
  62. data/test/test_grid.rb +256 -208
  63. data/test/test_input.rb +37 -31
  64. data/test/test_interaction_list.rb +106 -70
  65. data/test/test_label.rb +91 -77
  66. data/test/test_list.rb +110 -95
  67. data/test/test_select.rb +35 -30
  68. data/test/test_template.rb +66 -55
  69. data/test/test_text.rb +36 -31
  70. metadata +17 -4
  71. data/TooltipDialog.txt +0 -73
  72. data/interaction_no_inline.txt +0 -1216
data/test/test_input.rb CHANGED
@@ -21,51 +21,57 @@
21
21
  # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
22
22
  # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
23
23
  #
24
- # TestInput -- htmlgrid -- 18.11.2002 -- hwyss@ywesee.com
24
+ # TestInput -- htmlgrid -- 18.11.2002 -- hwyss@ywesee.com
25
25
 
26
26
  $LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
27
27
  $LOAD_PATH << File.dirname(__FILE__)
28
28
 
29
- require 'minitest/autorun'
30
- require 'stub/cgi'
31
- require 'htmlgrid/button'
32
- require 'htmlgrid/inputcurrency'
29
+ require "minitest/autorun"
30
+ require "stub/cgi"
31
+ require "htmlgrid/button"
32
+ require "htmlgrid/inputcurrency"
33
33
 
34
34
  class StubInputLookandfeel
35
- def attributes(key)
36
- {
37
- "bar" => "roz",
38
- }
39
- end
40
- def lookup(key)
41
- 'Foo'
42
- end
43
- def lookandfeel
44
- self
45
- end
46
- def format_price(price)
47
- sprintf('%.2f', price.to_f/100.0) if price.to_i > 0
48
- end
35
+ def attributes(key)
36
+ {
37
+ "bar" => "roz"
38
+ }
39
+ end
40
+
41
+ def lookup(key)
42
+ "Foo"
43
+ end
44
+
45
+ def lookandfeel
46
+ self
47
+ end
48
+
49
+ def format_price(price)
50
+ sprintf("%.2f", price.to_f / 100.0) if price.to_i > 0
51
+ end
49
52
  end
53
+
50
54
  class StubInputModel
51
- def foo
52
- 1234
53
- end
55
+ def foo
56
+ 1234
57
+ end
54
58
  end
55
59
 
56
60
  class TestInput < Minitest::Test
57
- def test_input
58
- input = HtmlGrid::Input.new(:foo, nil, StubInputLookandfeel.new)
61
+ def test_input
62
+ input = HtmlGrid::Input.new(:foo, nil, StubInputLookandfeel.new)
59
63
  assert_equal('<INPUT bar="roz" name="foo" value="">', input.to_html(CGI.new))
60
- end
61
- def test_button
62
- input = HtmlGrid::Button.new(:foo, nil, StubInputLookandfeel.new)
64
+ end
65
+
66
+ def test_button
67
+ input = HtmlGrid::Button.new(:foo, nil, StubInputLookandfeel.new)
63
68
  assert_equal('<INPUT bar="roz" value="Foo" type="button" name="foo">', input.to_html(CGI.new))
64
- end
69
+ end
65
70
  end
71
+
66
72
  class TestInputCurrency < Minitest::Test
67
- def test_to_html
68
- input = HtmlGrid::InputCurrency.new(:foo, StubInputModel.new, StubInputLookandfeel.new)
73
+ def test_to_html
74
+ input = HtmlGrid::InputCurrency.new(:foo, StubInputModel.new, StubInputLookandfeel.new)
69
75
  assert_equal('<INPUT bar="roz" name="foo" value="12.34" type="text">', input.to_html(CGI.new))
70
- end
76
+ end
71
77
  end
@@ -1,20 +1,20 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
2
+
3
3
  # A little bit more elaborated test of the list, where we add different lines
4
4
  # Constructing can be a little tricky.
5
5
  # Also shows one can choose a differnt background color for a line
6
6
  # Added by Niklaus Giger who had to some improvemnts for the interaction_chooser
7
- $: << File.expand_path('../lib', File.dirname(__FILE__))
7
+ $: << File.expand_path("../lib", File.dirname(__FILE__))
8
8
  $: << File.dirname(__FILE__)
9
9
 
10
- require 'minitest'
11
- require 'minitest/autorun'
12
- require 'stub/cgi'
13
- require 'htmlgrid/composite'
14
- require 'htmlgrid/inputtext'
15
- require 'htmlgrid/form'
16
- require 'htmlgrid/list'
17
- require 'htmlgrid/div'
10
+ require "minitest"
11
+ require "minitest/autorun"
12
+ require "stub/cgi"
13
+ require "htmlgrid/composite"
14
+ require "htmlgrid/inputtext"
15
+ require "htmlgrid/form"
16
+ require "htmlgrid/list"
17
+ require "htmlgrid/div"
18
18
 
19
19
  module InteractionTest
20
20
  class StubComposite < HtmlGrid::Composite
@@ -24,130 +24,151 @@ module InteractionTest
24
24
  [0, 0, 1] => :foo,
25
25
  [0, 0, 2] => :baz,
26
26
  [0, 1, 0] => :baz,
27
- [0, 1, 1] => :baz,
27
+ [0, 1, 1] => :baz
28
28
  }
29
29
  LABELS = true
30
30
  SYMBOL_MAP = {
31
- :bar => HtmlGrid::InputText,
31
+ bar: HtmlGrid::InputText
32
32
  }
33
33
  attr_reader :model, :session
34
34
  public :resolve_offset, :labels?
35
35
  def initialize(first, second, third = nil)
36
36
  super(first, second)
37
37
  end
38
+
38
39
  def init
39
- @barcount=0
40
+ @barcount = 0
40
41
  super
41
42
  end
42
- def foo(model, session=@session)
43
+
44
+ def foo(model, session = @session)
43
45
  "Foo"
44
46
  end
45
- def baz(model, session=@session)
47
+
48
+ def baz(model, session = @session)
46
49
  @barcount += 1
47
50
  "Baz#{@barcount}"
48
51
  end
49
52
  end
53
+
50
54
  class StubCompositeComponent < HtmlGrid::Component
51
55
  def to_html(context)
52
- context.a(@attributes) { 'brafoo' }
56
+ context.a(@attributes) { "brafoo" }
53
57
  end
54
58
  end
59
+
55
60
  class StubComposite2 < HtmlGrid::Composite
56
61
  COMPONENTS = {
57
- [0, 0] => StubCompositeComponent,
62
+ [0, 0] => StubCompositeComponent
58
63
  }
59
64
  end
65
+
60
66
  class StubComposite3 < StubComposite2
61
- COMPONENT_CSS_MAP = {[0, 0, 4, 4] => 'standard'}
67
+ COMPONENT_CSS_MAP = {[0, 0, 4, 4] => "standard"}
62
68
  end
69
+
63
70
  class StubComposite4 < StubComposite3
64
- CSS_MAP = {[0, 0] => 'dradnats'}
65
- COMPONENT_CSS_MAP = {[0, 0, 4, 4] => 'standard'}
71
+ CSS_MAP = {[0, 0] => "dradnats"}
72
+ COMPONENT_CSS_MAP = {[0, 0, 4, 4] => "standard"}
66
73
  end
74
+
67
75
  class StubCompositeNoLabel < HtmlGrid::Composite
68
76
  LABELS = false
69
77
  COMPONENTS = {}
70
78
  public :labels?
71
79
  end
80
+
72
81
  class StubCompositeModel
73
82
  end
83
+
74
84
  class StubCompositeLookandfeel
75
85
  def attributes(key)
76
86
  {}
77
87
  end
88
+
78
89
  def lookup(key)
79
90
  end
91
+
80
92
  def base_url
81
- 'http://www.oddb.org/de/gcc'
93
+ "http://www.oddb.org/de/gcc"
82
94
  end
83
95
  end
96
+
84
97
  class StubCompositeSession
85
98
  attr_accessor :event
86
99
  def lookandfeel
87
100
  StubCompositeLookandfeel.new
88
101
  end
102
+
89
103
  def error(key)
90
104
  end
105
+
91
106
  def user_agent
92
- 'user_agent'
107
+ "user_agent"
93
108
  end
94
109
  end
110
+
95
111
  class StubCompositeForm < HtmlGrid::Form
96
112
  COMPONENTS = {
97
113
  [0, 0] => StubComposite
98
114
  }
99
115
  EVENT = :foo
100
116
  end
117
+
101
118
  class StubCompositeColspan1 < HtmlGrid::Composite
102
119
  COMPONENTS = {}
103
120
  end
121
+
104
122
  class StubCompositeColspan2 < HtmlGrid::Composite
105
123
  COMPONENTS = {
106
- [0, 0] => :foo,
124
+ [0, 0] => :foo
107
125
  }
108
126
  end
127
+
109
128
  class StubCompositeColspan3 < HtmlGrid::Composite
110
129
  COMPONENTS = {
111
130
  [0, 0] => :foo,
112
- [1, 0] => :bar,
131
+ [1, 0] => :bar
113
132
  }
114
133
  end
134
+
115
135
  class StubCompositeColspan4 < HtmlGrid::Composite
116
136
  COMPONENTS = {
117
137
  [0, 0] => :foo,
118
- [2, 0] => :bar,
138
+ [2, 0] => :bar
119
139
  }
120
140
  end
121
141
 
122
142
  class StubInteractionChooserDrugList < HtmlGrid::List
123
143
  attr_reader :model, :value
124
144
  COMPONENTS = {
125
- [0, 0] => :info_drug,
145
+ [0, 0] => :info_drug
126
146
  }
127
147
  CSS_MAP = {
128
- [0, 0] => 'css.info',
148
+ [0, 0] => "css.info"
129
149
  }
130
150
  SORT_HEADER = false
131
151
  SORT_DEFAULT = :foo
132
- def initialize(models, session=@session)
152
+ def initialize(models, session = @session)
133
153
  @drugs = nil
134
154
  super # must come first or it will overwrite @value
135
155
  @value = []
136
- models.each{ |model|
156
+ models.each { |model|
137
157
  @value << StubInteractionChooserDrug.new(model, session)
138
158
  }
139
159
  end
160
+
140
161
  def to_html(context)
141
162
  div = HtmlGrid::Div.new(@model, @session, self)
142
- if @drugs and !@drugs.empty?
163
+ if @drugs && !@drugs.empty?
143
164
  link = HtmlGrid::Link.new(:delete, @model, @session, self)
144
- link.href = @lookandfeel._event_url(:delete_all, [])
165
+ link.href = @lookandfeel._event_url(:delete_all, [])
145
166
  link.value = @lookandfeel.lookup(:interaction_chooser_delete_all)
146
- link.css_class = 'list'
167
+ link.css_class = "list"
147
168
  div.value = link
148
169
  end
149
- div.set_attribute('id', 'drugs')
150
- @value << div unless @value.find{ |v| v.attributes['id'].eql?('drugs') }
170
+ div.set_attribute("id", "drugs")
171
+ @value << div unless @value.find { |v| v.attributes["id"].eql?("drugs") }
151
172
  super
152
173
  end
153
174
  end
@@ -157,11 +178,13 @@ module InteractionTest
157
178
  def initialize(foo)
158
179
  @foo = foo
159
180
  end
181
+
160
182
  def fachinfo
161
183
  @foo
162
184
  end
185
+
163
186
  def drug
164
- 'Drug'
187
+ "Drug"
165
188
  end
166
189
  end
167
190
 
@@ -169,87 +192,100 @@ module InteractionTest
169
192
  COMPONENTS = {
170
193
  [0, 0] => :fachinfo,
171
194
  [1, 0] => :atc,
172
- [2, 0] => :delete,
195
+ [2, 0] => :delete
173
196
  }
174
197
  CSS_MAP = {
175
- [0, 0] => 'small',
176
- [1, 0] => 'interaction-atc',
177
- [2, 0] => 'small',
198
+ [0, 0] => "small",
199
+ [1, 0] => "interaction-atc",
200
+ [2, 0] => "small"
178
201
  }
179
202
  HTML_ATTRIBUTES = {
180
- 'style' => 'background-color:greenyellow',
203
+ "style" => "background-color:greenyellow"
181
204
  }
182
205
  def init
183
206
  super
184
207
  end
185
- def fachinfo(model, session=@session)
208
+
209
+ def fachinfo(model, session = @session)
186
210
  "fachinfo-#{model.foo}"
187
211
  end
188
- def atc(model, session=@session)
189
- 'atc'
212
+
213
+ def atc(model, session = @session)
214
+ "atc"
190
215
  end
191
- def delete(model, session=@session)
192
- 'delete'
216
+
217
+ def delete(model, session = @session)
218
+ "delete"
193
219
  end
194
220
  end
221
+
195
222
  class StubInteractionChooserDrug < HtmlGrid::Composite
196
223
  COMPONENTS = {
197
- }
224
+ }
198
225
  CSS_MAP = {}
199
- CSS_CLASS = 'composite'
226
+ CSS_CLASS = "composite"
200
227
  @@barcode ||= 0
201
228
  def init
202
229
  @@barcode += 1
203
- components.store([0,0], :header_info)
204
- css_map.store([0,0], 'subheading')
230
+ components.store([0, 0], :header_info)
231
+ css_map.store([0, 0], "subheading")
205
232
  1.upto(@@barcode) { |idx|
206
- components.store([0,idx], :text_info)
233
+ components.store([0, idx], :text_info)
207
234
  }
208
- @attributes.store('id', 'drugs_' + @@barcode.to_s)
235
+ @attributes.store("id", "drugs_" + @@barcode.to_s)
209
236
  super
210
237
  end
211
- def header_info(model, session=@session)
238
+
239
+ def header_info(model, session = @session)
212
240
  StubInteractionChooserDrugHeader.new(model, session, self)
213
241
  end
214
- def text_info(model, session=@session)
242
+
243
+ def text_info(model, session = @session)
215
244
  "interaction for #{model.foo}"
216
245
  end
217
246
  end
247
+
218
248
  class TestComposite < Minitest::Test
219
249
  def setup
220
250
  @composite = StubComposite.new(
221
- StubCompositeModel.new, StubCompositeSession.new)
251
+ StubCompositeModel.new, StubCompositeSession.new
252
+ )
222
253
  end
254
+
223
255
  def test_create_method
224
- foo = nil
225
256
  foo = @composite.create(:foo, @composite.model)
226
257
  assert_equal("Foo", foo)
227
258
  end
259
+
228
260
  def test_to_html
229
- assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), @composite.to_html(CGI.new))
261
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ""), @composite.to_html(CGI.new))
230
262
  <TABLE cellspacing="0">
231
263
  <TR><TD>Baz1FooBaz2</TD></TR><TR><TD>Baz3Baz4</TD></TR>
232
264
  </TABLE>
233
265
  EXP
234
266
  end
267
+
235
268
  def test_component_css_map
236
269
  table = StubComposite2.new(
237
- StubCompositeModel.new, StubCompositeSession.new)
238
- assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), table.to_html(CGI.new))
270
+ StubCompositeModel.new, StubCompositeSession.new
271
+ )
272
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ""), table.to_html(CGI.new))
239
273
  <TABLE cellspacing="0">
240
274
  <TR><TD><A>brafoo</A></TD></TR>
241
275
  </TABLE>
242
276
  EXP
243
277
  table = StubComposite3.new(
244
- StubCompositeModel.new, StubCompositeSession.new)
245
- assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), table.to_html(CGI.new))
278
+ StubCompositeModel.new, StubCompositeSession.new
279
+ )
280
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ""), table.to_html(CGI.new))
246
281
  <TABLE cellspacing="0">
247
282
  <TR><TD><A class="standard">brafoo</A></TD></TR>
248
283
  </TABLE>
249
284
  EXP
250
285
  table = StubComposite4.new(
251
- StubCompositeModel.new, StubCompositeSession.new)
252
- assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), table.to_html(CGI.new))
286
+ StubCompositeModel.new, StubCompositeSession.new
287
+ )
288
+ assert_equal(<<-EXP.gsub(/\n|^\s*/, ""), table.to_html(CGI.new))
253
289
  <TABLE cellspacing=\"0\"><TR><TD class=\"dradnats\"><A class=\"standard\">brafoo</A></TD></TR></TABLE>
254
290
  EXP
255
291
  end
@@ -258,11 +294,12 @@ module InteractionTest
258
294
  # Spruce up lines in expectation
259
295
  def test_interaction_list_to_html
260
296
  models = [
261
- StubDrugModel.new('Aspirin'),
262
- StubDrugModel.new('Marcoumar'),
297
+ StubDrugModel.new("Aspirin"),
298
+ StubDrugModel.new("Marcoumar")
263
299
  ]
264
300
  composite = StubInteractionChooserDrugList.new(
265
- models, StubCompositeSession.new)
301
+ models, StubCompositeSession.new
302
+ )
266
303
  expected = [
267
304
  '<TABLE cellspacing="0" class="composite" id="drugs_1">',
268
305
  '<TR><TD class="subheading"><TABLE cellspacing="0" style="background-color:greenyellow">',
@@ -270,17 +307,16 @@ module InteractionTest
270
307
  '<TR><TD>interaction for Aspirin</TD></TR></TABLE> <TABLE cellspacing="0" class="composite" id="drugs_2">',
271
308
  '<TR><TD class="subheading"><TABLE cellspacing="0" style="background-color:greenyellow">',
272
309
  '<TR><TD class="small">fachinfo-Marcoumar</TD><TD class="interaction-atc">atc</TD><TD class="small">delete</TD></TR></TABLE></TD></TR>',
273
- '<TR><TD>interaction for Marcoumar</TD></TR>',
310
+ "<TR><TD>interaction for Marcoumar</TD></TR>",
274
311
  '<TR><TD>interaction for Marcoumar</TD></TR></TABLE> <DIV id="drugs"></DIV><TABLE cellspacing="0">',
275
- '<TR><TH>&nbsp;</TH></TR>',
312
+ "<TR><TH>&nbsp;</TH></TR>",
276
313
  '<TR><TD class="css.info">&nbsp;</TD></TR>',
277
- '<TR><TD class="css.info-bg">&nbsp;</TD></TR></TABLE>',
314
+ '<TR><TD class="css.info-bg">&nbsp;</TD></TR></TABLE>'
278
315
  ]
279
316
  html = composite.to_html(CGI.new)
280
317
  expected.each_with_index do |line, idx|
281
- assert(html.index(line), "#{idx}: missing #{line} in #{html}")
318
+ assert(html.index(line), "#{idx}: missing #{line} in #{html}")
282
319
  end
283
320
  end
284
321
  end
285
322
  end
286
-