htmlgrid 1.2.3 → 1.2.4
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 +4 -4
- data/lib/htmlgrid/component.rb +3 -3
- data/lib/htmlgrid/divcomposite.rb +2 -2
- data/lib/htmlgrid/dojotoolkit.rb +4 -4
- data/lib/htmlgrid/form.rb +3 -4
- data/lib/htmlgrid/grid.rb +4 -4
- data/lib/htmlgrid/list.rb +1 -1
- data/lib/htmlgrid/template.rb +1 -1
- data/lib/htmlgrid/version.rb +1 -1
- data/test/test_grid.rb +10 -10
- data/test/test_label.rb +4 -4
- data/test/test_template.rb +2 -4
- metadata +8 -10
- data/lib/htmlgrid/component.rb~ +0 -252
- data/lib/htmlgrid/version.rb~ +0 -5
- data/test/test_component.rb~ +0 -204
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac32c5daad4ba30a32d15b25f2e7204a333847a571b86d6dc4ff3674327ffd7a
|
4
|
+
data.tar.gz: 521a04676dbb15f3522c1c5defd8d1813bc8bf87cb1a7ca7cf5982b02e2e1589
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14e4e35e3639f44ff835416fedd0ec82471e179e6cdeead718aac1bdf49657d558412bf1c52797f82fd366bff37f9cfa3291c284f85f1dde2c6c119fb451918f
|
7
|
+
data.tar.gz: 4134060a38dee891f9da25d635c3e65956ce8e94943c1e0bbdd262f34bee18a07c1c19a6df548f1db75f0f2a178189453b81efa79704c7c1a1c5bd1d6298e652
|
data/lib/htmlgrid/component.rb
CHANGED
@@ -172,7 +172,7 @@ module HtmlGrid
|
|
172
172
|
def escape(txt)
|
173
173
|
@@html_entities.each_with_object(txt.to_s.dup) { |map, str|
|
174
174
|
char, entity = map
|
175
|
-
str.gsub!(char, "&"
|
175
|
+
str.gsub!(char, "&" + entity + ";")
|
176
176
|
}
|
177
177
|
end
|
178
178
|
|
@@ -180,8 +180,8 @@ module HtmlGrid
|
|
180
180
|
def escape_symbols(txt)
|
181
181
|
esc = ""
|
182
182
|
txt.to_s.each_byte { |byte|
|
183
|
-
esc
|
184
|
-
"&"
|
183
|
+
esc += if (entity = @@symbol_entities[byte])
|
184
|
+
"&" + entity + ";"
|
185
185
|
else
|
186
186
|
byte
|
187
187
|
end
|
@@ -37,9 +37,9 @@ module HtmlGrid
|
|
37
37
|
def to_html(context)
|
38
38
|
res = ""
|
39
39
|
@grid&.each_with_index { |div, idx|
|
40
|
-
res
|
40
|
+
res += context.div(tag_attributes(idx)) {
|
41
41
|
div.flatten.inject("") { |html, item|
|
42
|
-
html
|
42
|
+
html += if item.respond_to?(:to_html)
|
43
43
|
item.to_html(context).force_encoding("utf-8")
|
44
44
|
else
|
45
45
|
item.to_s
|
data/lib/htmlgrid/dojotoolkit.rb
CHANGED
@@ -62,10 +62,10 @@ module HtmlGrid
|
|
62
62
|
else
|
63
63
|
attrs.store("href", @dojo_tooltip)
|
64
64
|
end
|
65
|
-
html
|
65
|
+
html += context.div(attrs)
|
66
66
|
elsif @dojo_tooltip.respond_to?(:to_html)
|
67
67
|
@dojo_tooltip.attributes.update(attrs)
|
68
|
-
html
|
68
|
+
html += @dojo_tooltip.to_html(context).force_encoding("utf-8")
|
69
69
|
end
|
70
70
|
unless html.empty? || dojo_parse_on_load
|
71
71
|
html << context.script("type" => "text/javascript") {
|
@@ -73,7 +73,7 @@ module HtmlGrid
|
|
73
73
|
}
|
74
74
|
end
|
75
75
|
# call original dynamic_html
|
76
|
-
dojo_dynamic_html(context)
|
76
|
+
"#{dojo_dynamic_html(context)}#{html}"
|
77
77
|
end
|
78
78
|
end
|
79
79
|
end
|
@@ -114,7 +114,7 @@ module HtmlGrid
|
|
114
114
|
].join(",")
|
115
115
|
args.store("data-dojo-config", config)
|
116
116
|
args.store("src", dojo_path)
|
117
|
-
headers
|
117
|
+
headers += context.script(args)
|
118
118
|
args = {"type" => "text/javascript"}
|
119
119
|
headers << context.script(args) {
|
120
120
|
package_paths = self.class::DOJO_REQUIRE.map { |req|
|
data/lib/htmlgrid/form.rb
CHANGED
@@ -63,11 +63,10 @@ module HtmlGrid
|
|
63
63
|
private
|
64
64
|
|
65
65
|
def hidden_fields(context)
|
66
|
-
|
67
|
-
context.hidden("
|
68
|
-
context.hidden("language", @lookandfeel.language) <<
|
66
|
+
context.hidden("flavor", @lookandfeel.flavor) +
|
67
|
+
context.hidden("language", @lookandfeel.language) +
|
69
68
|
context.hidden({"NAME" => "event", "ID" => "event",
|
70
|
-
"VALUE" => event.to_s})
|
69
|
+
"VALUE" => event.to_s}) +
|
71
70
|
context.hidden("state_id", @session.state.object_id.to_s)
|
72
71
|
end
|
73
72
|
|
data/lib/htmlgrid/grid.rb
CHANGED
@@ -96,10 +96,10 @@ module HtmlGrid
|
|
96
96
|
def component_html(cgi)
|
97
97
|
html = ""
|
98
98
|
@components.each { |component|
|
99
|
-
|
100
|
-
component.to_html(cgi).to_s.dup.force_encoding("utf-8")
|
99
|
+
if component.respond_to? :to_html
|
100
|
+
html += component.to_html(cgi).to_s.dup.force_encoding("utf-8")
|
101
101
|
else
|
102
|
-
component.to_s
|
102
|
+
html += component.to_s
|
103
103
|
end
|
104
104
|
}
|
105
105
|
html = " " if html.empty?
|
@@ -162,7 +162,7 @@ module HtmlGrid
|
|
162
162
|
span = 1
|
163
163
|
@fields.each { |field|
|
164
164
|
if span < 2
|
165
|
-
html
|
165
|
+
html += field.to_html(cgi)
|
166
166
|
span = field.colspan
|
167
167
|
else
|
168
168
|
span -= 1
|
data/lib/htmlgrid/list.rb
CHANGED
@@ -90,7 +90,7 @@ module HtmlGrid
|
|
90
90
|
ystep = step.at(1)
|
91
91
|
components.each { |matrix, component|
|
92
92
|
key = lookandfeel_key(component)
|
93
|
-
header_key = "th_"
|
93
|
+
header_key = "th_" + key.to_s
|
94
94
|
if (txt = @lookandfeel.lookup(header_key))
|
95
95
|
if self.class::SORT_HEADER
|
96
96
|
@grid.add(sort_link(header_key, matrix, component), *matrix)
|
data/lib/htmlgrid/template.rb
CHANGED
data/lib/htmlgrid/version.rb
CHANGED
data/test/test_grid.rb
CHANGED
@@ -255,15 +255,15 @@ class TestGrid < Minitest::Test
|
|
255
255
|
assert_equal(expected, @grid.to_html(CGI.new))
|
256
256
|
@grid.add(nil, 1, 1)
|
257
257
|
@grid.add_style("bar", 0, 1, 2)
|
258
|
-
expected = '<TABLE cellspacing="0"><TR><TD class="foo"> </TD>'
|
259
|
-
|
260
|
-
|
258
|
+
expected = '<TABLE cellspacing="0"><TR><TD class="foo"> </TD>'+
|
259
|
+
'<TD> </TD></TR><TR><TD class="bar"> </TD>' +
|
260
|
+
'<TD class="bar"> </TD></TR></TABLE>'
|
261
261
|
assert_equal(expected, @grid.to_html(CGI.new))
|
262
262
|
@grid.add_style("foobar", 0, 0, 2, 2)
|
263
|
-
expected = '<TABLE cellspacing="0"><TR><TD class="foobar"> </TD>'
|
264
|
-
|
265
|
-
|
266
|
-
|
263
|
+
expected = '<TABLE cellspacing="0"><TR><TD class="foobar"> </TD>' +
|
264
|
+
'<TD class="foobar"> </TD></TR>' +
|
265
|
+
'<TR><TD class="foobar"> </TD>' +
|
266
|
+
'<TD class="foobar"> </TD></TR></TABLE>'
|
267
267
|
assert_equal(expected, @grid.to_html(CGI.new))
|
268
268
|
end
|
269
269
|
|
@@ -292,9 +292,9 @@ class TestGrid < Minitest::Test
|
|
292
292
|
def test_push
|
293
293
|
@grid.add("bar", 4, 0)
|
294
294
|
@grid.push("foo")
|
295
|
-
expected = '<TABLE cellspacing="0"><TR><TD> </TD><TD> </TD>'
|
296
|
-
|
297
|
-
|
295
|
+
expected = '<TABLE cellspacing="0"><TR><TD> </TD><TD> </TD>' +
|
296
|
+
"<TD> </TD><TD> </TD><TD>bar</TD></TR>" +
|
297
|
+
'<TR><TD colspan="5">foo</TD></TR></TABLE>'
|
298
298
|
assert_equal(expected, @grid.to_html(CGI.new))
|
299
299
|
end
|
300
300
|
|
data/test/test_label.rb
CHANGED
@@ -109,10 +109,10 @@ class TestLabel < Minitest::Test
|
|
109
109
|
def test_to_html1
|
110
110
|
composite = StubLabelComposite.new(StubLabelModel.new, @session)
|
111
111
|
expected = '<TABLE cellspacing="0"><TR>'
|
112
|
-
expected
|
113
|
-
expected
|
114
|
-
expected
|
115
|
-
expected
|
112
|
+
expected += '<TD><LABEL for="componentname">Label</LABEL></TD>'
|
113
|
+
expected += "<TD>component</TD></TR>"
|
114
|
+
expected += '<TR><TD><LABEL for="componentname">Named Label</LABEL></TD>'
|
115
|
+
expected += "<TD>component</TD></TR></TABLE>"
|
116
116
|
assert_equal(expected, composite.to_html(CGI.new))
|
117
117
|
end
|
118
118
|
|
data/test/test_template.rb
CHANGED
@@ -93,8 +93,7 @@ class TestTemplate < Minitest::Test
|
|
93
93
|
end
|
94
94
|
|
95
95
|
def test_to_html
|
96
|
-
result =
|
97
|
-
result << @template.to_html(CGI.new)
|
96
|
+
result = @template.to_html(CGI.new)
|
98
97
|
expected = [
|
99
98
|
"<TITLE>Test</TITLE>",
|
100
99
|
'<LINK rel="stylesheet" type="text/css" async="true" href="http://testserver.com:80/resources/gcc/test.css">',
|
@@ -111,8 +110,7 @@ class TestTemplate < Minitest::Test
|
|
111
110
|
@lookandfeel.should_receive(:lookup).with(:html_title).and_return("html_title").by_default
|
112
111
|
@lookandfeel.should_receive(:lookup).with(any).and_return(nil).by_default
|
113
112
|
@template = Template.new(nil, @lookandfeel, nil)
|
114
|
-
result =
|
115
|
-
result << @template.to_html(CGI.new)
|
113
|
+
result = @template.to_html(CGI.new)
|
116
114
|
expected = [
|
117
115
|
"<TITLE>html_title</TITLE>",
|
118
116
|
"this is a dummy CSS file, which should be inlined",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: htmlgrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masaomi Hatakeyama, Zeno R.R. Davatz
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sbsm
|
@@ -189,7 +189,6 @@ files:
|
|
189
189
|
- lib/htmlgrid/button.rb
|
190
190
|
- lib/htmlgrid/centeredcomposite.rb
|
191
191
|
- lib/htmlgrid/component.rb
|
192
|
-
- lib/htmlgrid/component.rb~
|
193
192
|
- lib/htmlgrid/composite.rb
|
194
193
|
- lib/htmlgrid/datevalue.rb
|
195
194
|
- lib/htmlgrid/div.rb
|
@@ -236,12 +235,10 @@ files:
|
|
236
235
|
- lib/htmlgrid/urllink.rb
|
237
236
|
- lib/htmlgrid/value.rb
|
238
237
|
- lib/htmlgrid/version.rb
|
239
|
-
- lib/htmlgrid/version.rb~
|
240
238
|
- test/stub/cgi.rb
|
241
239
|
- test/suite.rb
|
242
240
|
- test/test_add_row.rb
|
243
241
|
- test/test_component.rb
|
244
|
-
- test/test_component.rb~
|
245
242
|
- test/test_composite.rb
|
246
243
|
- test/test_datevalue.rb
|
247
244
|
- test/test_divlist.rb
|
@@ -260,8 +257,9 @@ files:
|
|
260
257
|
homepage: https://github.com/zdavatz/htmlgrid/
|
261
258
|
licenses:
|
262
259
|
- GPL v2.1
|
263
|
-
metadata:
|
264
|
-
|
260
|
+
metadata:
|
261
|
+
changelog_uri: https://github.com/zdavatz/htmlgrid//blob/master/History.md
|
262
|
+
post_install_message:
|
265
263
|
rdoc_options: []
|
266
264
|
require_paths:
|
267
265
|
- lib
|
@@ -276,8 +274,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
276
274
|
- !ruby/object:Gem::Version
|
277
275
|
version: '0'
|
278
276
|
requirements: []
|
279
|
-
rubygems_version: 3.3
|
280
|
-
signing_key:
|
277
|
+
rubygems_version: 3.5.3
|
278
|
+
signing_key:
|
281
279
|
specification_version: 4
|
282
280
|
summary: HtmlGrid is a Html-ToolKit for Ruby Webframeworks.
|
283
281
|
test_files: []
|
data/lib/htmlgrid/component.rb~
DELETED
@@ -1,252 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
#--
|
4
|
-
# HtmlGrid -- HyperTextMarkupLanguage Framework
|
5
|
-
# Copyright (C) 2003 ywesee - intellectual capital connected
|
6
|
-
# Andreas Schrafl, Benjamin Fay, Hannes Wyss, Markus Huggler
|
7
|
-
#
|
8
|
-
# This library is free software; you can redistribute it and/or
|
9
|
-
# modify it under the terms of the GNU Lesser General Public
|
10
|
-
# License as published by the Free Software Foundation; either
|
11
|
-
# version 2.1 of the License, or (at your option) any later version.
|
12
|
-
#
|
13
|
-
# This library is distributed in the hope that it will be useful,
|
14
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16
|
-
# Lesser General Public License for more details.
|
17
|
-
#
|
18
|
-
# You should have received a copy of the GNU Lesser General Public
|
19
|
-
# License along with this library; if not, write to the Free Software
|
20
|
-
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21
|
-
#
|
22
|
-
# ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
|
23
|
-
# htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
|
24
|
-
#
|
25
|
-
# HtmlGrid::Component -- htmlgrid -- 23.12.2012 -- mhatakeyama@ywesee.com
|
26
|
-
# HtmlGrid::Component -- htmlgrid -- 23.10.2002 -- hwyss@ywesee.com
|
27
|
-
#++
|
28
|
-
|
29
|
-
module HtmlGrid
|
30
|
-
class Component
|
31
|
-
# sets the 'class' html-attribute
|
32
|
-
CSS_CLASS = nil
|
33
|
-
# sets the 'id' html-attribute
|
34
|
-
CSS_ID = nil
|
35
|
-
# other html-attributes
|
36
|
-
HTML_ATTRIBUTES = {}
|
37
|
-
# default http-headers
|
38
|
-
HTTP_HEADERS = {
|
39
|
-
"Content-Type" => "text/html",
|
40
|
-
"Cache-Control" => "no-cache, max-age=3600, must-revalidate"
|
41
|
-
}
|
42
|
-
# precede instances of this class with a label?
|
43
|
-
LABEL = false
|
44
|
-
@@html_entities = [
|
45
|
-
["&", "amp"],
|
46
|
-
["<", "lt"],
|
47
|
-
[">", "gt"]
|
48
|
-
] # :nodoc:
|
49
|
-
@@symbol_entities = {
|
50
|
-
34 => "forall",
|
51
|
-
36 => "exist",
|
52
|
-
42 => "lowast",
|
53
|
-
45 => "minus",
|
54
|
-
64 => "cong",
|
55
|
-
65 => "Alpha", 97 => "alpha",
|
56
|
-
66 => "Beta", 98 => "beta",
|
57
|
-
67 => "Chi", 99 => "chi",
|
58
|
-
68 => "Delta", 100 => "delta",
|
59
|
-
69 => "Epsilon", 101 => "epsilon",
|
60
|
-
70 => "Phi", 102 => "phi",
|
61
|
-
71 => "Gamma", 103 => "gamma",
|
62
|
-
72 => "Eta", 104 => "eta",
|
63
|
-
73 => "Iota", 105 => "iota",
|
64
|
-
75 => "Kappa", 107 => "kappa",
|
65
|
-
76 => "Lambda", 108 => "lambda",
|
66
|
-
77 => "Mu", 109 => "mu",
|
67
|
-
78 => "Nu", 110 => "nu",
|
68
|
-
79 => "Omicron", 111 => "omicron",
|
69
|
-
80 => "Pi", 112 => "pi",
|
70
|
-
81 => "Theta", 113 => "theta",
|
71
|
-
82 => "Rho", 114 => "rho",
|
72
|
-
83 => "Sigma", 115 => "sigma",
|
73
|
-
84 => "Tau", 116 => "tau",
|
74
|
-
85 => "Upsilon", 117 => "upsilon",
|
75
|
-
86 => "sigmaf",
|
76
|
-
87 => "Omega", 119 => "omega",
|
77
|
-
88 => "Xi", 120 => "xi",
|
78
|
-
89 => "Psi", 121 => "psi",
|
79
|
-
90 => "Zeta", 122 => "zeta",
|
80
|
-
94 => "perp", 126 => "sim",
|
81
|
-
163 => "le",
|
82
|
-
165 => "infin",
|
83
|
-
166 => "fnof",
|
84
|
-
171 => "harr",
|
85
|
-
172 => "larr",
|
86
|
-
173 => "uarr",
|
87
|
-
174 => "rarr",
|
88
|
-
175 => "darr",
|
89
|
-
179 => "ge",
|
90
|
-
181 => "prop",
|
91
|
-
182 => "part",
|
92
|
-
185 => "ne",
|
93
|
-
186 => "equiv",
|
94
|
-
187 => "asymp",
|
95
|
-
191 => "crarr",
|
96
|
-
196 => "otimes",
|
97
|
-
197 => "oplus",
|
98
|
-
198 => "empty",
|
99
|
-
199 => "cap",
|
100
|
-
200 => "cup",
|
101
|
-
201 => "sup",
|
102
|
-
202 => "supe",
|
103
|
-
203 => "nsub",
|
104
|
-
204 => "sub",
|
105
|
-
205 => "sube",
|
106
|
-
206 => "isin",
|
107
|
-
207 => "notin",
|
108
|
-
208 => "ang",
|
109
|
-
209 => "nabla",
|
110
|
-
213 => "prod",
|
111
|
-
214 => "radic",
|
112
|
-
215 => "sdot",
|
113
|
-
217 => "and",
|
114
|
-
218 => "or",
|
115
|
-
219 => "hArr",
|
116
|
-
220 => "lArr",
|
117
|
-
221 => "uArr",
|
118
|
-
222 => "rArr",
|
119
|
-
223 => "dArr",
|
120
|
-
229 => "sum",
|
121
|
-
242 => "int"
|
122
|
-
} # :nodoc:
|
123
|
-
attr_reader :attributes, :model
|
124
|
-
attr_accessor :value
|
125
|
-
def initialize(model, session = nil, container = nil)
|
126
|
-
@model = model
|
127
|
-
@session = session
|
128
|
-
@lookandfeel = session.lookandfeel if session.respond_to?(:lookandfeel)
|
129
|
-
@container = container
|
130
|
-
@attributes = self.class::HTML_ATTRIBUTES.dup
|
131
|
-
if css_class
|
132
|
-
@attributes.store("class", css_class)
|
133
|
-
end
|
134
|
-
if css_id
|
135
|
-
@attributes.store("id", css_id)
|
136
|
-
end
|
137
|
-
@value = nil
|
138
|
-
@label = self.class::LABEL
|
139
|
-
init
|
140
|
-
end
|
141
|
-
|
142
|
-
# delegator to @container, default definition in Form
|
143
|
-
def autofill?
|
144
|
-
@container.autofill? if @container.respond_to?(:autofill?)
|
145
|
-
end
|
146
|
-
|
147
|
-
# gets the 'class' html-attribute if defined
|
148
|
-
def css_class
|
149
|
-
@css_class ||= self.class::CSS_CLASS
|
150
|
-
end
|
151
|
-
|
152
|
-
# sets the 'class' html-attribute
|
153
|
-
def css_class=(css_class)
|
154
|
-
@css_class = @attributes["class"] = css_class
|
155
|
-
end
|
156
|
-
|
157
|
-
# gets the 'id' html-attribute if defined
|
158
|
-
def css_id
|
159
|
-
@css_id ||= self.class::CSS_ID
|
160
|
-
end
|
161
|
-
|
162
|
-
# sets the 'id' html-attribute
|
163
|
-
def css_id=(css_id)
|
164
|
-
@css_id = @attributes["id"] = css_id
|
165
|
-
end
|
166
|
-
|
167
|
-
def dynamic_html(context)
|
168
|
-
""
|
169
|
-
end
|
170
|
-
|
171
|
-
# escape '&', '<' and '>' characters in txt
|
172
|
-
def escape(txt)
|
173
|
-
@@html_entities.each_with_object(txt.to_s.dup) { |map, str|
|
174
|
-
char, entity = map
|
175
|
-
str.gsub!(char, "&" << entity << ";")
|
176
|
-
}
|
177
|
-
end
|
178
|
-
|
179
|
-
# escape symbol-font strings
|
180
|
-
def escape_symbols(txt)
|
181
|
-
esc = ""
|
182
|
-
txt.to_s.each_byte { |byte|
|
183
|
-
esc << if (entity = @@symbol_entities[byte])
|
184
|
-
"&" << entity << ";"
|
185
|
-
else
|
186
|
-
byte
|
187
|
-
end
|
188
|
-
}
|
189
|
-
esc
|
190
|
-
end
|
191
|
-
|
192
|
-
# delegator to @container, default definition in Form
|
193
|
-
def formname
|
194
|
-
@container.formname if @container.respond_to?(:formname)
|
195
|
-
end
|
196
|
-
|
197
|
-
def http_headers
|
198
|
-
self.class::HTTP_HEADERS.dup
|
199
|
-
end
|
200
|
-
|
201
|
-
# precede this instance with a label?
|
202
|
-
def label?
|
203
|
-
@label
|
204
|
-
end
|
205
|
-
|
206
|
-
attr_writer :label
|
207
|
-
|
208
|
-
def onclick=(onclick)
|
209
|
-
@attributes["onclick"] = onclick
|
210
|
-
end
|
211
|
-
|
212
|
-
# delegator to @container, default definition in Template
|
213
|
-
def onload=(onload)
|
214
|
-
@container.onload = onload if @container.respond_to? :onload=
|
215
|
-
end
|
216
|
-
|
217
|
-
# delegator to @container, default definition in Form
|
218
|
-
def onsubmit=(onsubmit)
|
219
|
-
@container.onsubmit = onsubmit if @container.respond_to? :onsubmit=
|
220
|
-
end
|
221
|
-
|
222
|
-
# set a html attribute
|
223
|
-
def set_attribute(key, value)
|
224
|
-
@attributes.store(key, value)
|
225
|
-
end
|
226
|
-
|
227
|
-
def tabindex=(tab)
|
228
|
-
@attributes.store("tabIndex", tab.to_s)
|
229
|
-
end
|
230
|
-
|
231
|
-
def to_html(context)
|
232
|
-
_to_html(context, @value).to_s.encode("utf-8")
|
233
|
-
end
|
234
|
-
@@nl2br_ptrn = /(\r\n)|(\n)|(\r)/
|
235
|
-
def _to_html(context, value = @value)
|
236
|
-
if value.is_a?(Array)
|
237
|
-
value.collect { |item| _to_html(context, item) }.join(" ")
|
238
|
-
elsif value.respond_to?(:to_html)
|
239
|
-
value.to_html(context).to_s.dup.force_encoding("utf-8")
|
240
|
-
elsif value&.is_a?(String)
|
241
|
-
_value = CGI.unescape(value.gsub("+", CGI.escape("+")))
|
242
|
-
# elsif value&.is_a?(Integer)
|
243
|
-
# _value = value.to_s
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
private
|
248
|
-
|
249
|
-
def init
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
data/lib/htmlgrid/version.rb~
DELETED
data/test/test_component.rb~
DELETED
@@ -1,204 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# HtmlGrid -- HyperTextMarkupLanguage Framework
|
4
|
-
# Copyright (C) 2003 ywesee - intellectual capital connected
|
5
|
-
# Hannes Wyss
|
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
|
-
# TestComponent -- htmlgrid -- 26.11.2002 -- hwyss@ywesee.com
|
25
|
-
|
26
|
-
$: << File.expand_path("../lib", File.dirname(__FILE__))
|
27
|
-
$: << File.expand_path("../ext", File.dirname(__FILE__))
|
28
|
-
$: << File.dirname(__FILE__)
|
29
|
-
|
30
|
-
require "minitest/autorun"
|
31
|
-
require "htmlgrid/component"
|
32
|
-
require "stub/cgi"
|
33
|
-
|
34
|
-
module HtmlGrid
|
35
|
-
class Component
|
36
|
-
attr_reader :session, :container
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class TestComponent < Minitest::Test
|
41
|
-
STRING_WITH_SHARP = "Test_#_gartenhat"
|
42
|
-
STRING_WITH_PLUS = "Test_+_plus"
|
43
|
-
STRING_WITH_UMLAUT = "Test_with_Umlaut_üé"
|
44
|
-
class StubAttributeComponent < HtmlGrid::Component
|
45
|
-
HTML_ATTRIBUTES = {"key" => "val"}
|
46
|
-
end
|
47
|
-
|
48
|
-
class StubInitComponent < HtmlGrid::Component
|
49
|
-
attr_reader :init_called
|
50
|
-
def init
|
51
|
-
@init_called = true
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class StubLabelComponent < HtmlGrid::Component
|
56
|
-
LABEL = true
|
57
|
-
end
|
58
|
-
|
59
|
-
class StubContainer
|
60
|
-
attr_accessor :onsubmit
|
61
|
-
end
|
62
|
-
|
63
|
-
class ToHTMLreturnFrozen
|
64
|
-
def initialize content
|
65
|
-
@content = content
|
66
|
-
end
|
67
|
-
|
68
|
-
def to_html(what)
|
69
|
-
@content.to_s.freeze
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def setup
|
74
|
-
@component = HtmlGrid::Component.new(nil, nil)
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_initialize1
|
78
|
-
HtmlGrid::Component.new("foo", "bar")
|
79
|
-
comp = HtmlGrid::Component.new("foo", "bar")
|
80
|
-
assert_equal("foo", comp.model)
|
81
|
-
assert_equal("bar", comp.session)
|
82
|
-
assert_nil(comp.container)
|
83
|
-
assert_equal(false, comp.label?)
|
84
|
-
comp.label = true
|
85
|
-
assert_equal(true, comp.label?)
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_initialize2
|
89
|
-
HtmlGrid::Component.new("foo", "bar", "baz")
|
90
|
-
comp = HtmlGrid::Component.new("foo", "bar", "baz")
|
91
|
-
assert_equal("foo", comp.model)
|
92
|
-
assert_equal("bar", comp.session)
|
93
|
-
assert_equal("baz", comp.container)
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_to_html
|
97
|
-
comp = HtmlGrid::Component.new("foo", "bar", "baz").to_html(CGI.new)
|
98
|
-
assert_equal("", comp)
|
99
|
-
end
|
100
|
-
|
101
|
-
# Next is test for https://github.com/zdavatz/oddb.org/issues/118 FrozenError at /de/just-medical
|
102
|
-
def test_to_html_frozen_empty
|
103
|
-
comp = HtmlGrid::Component.new("context")
|
104
|
-
comp.value = ToHTMLreturnFrozen.new("")
|
105
|
-
result = comp.to_html(CGI.new)
|
106
|
-
assert_equal("", result)
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_gartenhag_to_html
|
110
|
-
comp = HtmlGrid::Component.new("context")
|
111
|
-
comp.value = STRING_WITH_SHARP
|
112
|
-
result = comp.to_html(CGI.new)
|
113
|
-
assert_equal(STRING_WITH_SHARP, result)
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_minus_to_html
|
117
|
-
comp = HtmlGrid::Component.new("context")
|
118
|
-
comp.value = STRING_WITH_PLUS
|
119
|
-
result = comp.to_html(CGI.new)
|
120
|
-
assert_equal(STRING_WITH_PLUS, result)
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_umlaut_to_html
|
124
|
-
comp = HtmlGrid::Component.new("context")
|
125
|
-
comp.value = STRING_WITH_UMLAUT
|
126
|
-
result = comp.to_html(CGI.new)
|
127
|
-
assert_equal(STRING_WITH_UMLAUT, result)
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_escaped_STRING_WITH_UMLAUT_to_html
|
131
|
-
comp = HtmlGrid::Component.new("context")
|
132
|
-
comp.value = CGI.escape(STRING_WITH_UMLAUT)
|
133
|
-
result = comp.to_html(CGI.new)
|
134
|
-
assert_equal(STRING_WITH_UMLAUT, result)
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_initialize3
|
138
|
-
comp = StubAttributeComponent.new("foo", "bar")
|
139
|
-
expected = {"key" => "val"}
|
140
|
-
assert_respond_to(comp, :attributes)
|
141
|
-
assert_equal(expected, comp.attributes)
|
142
|
-
assert_equal(expected, StubAttributeComponent::HTML_ATTRIBUTES)
|
143
|
-
comp.attributes.store("other", "val")
|
144
|
-
expected2 = {"key" => "val", "other" => "val"}
|
145
|
-
assert_equal(expected2, comp.attributes)
|
146
|
-
assert_equal(expected, StubAttributeComponent::HTML_ATTRIBUTES)
|
147
|
-
assert_equal({}, @component.attributes)
|
148
|
-
assert_equal({}, HtmlGrid::Component::HTML_ATTRIBUTES)
|
149
|
-
@component.attributes.store("third", "val")
|
150
|
-
expected = {"third" => "val"}
|
151
|
-
assert_equal(expected, @component.attributes)
|
152
|
-
assert_equal({}, HtmlGrid::Component::HTML_ATTRIBUTES)
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_initialize4
|
156
|
-
comp = StubInitComponent.new("foo", "bar")
|
157
|
-
assert_equal(true, comp.init_called)
|
158
|
-
end
|
159
|
-
|
160
|
-
def test_initialize5
|
161
|
-
comp = StubLabelComponent.new(nil, nil)
|
162
|
-
assert_equal(true, comp.label?)
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_integer_to_html
|
166
|
-
comp = HtmlGrid::Component.new("context")
|
167
|
-
comp.value = 3
|
168
|
-
result = comp.to_html(CGI.new)
|
169
|
-
assert_equal("xx", result)
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_escape
|
173
|
-
txt = "Guten Tag! & wie gehts uns denn heute? '<' schlechter oder '>' besser?"
|
174
|
-
control = txt.dup
|
175
|
-
expected = "Guten Tag! & wie gehts uns denn heute? '<' schlechter oder '>' besser?"
|
176
|
-
assert_equal(expected, @component.escape(txt))
|
177
|
-
assert_equal(control, txt)
|
178
|
-
assert_equal(expected, @component.escape(txt))
|
179
|
-
end
|
180
|
-
|
181
|
-
def test_escape_symbols
|
182
|
-
txt = "\263"
|
183
|
-
expected = "≥"
|
184
|
-
assert_equal(expected, @component.escape_symbols(txt))
|
185
|
-
end
|
186
|
-
|
187
|
-
def test_onsubmit
|
188
|
-
@component.onsubmit = "submitted"
|
189
|
-
assert_equal({}, @component.attributes)
|
190
|
-
cont = StubContainer.new
|
191
|
-
comp = HtmlGrid::Component.new("foo", "bar", cont)
|
192
|
-
comp.onsubmit = "submitted"
|
193
|
-
assert_equal("submitted", cont.onsubmit)
|
194
|
-
end
|
195
|
-
|
196
|
-
def test_set_attribute
|
197
|
-
assert_equal({}, @component.attributes)
|
198
|
-
@component.set_attribute("href", "http://www.ywesee.com")
|
199
|
-
expected = {
|
200
|
-
"href" => "http://www.ywesee.com"
|
201
|
-
}
|
202
|
-
assert_equal(expected, @component.attributes)
|
203
|
-
end
|
204
|
-
end
|