htmlgrid 1.1.1 → 1.1.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c5d30addff4506799b90228f01a9c910f6231967
4
- data.tar.gz: d96e8a7d27da7aab4acaf1458a334bbf89c76af2
2
+ SHA256:
3
+ metadata.gz: 499db7822b7a9628ffc8a755339c9498e727b60711b38c3433bf62340919dbcc
4
+ data.tar.gz: a742bdfd63e8a2bfe70d52b0912b68b3372194f182edaa9030f4db3b05034c48
5
5
  SHA512:
6
- metadata.gz: 7be2249769ff2f267ff89af97188e897c89e87d79403e71cb24658f315cf09d25211f756db822aec048da2ecf6fdc166c74a82b1c734b570b0cae68bec642754
7
- data.tar.gz: b6995921b53ae767df96a8fabdd97e3d7de0396e1a5a3626e88e7ed7d5259c9c84cd97de5e1f54ec26c00b3e7898499fa17f242cf31fb60fef9d9f7e98f86a8a
6
+ metadata.gz: d95e0f3b698b69bf8e3aaa9a8f84b2d79e28428e28b357512bfb74860b1dba3134b458fc9c7fbd62843ae570f228f3f8408bf0a033bd3b0e56c3de07284f5e08
7
+ data.tar.gz: 759170973e867985a62c8a1155d11dbcead9cafcade750f8d9089e1843544b8a6f04018741ec4dd9a1c8b1aff0f787700dcb194e4004303c7a60bb87d68a34e0
@@ -2,11 +2,10 @@
2
2
  .travis.yml
3
3
  COPYING
4
4
  Gemfile
5
- Gemfile.lock
6
5
  History.txt
7
6
  LICENCE.txt
8
7
  Manifest.txt
9
- README.textile
8
+ README.md
10
9
  Rakefile
11
10
  ext/htmlgrid/MANIFEST
12
11
  ext/htmlgrid/extconf.rb
@@ -65,7 +64,6 @@ lib/htmlgrid/ulcomposite.rb
65
64
  lib/htmlgrid/ullist.rb
66
65
  lib/htmlgrid/urllink.rb
67
66
  lib/htmlgrid/value.rb
68
- test/rebuild.rb
69
67
  test/stub/cgi.rb
70
68
  test/test_component.rb
71
69
  test/test_composite.rb
@@ -79,5 +77,6 @@ test/test_list.rb
79
77
  test/test_select.rb
80
78
  test/test_template.rb
81
79
  test/test_text.rb
80
+ test/test_helper.rb
82
81
  usage-en.txt
83
82
  widget/Tooltip.js
@@ -22,8 +22,8 @@
22
22
  # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
23
23
  # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
24
24
  #
25
- # HtmlGrid::Component -- htmlgrid -- 23.12.2012 -- mhatakeyama@ywesee.com
26
- # HtmlGrid::Component -- htmlgrid -- 23.10.2002 -- hwyss@ywesee.com
25
+ # HtmlGrid::Component -- htmlgrid -- 23.12.2012 -- mhatakeyama@ywesee.com
26
+ # HtmlGrid::Component -- htmlgrid -- 23.10.2002 -- hwyss@ywesee.com
27
27
  #++
28
28
 
29
29
  module HtmlGrid
@@ -72,7 +72,7 @@ module HtmlGrid
72
72
  83 => "Sigma", 115 => "sigma",
73
73
  84 => "Tau", 116 => "tau",
74
74
  85 => "Upsilon", 117 => "upsilon",
75
- 86 => "sigmaf",
75
+ 86 => "sigmaf",
76
76
  87 => "Omega", 119 => "omega",
77
77
  88 => "Xi", 120 => "xi",
78
78
  89 => "Psi", 121 => "psi",
@@ -163,7 +163,7 @@ module HtmlGrid
163
163
  end
164
164
  # escape '&', '<' and '>' characters in txt
165
165
  def escape(txt)
