htmlgrid 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
2
+
3
3
  #
4
4
  # HtmlGrid -- HyperTextMarkupLanguage Framework
5
5
  # Copyright (C) 2003 ywesee - intellectual capital connected
@@ -22,14 +22,14 @@
22
22
  # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
23
23
  # htmlgrid@ywesee.com, www.ywesee.com
24
24
  #
25
- # LabelText -- oddb -- 22.07.2003 -- hwyss@ywesee.com
25
+ # LabelText -- oddb -- 22.07.2003 -- hwyss@ywesee.com
26
26
 
27
- require 'htmlgrid/text'
27
+ require "htmlgrid/text"
28
28
 
29
29
  module HtmlGrid
30
- class LabelText < Text
31
- def to_html(context)
32
- context.label { super }
33
- end
34
- end
30
+ class LabelText < Text
31
+ def to_html(context)
32
+ context.label { super }
33
+ end
34
+ end
35
35
  end
data/lib/htmlgrid/link.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
2
+
3
3
  #
4
4
  # HtmlGrid -- HyperTextMarkupLanguage Framework
5
5
  # Copyright (C) 2003 ywesee - intellectual capital connected
@@ -22,33 +22,37 @@
22
22
  # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
23
23
  # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
24
24
  #
25
- # Link -- htmlgrid -- 19.11.2002 -- hwyss@ywesee.com
25
+ # Link -- htmlgrid -- 19.11.2002 -- hwyss@ywesee.com
26
26
 
27
- require 'htmlgrid/namedcomponent'
27
+ require "htmlgrid/namedcomponent"
28
28
 
29
29
  module HtmlGrid
30
- class Link < NamedComponent
31
- def init
32
- super
33
- @value = @lookandfeel.lookup(@name)
34
- end
35
- def href
36
- @attributes['href']
37
- end
38
- def href=(url)
39
- @attributes['href'] = url
40
- end
41
- def target=(trg)
42
- @attributes['target'] = trg
43
- end
44
- def to_html(context)
45
- context.a(@attributes) {
46
- if(@value.respond_to?(:to_html))
47
- @value.to_html(context).force_encoding('utf-8')
48
- else
49
- super
50
- end
51
- } << dynamic_html(context)
52
- end
53
- end
30
+ class Link < NamedComponent
31
+ def init
32
+ super
33
+ @value = @lookandfeel.lookup(@name)
34
+ end
35
+
36
+ def href
37
+ @attributes["href"]
38
+ end
39
+
40
+ def href=(url)
41
+ @attributes["href"] = url
42
+ end
43
+
44
+ def target=(trg)
45
+ @attributes["target"] = trg
46
+ end
47
+
48
+ def to_html(context)
49
+ context.a(@attributes) {
50
+ if @value.respond_to?(:to_html)
51
+ @value.to_html(context).force_encoding("utf-8")
52
+ else
53
+ super
54
+ end
55
+ } << dynamic_html(context)
56
+ end
57
+ end
54
58
  end
data/lib/htmlgrid/list.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
2
+
3
3
  #
4
4
  # HtmlGrid -- HyperTextMarkupLanguage Framework
5
5
  # Copyright (C) 2003 ywesee - intellectual capital connected
@@ -22,138 +22,149 @@
22
22
  # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
23
23
  # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
24
24
  #
25
- # List -- htmlgrid -- 03.03.2003 -- hwyss@ywesee.com
25
+ # List -- htmlgrid -- 03.03.2003 -- hwyss@ywesee.com
26
26
 
27
- require 'htmlgrid/composite'
28
- require 'htmlgrid/link'
29
- require 'htmlgrid/value'
27
+ require "htmlgrid/composite"
28
+ require "htmlgrid/link"
29
+ require "htmlgrid/value"
30
30
 
31
31
  module HtmlGrid
32
- class List < Composite
32
+ class List < Composite
33
33
  BACKGROUND_ROW = nil
