htmlgrid 1.2.2 → 1.2.3

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
2
  SHA256:
3
- metadata.gz: a894cd7a5db3b2ca1cec59510012c4762173876fc0bba7024019467c4d31995a
4
- data.tar.gz: c06fca0f6b632ecfc29d6c83540ebfc96ca595d883b7b66ff03c3ba6892c7ca5
3
+ metadata.gz: 87d0fe1b57b1446781886b5c03fff8f9eaef864515f05cfb0312269bb933b925
4
+ data.tar.gz: c134762161a92b02cd1e8658fb22efd6a2d0d89f57c9d088b05236dfd5a3b9dc
5
5
  SHA512:
6
- metadata.gz: bd9cd290ee26db218bc675434031888db1067bdcb28105f656ad9ef8f1f9bbed20b518b83c7b72129ccdaa6e1412c037e9e17b6cf7f0b70aba34eb1f3fd79fab
7
- data.tar.gz: e42dd5526ec2daca35de2eba08da359305424d1b04fa5d8bc2082b2a23b7d8dbbed109bd5ca162bb970db9839147800d90a491115433b3650fcc93467ac4e928
6
+ metadata.gz: bb5d41e32a404dd906968f050859a7312466d01ce71c57afd8deabb48fbf8caa0884f450e61b59524abeb9cf7d0e224757df0712203163a3243148ac7c323f19
7
+ data.tar.gz: 02c89a8f66c5ce317a14f144d42d9f174ac62f3ae9e63ef1fca735df94ebe504ff69cf259f2aa3500af1fad5fdf02ab0b1b5de70e95f4d19d0dc0733e3b95f3e
@@ -239,6 +239,8 @@ module HtmlGrid
239
239
  value.to_html(context).to_s.dup.force_encoding("utf-8")
240
240
  elsif value&.is_a?(String)
241
241
  _value = CGI.unescape(value.gsub("+", CGI.escape("+")))
242
+ elsif value&.is_a?(Integer)
243
+ _value = value.to_s
242
244
  end
243
245
  end
244
246
 
@@ -0,0 +1,252 @@
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
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  module HtmlGrid
4
- VERSION = "1.2.2"
4
+ VERSION = "1.2.3"
5
5
  end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module HtmlGrid
4
+ VERSION = "1.2.2"
5
+ end
@@ -162,6 +162,13 @@ class TestComponent < Minitest::Test
162
162
  assert_equal(true, comp.label?)
163
163
  end
164
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("3", result)
170
+ end
171
+
165
172
  def test_escape
166
173
  txt = "Guten Tag! & wie gehts uns denn heute? '<' schlechter oder '>' besser?"
167
174
  control = txt.dup
@@ -0,0 +1,204 @@
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! &amp; wie gehts uns denn heute? '&lt;' schlechter oder '&gt;' 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 = "&ge;"
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
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.2
4
+ version: 1.2.3
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: 2021-05-24 00:00:00.000000000 Z
11
+ date: 1980-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sbsm
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.6.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: psych
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "<"
46
+ - !ruby/object:Gem::Version
47
+ version: 4.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "<"
53
+ - !ruby/object:Gem::Version
54
+ version: 4.0.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -175,6 +189,7 @@ files:
175
189
  - lib/htmlgrid/button.rb
176
190
  - lib/htmlgrid/centeredcomposite.rb
177
191
  - lib/htmlgrid/component.rb
192
+ - lib/htmlgrid/component.rb~
178
193
  - lib/htmlgrid/composite.rb
179
194
  - lib/htmlgrid/datevalue.rb
180
195
  - lib/htmlgrid/div.rb
@@ -221,10 +236,12 @@ files:
221
236
  - lib/htmlgrid/urllink.rb
222
237
  - lib/htmlgrid/value.rb
223
238
  - lib/htmlgrid/version.rb
239
+ - lib/htmlgrid/version.rb~
224
240
  - test/stub/cgi.rb
225
241
  - test/suite.rb
226
242
  - test/test_add_row.rb
227
243
  - test/test_component.rb
244
+ - test/test_component.rb~
228
245
  - test/test_composite.rb
229
246
  - test/test_datevalue.rb
230
247
  - test/test_divlist.rb
@@ -244,7 +261,7 @@ homepage: https://github.com/zdavatz/htmlgrid/
244
261
  licenses:
245
262
  - GPL v2.1
246
263
  metadata: {}
247
- post_install_message:
264
+ post_install_message:
248
265
  rdoc_options: []
249
266
  require_paths:
250
267
  - lib
@@ -259,8 +276,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
259
276
  - !ruby/object:Gem::Version
260
277
  version: '0'
261
278
  requirements: []
262
- rubygems_version: 3.1.2
263
- signing_key:
279
+ rubygems_version: 3.3.20
280
+ signing_key:
264
281
  specification_version: 4
265
282
  summary: HtmlGrid is a Html-ToolKit for Ruby Webframeworks.
266
283
  test_files: []