htmlgrid 1.2.0 → 1.2.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.
Files changed (70) 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 -199
  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 +120 -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 +121 -100
  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 -27
  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 +63 -55
  69. data/test/test_text.rb +36 -31
  70. metadata +17 -2
@@ -21,40 +21,44 @@
21
21
  # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
22
22
  # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
23
23
  #
24
- # TestDateValue -- htmlgrid -- 10.03.2003 -- hwyss@ywesee.com
24
+ # TestDateValue -- htmlgrid -- 10.03.2003 -- hwyss@ywesee.com
25
25
 
26
26
  $: << File.expand_path("../lib", File.dirname(__FILE__))
27
27
 
28
- require 'minitest/autorun'
29
- require 'htmlgrid/datevalue'
30
- require 'stub/cgi'
31
- require 'date'
28
+ require "minitest/autorun"
29
+ require "htmlgrid/datevalue"
30
+ require "stub/cgi"
31
+ require "date"
32
32
 
33
33
  class StubDateLookandfeel
34
- def lookup(key)
35
- '%d.%m.%Y'
36
- end
37
- def attributes(key)
38
- {}
39
- end
34
+ def lookup(key)
35
+ "%d.%m.%Y"
36
+ end
37
+
38
+ def attributes(key)
39
+ {}
40
+ end
40
41
  end
42
+
41
43
  class StubDateSession
42
- def lookandfeel
43
- StubDateLookandfeel.new
44
- end
44
+ def lookandfeel
45
+ StubDateLookandfeel.new
46
+ end
45
47
  end
48
+
46
49
  class StubDateProvider
47
- def date
48
- Date.new(2002,1,1)
49
- end
50
+ def date
51
+ Date.new(2002, 1, 1)
52
+ end
50
53
  end
51
54
 
52
55
  class TestDateValue < Minitest::Test
53
- def setup
54
- @component = HtmlGrid::DateValue.new(:date, StubDateProvider.new,
55
- StubDateSession.new)
56
- end
57
- def test_formatted
58
- assert_equal('01.01.2002', @component.to_html(CGI.new))
59
- end
56
+ def setup
57
+ @component = HtmlGrid::DateValue.new(:date, StubDateProvider.new,
58
+ StubDateSession.new)
59
+ end
60
+
61
+ def test_formatted
62
+ assert_equal("01.01.2002", @component.to_html(CGI.new))
63
+ end
60
64
  end
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # HtmlGrid -- HyperTextMarkupLanguage Framework
4
+ # Copyright (C) 2003 ywesee - intellectual capital connected
5
+ # Andreas Schrafl, Benjamin Fay, Hannes Wyss, Markus Huggler
6
+ #
7
+ # This library is free software; you can redistribute it and/or
8
+ # modify it under the terms of the GNU Lesser General Public
9
+ # License as published by the Free Software Foundation; either
10
+ # version 2.1 of the License, or (at your option) any later version.
11
+ #
12
+ # This library is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public
18
+ # License along with this library; if not, write to the Free Software
19
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ #
21
+ # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
22
+ # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
23
+ #
24
+ # TestList -- htmlgrid -- 03.03.2003 -- hwyss@ywesee.com
25
+
26
+ $: << File.dirname(__FILE__)
27
+ $: << File.expand_path("../lib", File.dirname(__FILE__))
28
+
29
+ require "minitest/autorun"
30
+ require "htmlgrid/divlist"
31
+ require "stub/cgi"
32
+ require "test_helper"
33
+
34
+ module HtmlGrid
35
+ class DivList < DivComposite
36
+ attr_reader :grid
37
+ end
38
+ end
39
+
40
+ class StubDivList < HtmlGrid::DivList
41
+ attr_reader :model
42
+ COMPONENTS = {
43
+ [0, 0] => :jaguar,
44
+ [1, 0] => :panther
45
+ }
46
+ CSS_MAP = {
47
+ [0, 0] => "flecken",
48
+ [1, 0] => "schwarz"
49
+ }
50
+ SORT_HEADER = false
51
+ SORT_DEFAULT = :foo
52
+ end
53
+
54
+ class StubDivListLookandfeel
55
+ def lookup(key)
56
+ key
57
+ end
58
+
59
+ def attributes(key)
60
+ {}
61
+ end
62
+ end
63
+
64
+ class StubDivListSession
65
+ attr_accessor :event
66
+ def lookandfeel
67
+ StubDivListLookandfeel.new
68
+ end
69
+ end
70
+
71
+ class StubDivListModel
72
+ attr_reader :foo
73
+ def initialize(foo)
74
+ @foo = foo
75
+ end
76
+
77
+ def jaguar
78
+ "Jaguar"
79
+ end
80
+
81
+ def panther
82
+ "Panther"
83
+ end
84
+ end
85
+
86
+ class StubDivListEmpty
87
+ attr_reader :foo
88
+ def initialize(foo)
89
+ @foo = foo
90
+ end
91
+ end
92
+
93
+ class TestDivList < Minitest::Test
94
+ def setup
95
+ model = [
96
+ StubDivListModel.new(3),
97
+ StubDivListModel.new(2),
98
+ StubDivListModel.new(4),
99
+ StubDivListModel.new(1),
100
+ StubDivListModel.new(nil)
101
+ ]
102
+ @list = StubDivList.new(model, StubDivListSession.new)
103
+ end
104
+
105
+ def test_nil_robust
106
+ list = StubDivList.new(nil, StubDivListSession.new)
107
+ assert_equal("", list.to_html(CGI.new))
108
+ end
109
+
110
+ def test_to_html
111
+ expected = "<DIV>JaguarPanther</DIV><DIV>JaguarPanther</DIV><DIV>JaguarPanther</DIV><DIV>JaguarPanther</DIV><DIV>JaguarPanther</DIV>"
112
+ assert_equal(expected, @list.to_html(CGI.new))
113
+ end
114
+
115
+ def test_nil_robust_to_html
116
+ list = StubDivList.new([nil], StubDivListSession.new)
117
+ expected = "<DIV></DIV>"
118
+ assert_equal(expected, list.to_html(CGI.new))
119
+ end
120
+
121
+ def test_nil_robust_to_html2
122
+ list = StubDivList.new([], StubDivListSession.new)
123
+ expected = ""
124
+ assert_equal(expected, list.to_html(CGI.new))
125
+ end
126
+ end
@@ -22,94 +22,107 @@
22
22
  # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