166
- @@html_entities.inject(txt.to_s.dup) { |str, map|
166
+ @@html_entities.inject(txt.to_s.dup) { |str, map|
167
167
  char, entity = map
168
168
  str.gsub!(char, '&' << entity << ';')
169
169
  str
@@ -213,8 +213,8 @@ module HtmlGrid
213
213
  def tabindex=(tab)
214
214
  @attributes.store('tabIndex', tab.to_s)
215
215
  end
216
- def to_html(context)
217
- _to_html(context, @value).to_s.force_encoding('utf-8')
216
+ def to_html(context)
217
+ _to_html(context, @value).to_s.encode('utf-8')
218
218
  end
219
219
  @@nl2br_ptrn = /(\r\n)|(\n)|(\r)/
220
220
  def _to_html(context, value=@value)
@@ -223,7 +223,7 @@ module HtmlGrid
223
223
  elsif(value.respond_to?(:to_html))
224
224
  value.to_html(context).to_s.force_encoding('utf-8')
225
225
  else
226
- value.to_s.gsub(@@nl2br_ptrn, '<br>')
226
+ value =CGI.unescape(value) if value && value.is_a?(String)
227
227
  end
228
228
  end
229
229
  private
@@ -51,6 +51,21 @@ module HtmlGrid
51
51
  CSS_ID = nil
52
52
  DEFAULT_CLASS = Value
53
53
  LOOKANDFEEL_MAP = {}
54
+
55
+ def self.component(klass, key, name=nil)
56
+ methname = klass.to_s.downcase.gsub('::', '_') << '_' << key.to_s
57
+ define_method(methname) { |*args|
58
+ model, session = args
59
+ args = [model.send(key), session || @session, self]
60
+ if(name)
61
+ args.unshift(name)
62
+ lookandfeel_map.store(methname.to_sym, name.to_sym)
63
+ end
64
+ klass.new(*args)
65
+ }
66
+ methname.to_sym
67
+ end
68
+
54
69
  def init
55
70
  super
56
71
  setup_grid()
@@ -102,19 +117,6 @@ module HtmlGrid
102
117
  def symbol_map
103
118
  @symbol_map ||= self::class::SYMBOL_MAP.dup
104
119
  end
105
- def AbstractComposite.component(klass, key, name=nil)
106
- methname = klass.to_s.downcase.gsub('::', '_') << '_' << key.to_s
107
- define_method(methname) { |*args|
108
- model, session = args
109
- args = [model.send(key), @session, self]
110
- if(name)
111
- args.unshift(name)
112
- lookandfeel_map.store(methname.to_sym, name.to_sym)
113
- end
114
- klass.new(*args)
115
- }
116
- methname.to_sym
117
- end
118
120
  end
119
121
  class TagComposite < AbstractComposite
120
122
  def compose(model=@model)
@@ -5,12 +5,12 @@
5
5
 
6
6
  require 'htmlgrid/component'
7
7
  require 'htmlgrid/div'
8
+ require 'htmlgrid/template'
8
9
 
9
10
  module HtmlGrid
10
11
  class Component
11
12
  @@msie_ptrn = /MSIE\s*(\d)/
12
13
  attr_accessor :dojo_tooltip
13
- # DOJO_VERSION >= 1.7.0 only (removed old version support)
14
14
  def dojo_tag(widget, args={}, inner_html='')
15
15
  div = HtmlGrid::Div.new(@model, @session, self)
16
16
  div.set_attribute('data-dojo-type', widget)
@@ -38,24 +38,22 @@ module HtmlGrid
38
38
  def dynamic_html(context)
39
39
  html = ''
40
40
  attrs = {
41
- # NOTE:
42
- # DOJO >= 1.8 has support for type name separated by '/'
43
- # but, <= 1.7 must be separated with '.'
44
- 'data-dojo-type' => 'dijit.Tooltip',
45
- 'data-dojo-props' => "connectId:'#{css_id}'",
41
+ 'data-dojo-type' => 'dijit/TooltipDialog',
42
+ 'data-dojo-props' => "connectId:#{css_id}",
46
43
  'id' => "#{css_id}_widget",
47
44
  'style' => 'display: none',
48
45
  }
49
- unless match = @@msie_ptrn.match(@session.user_agent) \
46
+ unless (match = @@msie_ptrn.match(@session.user_agent)) \
50
47
  && match[1].to_i < 7
51
48
  attrs.update({
52
49
  'toggle' => 'fade',
53
50
  'toggleDuration' => '500',
54
51
  })
55
52
  end
53
+ @dojo_tooltip ||= nil
56
54
  if @dojo_tooltip.is_a?(String)
57
55
  if @dojo_tooltip !~ /^http/ # e.g. javascript
58
- attrs.store('href', "'#@dojo_tooltip'")
56
+ attrs.store('href', "#@dojo_tooltip")
59
57
  else
60
58
  attrs.store('href', @dojo_tooltip)
61
59
  end
@@ -65,9 +63,7 @@ module HtmlGrid
65
63
  html << @dojo_tooltip.to_html(context).force_encoding('utf-8')
66
64
  end
67
65
  unless html.empty? || dojo_parse_on_load
68
- html << context.script('type' => 'text/javascript') {
69
- "dojoConfig.searchIds.push('#{css_id}')"
70
- }
66
+ html << context.script('type' => 'text/javascript') { "dojoConfig.searchIds.push('#{css_id}')" }
71
67
  end
72
68
  # call original dynamic_html
73
69
  dojo_dynamic_html(context) << html
@@ -76,7 +72,7 @@ module HtmlGrid
76
72
  end
77
73
  module DojoToolkit
78
74
  module DojoTemplate
79
- DOJO_DEBUG = false
75
+ DOJO_DEBUG = true
80
76
  DOJO_BACK_BUTTON = false
81
77
  DOJO_ENCODING = nil
82
78
  DOJO_PARSE_ON_LOAD = true
@@ -95,53 +91,30 @@ module HtmlGrid
95
91
  "{ name: '#{prefix}', location: '#{path}' }"
96
92
  }.join(",")
97
93
  end
98
- config = [
99
- "parseOnLoad: #{self.class::DOJO_PARSE_ON_LOAD}",
100
- "isDebug: #{self.class::DOJO_DEBUG}",
101
- "preventBackButtonFix: #{!self.class::DOJO_BACK_BUTTON}",
102
- "bindEncoding: '#{encoding}'",
103
- "searchIds: []",
104
- "async: true",
105
- "urchin: ''",
94
+ puts "dynamic_html_headers with pkgs: #{packages}"
95
+ config =config = [
106
96
  "has: {
107
- 'dojo-firebug': #{self.class::DOJO_DEBUG},
108
- 'dojo-debug-messages': #{self.class::DOJO_DEBUG}
97
+ 'dojo-debug-messages': true
109
98
  }",
110
- "packages: [ #{packages} ]"
111
99
  ].join(',')
112
- args.store('data-dojo-config', config)
113
- args.store('src', dojo_path)
100
+ headers << %(<script>
101
+ var dojoConfig = {
102
+ parseOnLoad: true,
103
+ isDebug: true,
104
+ async: true,
105
+ urchin: '',
106
+ };
107
+ </script>)
114
108
  headers << context.script(args)
115
- args = { 'type' => 'text/javascript' }
116
- headers << context.script(args) {
117
- package_paths = self.class::DOJO_REQUIRE.map { |req|
118
- "'#{req}'"
119
- }.join(',')
120
- package_names = self.class::DOJO_REQUIRE.map { |req|
121
- req.split('/').last
122
- }.join(',')
123
- if @dojo_onloads
124
- onloads = ''
125
- @dojo_onloads.each { |onload|
126
- onloads << "#{onload}\n"
127
- }
128
- script =
129
- "require([#{package_paths}], function(#{package_names}) {" \
130
- "ready(function() {" \
131
- "#{onloads}" \
132
- "});" \
133
- "});"
109
+ { 'text/css' => File.join(File.dirname(dojo_path), "/resources/dojo.css"),
110
+ 'text/javascript' => dojo_path,
111
+ }.each do |type, path|
112
+ if (content = get_inline(path))
113
+ headers << context.style(:type =>type) { content }
134
114
  else
135
- script = "require([#{package_paths}]);"
115
+ headers << context.style(:type =>type, :src => path) { "@import \"#{path}\";" }
136
116
  end
137
- script
138
- }
139
- dojo_dir = File.dirname(dojo_path)
140
- headers << context.style(:type => "text/css") { <<-EOS
141
- @import "#{File.join(dojo_dir, "/resources/dojo.css")}";
142
- @import "#{File.join(dojo_dir, "../dijit/themes/tundra/tundra.css")}";
143
- EOS
144
- }
117
+ end
145
118
  headers
146
119
  end
147
120
  def dojo_parse_on_load
@@ -61,7 +61,7 @@ module HtmlGrid
61
61
  end
62
62
  def __messages(ary, css_class, ypos=0)
63
63
  ary.sort_by { |item|
64
- (components.index(item.key) || [-1,-1]).reverse
64
+ (components.key(item.key) || [-1,-1]).reverse
65
65
  }.reverse.each { |item|
66
66
  __message(item, css_class, ypos)
67
67
  }
@@ -24,285 +24,268 @@
24
24
  #
25
25
  # HtmlGrid::Grid -- htmlgrid -- 23.02.2012 -- mhatakeyama@ywesee.com
26
26
  # HtmlGrid::Grid -- htmlgrid -- 12.01.2010 -- hwyss@ywesee.com
27
- require 'htmlgrid/version'
28
- begin
29
- VERSION = '1.0.8'
30
- begin
31
- # for gem install
32
- ext_dir = File.expand_path('../../ext/htmlgrid', File.dirname(__FILE__))
33
- ext_lib = File.join(ext_dir, 'htmlgrid.so')
34
- require ext_lib
35
- rescue LoadError
36
- # for setup.rb install
37
- require 'htmlgrid.so'
38
- end
39
- rescue LoadError
40
- puts "could not find htmlgrid.so, falling back to pure-ruby class"
41
- module HtmlGrid
42
- class Grid
43
- attr_accessor :width, :height
44
- private
45
- class Row
46
- class Field
47
- attr_reader :components
48
- attr_accessor :tag
49
- ALLOWED_ATTRIBUTES = [
50
- 'align',
51
- 'class',
52
- 'colspan',
53
- 'style',
54
- 'tag',
55
- 'title',
56
- ]
57
- def initialize
58
- @components = []
59
- @attributes = {}
60
- end
61
- def add(item)
62
- if(item.is_a? Array)
63
- @components += item
64
- else
65
- @components.push item
66
- end
67
- end
68
- def add_background
69
- compose
70
- @components.each { |component|
71
- component.add_background
72
- }
73
- if(@attributes["class"])
74
- @attributes["class"] += "-bg" unless @attributes["class"] =~ /-bg/
75
- else
76
- @attributes["class"] = "bg"
77
- end
78
- end
79
- def add_attribute(key, value)
80
- @attributes.store(key.to_s, value.to_s)
81
- end
82
- def add_component_style(style)
83
- @components.each { |cmp|
84
- cmp.set_attribute("class", style) if cmp.respond_to?(:set_attribute)
85
- }
86
- end
87
- def add_style(style)
88
- @attributes["class"] = style
89
- end
90
- def attribute(key)
91
- @attributes[key]
92
- end
93
- def colspan
94
- @attributes.fetch("colspan", 1).to_i
95
- end
96
- def colspan=(span)
97
- @attributes["colspan"] = span.to_s if span.to_i > 1
98
- end
99
- def component_html(cgi)
100
- html = ''
101
- @components.each { |component|
102
- if component.respond_to? :to_html
103
- html << component.to_html(cgi).to_s.force_encoding('utf-8')
104
- else
105
- html << component.to_s
106
- end
107
- }
108
- html = "&nbsp;" if html.empty?
109
- html
110
- end
111
- def tag=(tag)
112
- @tag = tag.to_s.downcase
113
- end
114
- def to_html(context)
115
- if(@tag && context.respond_to?(@tag))
116
- context.send(@tag, @attributes) {
117
- component_html(context) }
118
- else
119
- context.td(@attributes) {
120
- component_html(context) }
121
- end
122
- end
123
- end
124
- def initialize # Row
125
- @width = 1
126
- @fields = [Field.new]
127
- @attributes = {}
128
- end
129
- def initialize_row w
130
- if(w > @width)
131
- @width.upto(w-1) { |ii| @fields[ii] ||= Field.new }
132
- @width = w
133
- end
134
- end
135
- def add(item, x)
136
- (@fields[x] ||= Field.new).add item
137
- end
138
- def each_field(x, w=1)
139
- x.upto([x+w, @width].min - 1) { |xx|
140
- yield(@fields[xx])
141
- }
142
- end
143
- def to_html cgi
144
- cgi.tr(@attributes) {
145
- field_html(cgi)
146
- }
147
- end
148
- def field_attribute(key, x=0)
149
- @fields[x].attribute(key)
150
- end
151
- def field_html(cgi)
152
- html = ""
153
- span = 1
154
- @fields.each { |field|
155
- if(span < 2)
156
- html << field.to_html(cgi)
157
- span = field.colspan
158
- else
159
- span -= 1
160
- end
161
- }
162
- html
163
- end
164
- def set_attributes(attr)
165
- @attributes = attr
166
- end
167
- def [](x)
168
- begin
169
- @fields[x]
170
- rescue StandardError
171
- nil
172
- end
173
- end
174
- end
175
- public
176
- def initialize(attributes={}) # Grid
177
- @height = 1
178
- @width = 1
179
- @rows = [Row.new]
180
- @attributes = {
181
- "cellspacing" => "0",
182
- }.update(attributes)
183
- end
184
- def initialize_grid(w, h)
185
- if(w > @width || h > @height)
186
- floor = (w > @width) ? 0 : @height
187
- @width = [w, @width].max
188
- @height = [h, @height].max
189
- floor.upto(@height - 1) { |ii|
190
- (@rows[ii] ||= Row.new).initialize_row(@width)
191
- }
192
- end
193
- end
194
- def add(arg, x, y, col=false)
195
- if arg.kind_of? Enumerable
196
- if arg.kind_of? String
197
- add_field(arg, x, y)
198
- elsif arg.kind_of? Array
199
- arg.each do |item|
200
- add_field(item, x ? x : '', y)
201
- end
27
+ module HtmlGrid
28
+ class Grid
29
+ attr_accessor :width, :height
30
+ private
31
+ class Row
32
+ class Field
33
+ attr_reader :components, :tag
34
+ ALLOWED_ATTRIBUTES = [
35
+ 'align',
36
+ 'class',
37
+ 'colspan',
38
+ 'style',
39
+ 'tag',
40
+ 'title',
41
+ ]
42
+ def initialize
43
+ @components = []
44
+ @attributes = {}
45
+ @tag = nil
46
+ end
47
+ def add(item)
48
+ if(item.is_a? Array)
49
+ @components += item
202
50
  else
203
- if(col)
204
- add_column(arg, x, y)
51
+ @components.push item
52
+ end
53
+ end
54
+ def add_background
55
+ compose
56
+ @components.each { |component|
57
+ component.add_background
58
+ }
59
+ if(@attributes["class"])
60
+ @attributes["class"] += "-bg" unless @attributes["class"] =~ /-bg/
61
+ else
62
+ @attributes["class"] = "bg"
63
+ end
64
+ end
65
+ def add_attribute(key, value)
66
+ @attributes.store(key.to_s, value.to_s)
67
+ end
68
+ def add_component_style(style)
69
+ @components.each { |cmp|
70
+ cmp.set_attribute("class", style) if cmp.respond_to?(:set_attribute)
71
+ }
72
+ end
73
+ def add_style(style)
74
+ @attributes["class"] = style
75
+ end
76
+ def attribute(key)
77
+ @attributes[key]
78
+ end
79
+ def colspan
80
+ @attributes.fetch("colspan", 1).to_i
81
+ end
82
+ def colspan=(span)
83
+ @attributes["colspan"] = span.to_s if span.to_i > 1
84
+ end
85
+ def component_html(cgi)
86
+ html = ''
87
+ @components.each { |component|
88
+ if component.respond_to? :to_html
89
+ html << component.to_html(cgi).to_s.dup.force_encoding('utf-8')
205
90
  else
206
- add_row(arg, x, y)
91
+ html << component.to_s
207
92
  end
93
+ }
94
+ html = "&nbsp;" if html.empty?
95
+ html
96
+ end
97
+ def tag=(tag)
98
+ @tag = tag.to_s.downcase
99
+ end
100
+ def to_html(context)
101
+ if(@tag && context.respond_to?(@tag))
102
+ context.send(@tag, @attributes) {
103
+ component_html(context) }
104
+ else
105
+ context.td(@attributes) {
106
+ component_html(context) }
208
107
  end
209
- else
108
+ end
109
+ end
110
+ def initialize # Row
111
+ @width = 1
112
+ @fields = [Field.new]
113
+ @attributes = {}
114
+ end
115
+ def initialize_row w
116
+ if(w > @width)
117
+ @width.upto(w-1) { |ii| @fields[ii] ||= Field.new }
118
+ @width = w
119
+ end
120
+ end
121
+ def add(item, x)
122
+ (@fields[x] ||= Field.new).add item
123
+ end
124
+ def each_field(x, w=1)
125
+ x.upto([x+w, @width].min - 1) { |xx|
126
+ yield(@fields[xx])
127
+ }
128
+ end
129
+ def to_html cgi
130
+ cgi.tr(@attributes) {
131
+ field_html(cgi)
132
+ }
133
+ end
134
+ def field_attribute(key, x=0)
135
+ @fields[x].attribute(key)
136
+ end
137
+ def field_html(cgi)
138
+ html = ""
139
+ span = 1
140
+ @fields.each { |field|
141
+ if(span < 2)
142
+ html << field.to_html(cgi)
143
+ span = field.colspan
144
+ else
145
+ span -= 1
146
+ end
147
+ }
148
+ html
149
+ end
150
+ def set_attributes(attr)
151
+ @attributes = attr
152
+ end
153
+ def [](x)
154
+ begin
155
+ @fields[x]
156
+ rescue StandardError
157
+ nil
158
+ end
159
+ end
160
+ end
161
+ public
162
+ def initialize(attributes={}) # Grid
163
+ @height = 1
164
+ @width = 1
165
+ @rows = [Row.new]
166
+ @attributes = {
167
+ "cellspacing" => "0",
168
+ }.update(attributes)
169
+ end
170
+ def initialize_grid(w, h)
171
+ if(w > @width || h > @height)
172
+ floor = (w > @width) ? 0 : @height
173
+ @width = [w, @width].max
174
+ @height = [h, @height].max
175
+ floor.upto(@height - 1) { |ii|
176
+ (@rows[ii] ||= Row.new).initialize_row(@width)
177
+ }
178
+ end
179
+ end
180
+ def add(arg, x, y, col=false)
181
+ if arg.kind_of?(Enumerable)
182
+ if arg.kind_of?(String)
210
183
  add_field(arg, x, y)
184
+ elsif arg.kind_of?(Array)
185
+ arg.each do |item|
186
+ add_field(item, x ? x : '', y)
187
+ end
188
+ elsif col
189
+ add_column(arg, x, y)
190
+ else
191
+ add_row(arg, x, y)
211
192
  end
212
- end
213
- def add_attribute(key, value, x, y, w=1, h=1)
214
- each_field(x, y, w, h) { |field|
215
- field.add_attribute(key, value)
216
- }
217
- end
218
- def add_background(x, y, w=1, h=1)
219
- each_field(x, y, w, h) { |field|
220
- field.add_background(x, w)
221
- }
222
- end
223
- def add_column(arg, x, y)
224
- offset = 0
225
- arg.each do |item|
226
- add_field(item, x, y + offset)
227
- offset = offset.next
228
- end
229
- end
230
- def add_component_style(style, x, y, w=1, h=1)
231
- each_field(x, y, w, h) { |field|
232
- field.add_component_style(style)
233
- }
234
- end
235
- def add_field(arg, x, y)
236
- initialize_grid(x+1, y+1)
237
- (@rows[y] ||= Row.new).add(arg, x)
238
- end
239
- def add_row(arg, x, y)
240
- offset = 0
241
- arg.each do |item|
242
- add_field(item, x + offset, y)
243
- offset = offset.next
244
- end
245
- end
246
- def add_style(style, x, y, w=1, h=1)
247
- each_field(x, y, w, h) { |field|
248
- field.add_style(style)
249
- }
250
- end
251
- def add_tag(tag, x, y, w=1, h=1)
252
- initialize_grid(x+w, y+h)
253
- each_field(x, y, w, h) { |field|
254
- field.tag = tag
255
- }
256
- end
257
- def each_field(x, y, w=1, h=1)
258
- y.upto([y+h, @height].min - 1) { |yy|
259
- @rows[yy].each_field(x,w) { |field|
260
- yield(field)
261
- }
262
- }
263
- end
264
- def field_attribute(key, x=0, y=0)
265
- @rows[y].field_attribute(key, x)
266
- end
267
- def insert_row(y=0, arg=nil)
268
- @rows[y, 0] = Row.new
269
- @height += 1
270
- add(arg, 0, y)
271
- end
272
- def push(arg, x=0, y=height)
273
- add(arg, x, y)
274
- set_colspan(x,y)
275
- end
276
- def set_attribute(key, value)
277
- @attributes[key] = value
278
- end
279
- def set_attributes(hash)
280
- @attributes.update(hash)
281
- end
282
- def set_colspan(x=0, y=0, span=(@width - x))
283
- span = span.to_i
284
- initialize_grid(x+span, y+1)
285
- self[x,y].colspan = span
286
- end
287
- def set_row_attributes(attr={}, y=0, offset=0)
288
- # TODO
289
- # At the moment, offset value is not used
290
- # But probably offset value is used in grid.c
291
- initialize_grid(offset, y + 1)
292
- @rows[y].set_attributes(attr)
293
- end
294
- def to_html(cgi)
295
- cgi.table(@attributes) {
296
- @rows.collect { |row| row.to_html(cgi).force_encoding('utf-8') }.join
297
- }
298
- end
299
- def [](x, y)
300
- begin
301
- @rows[y][x]
302
- rescue StandardError
303
- nil
304
- end
305
- end
306
- end
307
- end
193
+ else
194
+ add_field(arg, x, y)
195
+ end
196
+ end
197
+ def add_attribute(key, value, x, y, w=1, h=1)
198
+ each_field(x, y, w, h) { |field|
199
+ field.add_attribute(key, value)
200
+ }
201
+ end
202
+ def add_background(x, y, w=1, h=1)
203
+ each_field(x, y, w, h) { |field|
204
+ field.add_background(x, w)
205
+ }
206
+ end
207
+ def add_column(arg, x, y)
208
+ offset = 0
209
+ arg.each do |item|
210
+ add_field(item, x, y + offset)
211
+ offset = offset.next
212
+ end
213
+ end
214
+ def add_component_style(style, x, y, w=1, h=1)
215
+ each_field(x, y, w, h) { |field|
216
+ field.add_component_style(style)
217
+ }
218
+ end
219
+ def add_field(arg, x, y)
220
+ initialize_grid(x+1, y+1)
221
+ (@rows[y] ||= Row.new).add(arg, x)
222
+ end
223
+ def add_row(arg, x, y)
224
+ offset = 0
225
+ arg.each do |item|
226
+ add_field(item, x + offset, y)
227
+ offset = offset.next
228
+ end
229
+ end
230
+ def add_style(style, x, y, w=1, h=1)
231
+ each_field(x, y, w, h) { |field|
232
+ field.add_style(style)
233
+ }
234
+ end
235
+ def add_tag(tag, x, y, w=1, h=1)
236
+ initialize_grid(x+w, y+h)
237
+ each_field(x, y, w, h) { |field|
238
+ field.tag = tag
239
+ }
240
+ end
241
+ def each_field(x, y, w=1, h=1)
242
+ y.upto([y+h, @height].min - 1) { |yy|
243
+ @rows[yy].each_field(x,w) { |field|
244
+ yield(field)
245
+ }
246
+ }
247
+ end
248
+ def field_attribute(key, x=0, y=0)
249
+ @rows[y].field_attribute(key, x)
250
+ end
251
+ def insert_row(y=0, arg=nil)
252
+ @rows[y, 0] = Row.new
253
+ @height += 1
254
+ add(arg, 0, y)
255
+ end
256
+ def push(arg, x=0, y=height)
257
+ add(arg, x, y)
258
+ set_colspan(x,y)
259
+ end
260
+ def set_attribute(key, value)
261
+ @attributes[key] = value
262
+ end
263
+ def set_attributes(hash)
264
+ @attributes.update(hash)
265
+ end
266
+ def set_colspan(x=0, y=0, span=(@width - x))
267
+ span = span.to_i
268
+ initialize_grid(x+span, y+1)
269
+ self[x,y].colspan = span
270
+ end
271
+ def set_row_attributes(attr={}, y=0, offset=0)
272
+ # TODO
273
+ # At the moment, offset value is not used
274
+ # But probably offset value is used in grid.c
275
+ initialize_grid(offset, y + 1)
276
+ @rows[y].set_attributes(attr)
277
+ end
278
+ def to_html(cgi)
279
+ cgi.table(@attributes) {
280
+ @rows.collect { |row| row.to_html(cgi).force_encoding('utf-8') }.join
281
+ }
282
+ end
283
+ def [](x, y)
284
+ begin
285
+ @rows[y][x]
286
+ rescue StandardError
287
+ nil
288
+ end
289
+ end
290
+ end
308
291
  end