34
- BACKGROUND_SUFFIX = '-bg'
35
- CSS_HEAD_MAP = {}
36
- DEFAULT_CLASS = Value
37
- DEFAULT_HEAD_CLASS = nil
38
- EMPTY_LIST = false
39
- EMPTY_LIST_KEY = :empty_list
40
- OFFSET_STEP = [0,1]
41
- OMIT_HEADER = false
42
- OMIT_HEAD_TAG = false
43
- SORT_DEFAULT = :to_s
44
- SORT_HEADER = true
45
- SORT_REVERSE = false
46
- STRIPED_BG = true
47
- def compose(model=@model, offset=[0,0])
48
- unless (self::class::OMIT_HEADER)
49
- offset = compose_header(offset)
50
- end
51
- if(model.empty?)
52
- offset = compose_empty_list(offset) unless (self::class::EMPTY_LIST)
53
- else
54
- offset = compose_list(model, offset)
55
- end
56
- compose_footer(offset)
57
- end
58
- def compose_footer(offset=[0,0])
59
- end
60
- def compose_empty_list(offset, klass='list')
61
- fill_row(offset, self::class::EMPTY_LIST_KEY, klass)
62
- end
63
- def compose_list(model=@model, offset=[0,0])
64
- bg_flag = false
65
- model.each_with_index { |mdl, idx|
66
- @list_index = idx
67
- _compose(mdl, offset, bg_flag)
68
- #compose_components(mdl, offset)
69
- #compose_css(offset, resolve_suffix(mdl, bg_flag))
70
- #compose_colspan(offset)
71
- if(rcss = row_css(mdl, bg_flag))
72
- @grid.set_row_attributes({'class' => rcss}, offset.at(1),
73
- self::class::OFFSET_STEP.at(1))
74
- end
75
- offset = resolve_offset(offset, self::class::OFFSET_STEP)
76
- bg_flag = !bg_flag if self::class::STRIPED_BG
77
- }
78
- offset
79
- end
80
- def compose_header(offset=[0,0])
81
- step = if(defined?(self::class::HEAD_OFFSET_STEP))
82
- self::class::HEAD_OFFSET_STEP
83
- else
84
- self::class::OFFSET_STEP
85
- end
86
- ystep = step.at(1)
87
- components.each { |matrix, component|
88
- key = lookandfeel_key(component)
89
- header_key = 'th_' << key.to_s
90
- if(txt = @lookandfeel.lookup(header_key))
91
- if(self::class::SORT_HEADER)
92
- @grid.add(sort_link(header_key, matrix, component), *matrix)
93
- else
94
- @grid.add(txt, *matrix)
95
- end
96
- end
97
- if((cls = css_head_map[matrix]) \
98
- || (cls = self::class::DEFAULT_HEAD_CLASS))
99
- @grid.add_attribute('class', cls, *matrix)
100
- #link.attributes['class'] = cls
101
- end
102
- unless(self::class::OMIT_HEAD_TAG || matrix.at(1) >= ystep)
103
- @grid.add_tag('TH', *matrix)
104
- end
105
- if(title = @lookandfeel.lookup(header_key + '_title'))
106
- @grid.add_attribute('title', title, *matrix)
107
- end
108
- }
109
- #span = full_colspan || 1
110
- resolve_offset(offset, step)
111
- end
112
- def css_head_map
113
- @css_head_map ||= self::class::CSS_HEAD_MAP.dup
114
- end
34
+ BACKGROUND_SUFFIX = "-bg"
35
+ CSS_HEAD_MAP = {}
36
+ DEFAULT_CLASS = Value
37
+ DEFAULT_HEAD_CLASS = nil
38
+ EMPTY_LIST = false
39
+ EMPTY_LIST_KEY = :empty_list
40
+ OFFSET_STEP = [0, 1]
41
+ OMIT_HEADER = false
42
+ OMIT_HEAD_TAG = false
43
+ SORT_DEFAULT = :to_s
44
+ SORT_HEADER = true
45
+ SORT_REVERSE = false
46
+ STRIPED_BG = true
47
+ def compose(model = @model, offset = [0, 0])
48
+ unless self.class::OMIT_HEADER
49
+ offset = compose_header(offset)
50
+ end
51
+ if model.empty?
52
+ offset = compose_empty_list(offset) unless self.class::EMPTY_LIST
53
+ else
54
+ offset = compose_list(model, offset)
55
+ end
56
+ compose_footer(offset)
57
+ end
58
+
59
+ def compose_footer(offset = [0, 0])
60
+ end
61
+
62
+ def compose_empty_list(offset, klass = "list")
63
+ fill_row(offset, self.class::EMPTY_LIST_KEY, klass)
64
+ end
65
+
66
+ def compose_list(model = @model, offset = [0, 0])
67
+ bg_flag = false
68
+ model.each_with_index { |mdl, idx|
69
+ @list_index = idx
70
+ _compose(mdl, offset, bg_flag)
71
+ # compose_components(mdl, offset)
72
+ # compose_css(offset, resolve_suffix(mdl, bg_flag))
73
+ # compose_colspan(offset)
74
+ if (rcss = row_css(mdl, bg_flag))
75
+ @grid.set_row_attributes({"class" => rcss}, offset.at(1),
76
+ self.class::OFFSET_STEP.at(1))
77
+ end
78
+ offset = resolve_offset(offset, self.class::OFFSET_STEP)
79
+ bg_flag = !bg_flag if self.class::STRIPED_BG
80
+ }
81
+ offset
82
+ end
83
+
84
+ def compose_header(offset = [0, 0])
85
+ step = if defined?(self.class::HEAD_OFFSET_STEP)
86
+ self.class::HEAD_OFFSET_STEP
87
+ else
88
+ self.class::OFFSET_STEP
89
+ end
90
+ ystep = step.at(1)
91
+ components.each { |matrix, component|
92
+ key = lookandfeel_key(component)
93
+ header_key = "th_" << key.to_s
94
+ if (txt = @lookandfeel.lookup(header_key))
95
+ if self.class::SORT_HEADER
96
+ @grid.add(sort_link(header_key, matrix, component), *matrix)
97
+ else
98
+ @grid.add(txt, *matrix)
99
+ end
100
+ end
101
+ if (cls = css_head_map[matrix]) \
102
+ || (cls = self.class::DEFAULT_HEAD_CLASS)
103
+ @grid.add_attribute("class", cls, *matrix)
104
+ # link.attributes['class'] = cls
105
+ end
106
+ unless self.class::OMIT_HEAD_TAG || matrix.at(1) >= ystep
107
+ @grid.add_tag("TH", *matrix)
108
+ end
109
+ if (title = @lookandfeel.lookup(header_key + "_title"))
110
+ @grid.add_attribute("title", title, *matrix)
111
+ end
112
+ }
113
+ # span = full_colspan || 1
114
+ resolve_offset(offset, step)
115
+ end
116
+
117
+ def css_head_map
118
+ @css_head_map ||= self.class::CSS_HEAD_MAP.dup
119
+ end
120
+
115
121
  def fill_row(offset, key, klass)