23
23
  #
24
24
 
25
- $: << File.expand_path('../lib', File.dirname(__FILE__))
25
+ $: << File.expand_path("../lib", File.dirname(__FILE__))
26
26
  $: << File.dirname(__FILE__)
27
27
 
28
- require 'minitest/autorun'
29
- require 'stub/cgi'
30
- require 'htmlgrid/template'
31
- require 'htmlgrid/dojotoolkit'
32
- require 'test_helper'
33
- require 'flexmock/minitest'
34
- require 'sbsm/lookandfeel'
28
+ require "minitest/autorun"
29
+ require "stub/cgi"
30
+ require "htmlgrid/template"
31
+ require "htmlgrid/dojotoolkit"
32
+ require "test_helper"
33
+ require "flexmock/minitest"
34
+ require "sbsm/lookandfeel"
35
35
 
36
36
  class TestDojotoolkit < Minitest::Test
37
37
  class StubAttributeComponent < HtmlGrid::Component
38
- HTML_ATTRIBUTES = { "key" => "val" }
38
+ HTML_ATTRIBUTES = {"key" => "val"}
39
39
  end
40
+
40
41
  class StubInitComponent < HtmlGrid::Component
41
42
  attr_reader :init_called
42
43
  def init
43
44
  @init_called = true
44
45
  end
45
46
  end
47
+
46
48
  class StubLabelComponent < HtmlGrid::Component
47
49
  LABEL = true
48
50
  end
51
+
49
52
  class StubContainer
50
53
  attr_accessor :onsubmit
51
54
  end
55
+
52
56
  def setup
53
57
  @component = HtmlGrid::Component.new(nil, nil)
54
- @session = flexmock('session') do |s|
55
- s.should_receive(:user_agent).and_return('user_agent').by_default
58
+ @session = flexmock("session") do |s|
59
+ s.should_receive(:user_agent).and_return("user_agent").by_default
56
60
  end
57
61
  @cgi = CGI.new
58
62
  end
63
+
59
64
  def test_dynamic_html
60
65
  comp = HtmlGrid::Component.new("foo", @session)
61
- comp.dojo_tooltip = 'my_tooltip'
66
+ comp.dojo_tooltip = "my_tooltip"
62
67
  assert_equal("foo", comp.model)
63
68
  assert_equal(false, comp.label?)
64
- result= comp.dynamic_html(@cgi)
69
+ result = comp.dynamic_html(@cgi)
65
70
  assert(/href="my_tooltip"/.match(result))
66
71
  end
72
+
67
73
  def test_dynamic_html_with_msie
68
- @session.should_receive(:user_agent).and_return('MSIE 4')
74
+ @session.should_receive(:user_agent).and_return("MSIE 4")
69
75
  comp = HtmlGrid::Component.new("foo", @session)
70
- comp.dojo_tooltip = 'my_tooltip'
76
+ comp.dojo_tooltip = "my_tooltip"
71
77
  assert_equal("foo", comp.model)
72
78
  assert_equal(false, comp.label?)
73
- result= comp.dynamic_html(@cgi)
79
+ result = comp.dynamic_html(@cgi)
74
80
  assert(/href="my_tooltip"/.match(result))
