htmlgrid 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5d30addff4506799b90228f01a9c910f6231967
4
- data.tar.gz: d96e8a7d27da7aab4acaf1458a334bbf89c76af2
3
+ metadata.gz: 2847726b7e6ac148bca47055c992b5d330ca670e
4
+ data.tar.gz: 5c53eb62fb668b52bc7baab302b6a50127838e6a
5
5
  SHA512:
6
- metadata.gz: 7be2249769ff2f267ff89af97188e897c89e87d79403e71cb24658f315cf09d25211f756db822aec048da2ecf6fdc166c74a82b1c734b570b0cae68bec642754
7
- data.tar.gz: b6995921b53ae767df96a8fabdd97e3d7de0396e1a5a3626e88e7ed7d5259c9c84cd97de5e1f54ec26c00b3e7898499fa17f242cf31fb60fef9d9f7e98f86a8a
6
+ metadata.gz: 48861a4c77a5f83517637e23b88200145c0dfe26097d342e06c1d7fe559699a70f3310462647a370e6ee9a6941ee6d42d71557bad0a8a9b15f1c7a9f81007e39
7
+ data.tar.gz: f3a7b84c902d5e5615e50e2a602e7c58d789148614205fc0a28e1342b5477dfc468de1a8442909a3afa67cf4c7599427f1b9ba25866436696d5179c8b86b78d1
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ === 1.1.2 / 10.08.2016
2
+
3
+ * Fix warnings by syntax or coding style
4
+ * Fix test errors
5
+ * Fix asset (doc) files permission
6
+ * Fix installation issues on ruby 2.0.0 and 2.1.9
7
+ * Add ruby 2.3.1 as ci target
8
+
1
9
  === 1.1.1 / 07.07.2016
2
10
 
3
11
  * Improve dojotoolkit.rb
data/Manifest.txt CHANGED
@@ -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
@@ -213,7 +213,7 @@ module HtmlGrid
213
213
  def tabindex=(tab)
214
214
  @attributes.store('tabIndex', tab.to_s)
215
215
  end
216
- def to_html(context)
216
+ def to_html(context)
217
217
  _to_html(context, @value).to_s.force_encoding('utf-8')
218
218
  end
219
219
  @@nl2br_ptrn = /(\r\n)|(\n)|(\r)/
@@ -106,7 +106,7 @@ module HtmlGrid
106
106
  methname = klass.to_s.downcase.gsub('::', '_') << '_' << key.to_s
107
107
  define_method(methname) { |*args|
108
108
  model, session = args
109
- args = [model.send(key), @session, self]
109
+ args = [model.send(key), session, self]
110
110
  if(name)
111
111
  args.unshift(name)
112
112
  lookandfeel_map.store(methname.to_sym, name.to_sym)
@@ -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
  }
data/lib/htmlgrid/grid.rb CHANGED
@@ -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.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