116
122
  @grid.add(@lookandfeel.lookup(key), *offset)
117
- @grid.add_attribute('class', klass, *offset)
123
+ @grid.add_attribute("class", klass, *offset)
118
124
  @grid.set_colspan(*offset)
119
- resolve_offset(offset, self::class::OFFSET_STEP)
125
+ resolve_offset(offset, self.class::OFFSET_STEP)
126
+ end
127
+
128
+ private
129
+
130
+ def init
131
+ @model ||= []
132
+ @index = 0
133
+ sort_model
134
+ if self.class::SORT_REVERSE && (@session.event != :sort)
135
+ @model = @model.reverse
136
+ end
137
+ super
120
138
  end
121
- private
122
- def init
123
- @model ||= []
124
- @index = 0
125
- sort_model()
126
- if(self::class::SORT_REVERSE && (@session.event != :sort))
127
- @model = @model.reverse
128
- end
129
- super
130
- end
139
+
131
140
  def row_css(model, bg_flag)
132
- self::class::BACKGROUND_ROW if(bg_flag)
141
+ self.class::BACKGROUND_ROW if bg_flag
133
142
  end
143
+
134
144
  def sort_link(header_key, matrix, component)
135
145
  link = Link.new(header_key, @model, @session, self)
136
146
  args = {
137
- 'sortvalue' => component.to_s,
147
+ "sortvalue" => component.to_s
138
148
  }
139
- link.attributes['href'] = @lookandfeel.event_url(:sort, args)
140
- if((cls = css_head_map[matrix]) \
141
- || (cls = self::class::DEFAULT_HEAD_CLASS))
142
- link.attributes['class'] = cls
149
+ link.attributes["href"] = @lookandfeel.event_url(:sort, args)
150
+ if (cls = css_head_map[matrix]) \
151
+ || (cls = self.class::DEFAULT_HEAD_CLASS)
152
+ link.attributes["class"] = cls
143
153
  end