75
81
  end
76
82
  end
83
+
77
84
  class StubTemplateLookandfeel < SBSM::Lookandfeel
78
85
  RESOURCES = {
79
- :css => "test.css"
86
+ css: "test.css"
80
87
  }
81
88
  DICTIONARIES = {
82
89
  "de" => {
83
- :html_title => "Test",
90
+ html_title: "Test"
84
91
  }
85
92
  }
86
93
  def lookandfeel
87
94
  self
88
95
  end
89
96
  end
97
+
90
98
  class StubTemplateSession
91
99
  def flavor
92
100
  "gcc"
93
101
  end
102
+
94
103
  def language
95
104
  "de"
96
105
  end
106
+
97
107
  def http_protocol
98
- 'http'
108
+ "http"
99
109
  end
110
+
100
111
  def server_name
101
112
  "testserver.com"
102
113
  end
114
+
103
115
  def server_port
104
- '80'
116
+ "80"
105
117
  end
106
- alias :default_language :language
118
+ alias_method :default_language, :language
107
119
  end
120
+
108
121
  class PublicTemplate < HtmlGrid::Template
109
122
  include HtmlGrid::DojoToolkit::DojoTemplate
110
123
  COMPONENTS = {}
111
124
  def dynamic_html_headers(context)
112
- headers = super
125
+ _headers = super
113
126
  end
114
127
  end
115
128
 
@@ -118,16 +131,17 @@ class TestTemplate < Minitest::Test
118
131
  lookandfeel = StubTemplateLookandfeel.new(StubTemplateSession.new)
119
132
  @template = PublicTemplate.new(nil, lookandfeel, nil)
120
133
  end
134
+
121
135
  def test_dynamic_html_headers
122
136
  @cgi = CGI.new
123
- result = @template.to_html(@cgi)
124
- @session = flexmock('session')
137
+ _result = @template.to_html(@cgi)
138
+ @session = flexmock("session")
125
139
  comp = HtmlGrid::Component.new("foo", @session)
126
- comp.dojo_tooltip = 'my_tooltip'
140
+ comp.dojo_tooltip = "my_tooltip"
127
141
  assert_equal("foo", comp.model)
128
142
  assert_equal(false, comp.label?)
129
- result= comp.to_html(@cgi)
130
- skip 'tooltip test does not work'
143
+ result = comp.to_html(@cgi)
144
+ skip "tooltip test does not work"
131
145
  assert(/href="my_tooltip"/.match(result))
132
146
  end
133
147
  end
data/test/test_form.rb CHANGED
@@ -21,104 +21,120 @@
21
21
  # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
22
22
  # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
23
23
  #
24
- # TestForm -- htmlgrid -- 25.11.2002 -- hwyss@ywesee.com
24
+ # TestForm -- htmlgrid -- 25.11.2002 -- hwyss@ywesee.com
25
25
 
26
26
  $: << File.dirname(__FILE__)
27
27
  $: << File.expand_path("../lib", File.dirname(__FILE__))
28
28
 
29
- require 'minitest/autorun'
30
- require 'htmlgrid/form'
31
- require 'stub/cgi'
29
+ require "minitest/autorun"
30
+ require "htmlgrid/form"
31
+ require "stub/cgi"
32
32
 
33
33
  class StubFormModel; end
34
+
34
35
  class StubFormLookandfeel
35
- def attributes(key)
36
- {}
37
- end
38
- def base_url
39
- 'http://test.oddb.org/de/gcc'
40
- end
41
- def flavor
42
- 'gcc'
43
- end
44
- def language
45
- 'de'
46
- end
47
- def lookup(key)
48
- 'Submit-Value'
49
- end
50
- def lookandfeel
51
- self
52
- end
53
- def state
54
- 0
55
- end
36
+ def attributes(key)
37
+ {}
38
+ end
39
+
40
+ def base_url
41
+ "http://test.oddb.org/de/gcc"
42
+ end
43
+
44
+ def flavor
45
+ "gcc"
46
+ end
47
+
48
+ def language
49
+ "de"
50
+ end
51
+
52
+ def lookup(key)
53
+ "Submit-Value"
54
+ end
55
+
56
+ def lookandfeel
57
+ self
58
+ end
59
+
60
+ def state
61
+ 0
62
+ end
56
63
  end
64
+
57
65
  class StubFormComponent < HtmlGrid::Component
58
- def init
59
- self.onsubmit = 'submitted'
60
- end
66
+ def init
67
+ self.onsubmit = "submitted"
68
+ end
61
69
  end
70
+
62
71
  class Form < HtmlGrid::Form
63
- EVENT = :foo
64
- COMPONENTS = {}
65
- public :submit
72
+ EVENT = :foo
73
+ COMPONENTS = {}
74
+ public :submit
66
75
  end
76
+
67
77
  class StubForm2 < HtmlGrid::Form
68
- EVENT = :foo
69
- COMPONENTS = {
70
- [0,0] => StubFormComponent,
71
- }
78
+ EVENT = :foo
79
+ COMPONENTS = {
80
+ [0, 0] => StubFormComponent
81
+ }
72
82
  end
83
+
73
84
  class StubFormMultiPart < HtmlGrid::Form
74
- EVENT = :foo
75
- COMPONENTS = {}
76
- TAG_METHOD = :multipart_form
85
+ EVENT = :foo
86
+ COMPONENTS = {}
87
+ TAG_METHOD = :multipart_form
77
88
  end
78
89
 
79
90
  class TestForm < Minitest::Test
80
- def setup
81
- @model = StubFormModel.new
82
- @lookandfeel = StubFormLookandfeel.new
83
- @form = Form.new(@model, @lookandfeel)
84
- end
85
- def test_event
86
- assert_equal(:foo, @form.event)
87
- end
88
- def test_multipart
89
- form = StubFormMultiPart.new(@model, @lookandfeel)
90
- result = form.to_html(CGI.new)
91
+ def setup
92
+ @model = StubFormModel.new
93
+ @lookandfeel = StubFormLookandfeel.new
94
+ @form = Form.new(@model, @lookandfeel)
95
+ end
96
+
97
+ def test_event
98
+ assert_equal(:foo, @form.event)
99
+ end
100
+
101
+ def test_multipart
102
+ form = StubFormMultiPart.new(@model, @lookandfeel)
103
+ result = form.to_html(CGI.new)
91
104
  expected = '<FORM NAME="stdform" METHOD="POST" ACTION="http://test.oddb.org/de/gcc" ACCEPT-CHARSET="UTF-8" ENCTYPE="multipart/form-data">'
92
105
  assert_equal(0, result.index(expected), "expected\n#{result}\nto start with\n#{expected}")
93
- end
94
- def test_to_html
95
- result = @form.to_html(CGI.new)
106
+ end
107
+
108
+ def test_to_html
109
+ result = @form.to_html(CGI.new)
96
110
  expected = [
97
111
  '<INPUT TYPE="hidden" NAME="flavor" VALUE="gcc">',
98
112
  '<INPUT TYPE="hidden" NAME="language" VALUE="de">',
99
113
  '<INPUT NAME="event" ID="event" VALUE="foo" TYPE="hidden">',
100
- '<INPUT TYPE="hidden" NAME="state_id" VALUE="1">',
114
+ '<INPUT TYPE="hidden" NAME="state_id" VALUE="1">'
101
115
  ]
102
- expected.each_with_index { |line, idx|
103
- assert(result.index(line), "#{idx}: missing #{line}\n in #{result}")
104
- }
105
- end
106
- def test_submit
116
+ expected.each_with_index { |line, idx|
117
+ assert(result.index(line), "#{idx}: missing #{line}\n in #{result}")
118
+ }
119
+ end
120
+
121
+ def test_submit
107
122
  html = @form.submit(@model, @lookandfeel).to_html(CGI.new)
108
123
  expected = '<INPUT value="Submit-Value" type="submit" name="foo">'
109
- assert_equal(expected, html)
110
- end
111
- def test_onsubmit
112
- @form.onsubmit = 'submitted'
113
- expected = 'onSubmit="submitted"'
114
- result = /<FORM[^>]+>/.match(@form.to_html(CGI.new))[0]
115
- assert(result.index(expected), "missing:\n#{expected}\nin:\n#{result}")
116
- end
117
- def test_onsubmit_init
118
- form = nil
119
- form = StubForm2.new(@model, @lookandfeel)
120
- expected = 'onSubmit="submitted"'
121
- result = /<FORM[^>]+>/.match(form.to_html(CGI.new))[0]
122
- assert(result.index(expected), "missing:\n#{expected}\nin:\n#{result}")
123
- end
124
+ assert_equal(expected, html)
125
+ end
126
+
127
+ def test_onsubmit
128
+ @form.onsubmit = "submitted"
129
+ expected = 'onSubmit="submitted"'
130
+ result = /<FORM[^>]+>/.match(@form.to_html(CGI.new))[0]
131
+ assert(result.index(expected), "missing:\n#{expected}\nin:\n#{result}")
132
+ end
133
+
134
+ def test_onsubmit_init
135
+ form = StubForm2.new(@model, @lookandfeel)
136
+ expected = 'onSubmit="submitted"'
137
+ result = /<FORM[^>]+>/.match(form.to_html(CGI.new))[0]
138
+ assert(result.index(expected), "missing:\n#{expected}\nin:\n#{result}")
139
+ end
124
140
  end