144
154
  link
145
155
  end
156
+
146
157
  def sort_model
147
- block = self::class::SORT_DEFAULT
158
+ block = self.class::SORT_DEFAULT
148
159
  if block && (@session.event != :sort)
149
160
  begin
150
161
  if block == :self
151
162
  @model = @model.sort
152
163
  else
153
164
  unless block.is_a?(Proc)
154
- block = Proc.new { |item|
165
+ block = proc { |item|
155
166
  begin
156
- item.send(self::class::SORT_DEFAULT)
167
+ item.send(self.class::SORT_DEFAULT)
157
168
  rescue RuntimeError
158
169
  item.to_s
159
170
  end
@@ -161,10 +172,10 @@ module HtmlGrid
161
172
  end
162
173
  @model = @model.sort_by(&block)
163
174
  end
164
- rescue StandardError => e
175
+ rescue => e
165
176
  puts "could not sort: #{e.message}"
166
177
  end
167
178
  end
168
179
  end
169
- end
180
+ end
170
181
  end
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
2
+
3
3
  #
4
4
  # HtmlGrid -- HyperTextMarkupLanguage Framework
5
5
  # Copyright (C) 2003 ywesee - intellectual capital connected
@@ -22,31 +22,34 @@
22
22
  # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
23
23
  # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
24
24
  #
25
- # NamedComponent -- htmlgrid -- 19.11.2002 -- hwyss@ywesee.com
25
+ # NamedComponent -- htmlgrid -- 19.11.2002 -- hwyss@ywesee.com
26
26
 
27
- require 'htmlgrid/component'
27
+ require "htmlgrid/component"
28
28
 
29
29
  module HtmlGrid
30
- class NamedComponent < Component
31
- attr_reader :name
32
- def initialize(name, model, session, container=nil)
33
- @name = name
34
- super(model, session, container)
35
- @attributes['name'] = @name.to_s
36
- end
37
- def init
38
- super
39
- @attributes.update(@lookandfeel.attributes(@name)) if @lookandfeel
40
- end
41
- def data_origin
42
- if(@model.respond_to?(:data_origin))
43
- @model.data_origin(@name)
44
- end
45
- end
46
- def error?
47
- if(@model.respond_to?(:error?))
48
- @model.error?(@name)
49
- end
50
- end
51
- end
30
+ class NamedComponent < Component
31
+ attr_reader :name
32
+ def initialize(name, model, session, container = nil)
33
+ @name = name
34
+ super(model, session, container)
35
+ @attributes["name"] = @name.to_s
36
+ end
37
+
38
+ def init
39
+ super
40
+ @attributes.update(@lookandfeel.attributes(@name)) if @lookandfeel
41
+ end
42
+
43
+ def data_origin
44
+ if @model.respond_to?(:data_origin)
45
+ @model.data_origin(@name)
46
+ end
47
+ end
48
+
49
+ def error?
50
+ if @model.respond_to?(:error?)
51
+ @model.error?(@name)
52
+ end
53
+ end
54
+ end
52
55
  end
data/lib/htmlgrid/pass.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
2
+
3
3
  #
4
4
  # HtmlGrid -- HyperTextMarkupLanguage Framework
5
5
  # Copyright (C) 2003 ywesee - intellectual capital connected
@@ -22,17 +22,17 @@
22
22
  # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
23
23
  # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
24
24
  #
25
- # Pass -- htmlgrid -- 03.03.2003 -- hwyss@ywesee.com
25
+ # Pass -- htmlgrid -- 03.03.2003 -- hwyss@ywesee.com
26
26
 
27
- require 'htmlgrid/input'
27
+ require "htmlgrid/input"
28
28
 
29
29
  module HtmlGrid
30
- class Pass < Input
31
- LABEL = true
32
- def init
33
- super
34
- @attributes['type'] = 'password'
35
- @attributes.delete('value')
36
- end
37
- end
30
+ class Pass < Input
31
+ LABEL = true
32
+ def init
33
+ super
34
+ @attributes["type"] = "password"
35
+ @attributes.delete("value")
36
+ end
37
+ end
38
38
  end