htmlgrid 1.1.4 → 1.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/TooltipDialog.txt +73 -0
- data/interaction_no_inline.txt +1216 -0
- data/lib/htmlgrid/component.rb +9 -7
- data/lib/htmlgrid/grid.rb +1 -1
- data/lib/htmlgrid/template.rb +20 -8
- data/lib/htmlgrid/version.rb +1 -1
- data/test/test_component.rb +48 -0
- data/test/test_dojotoolkit.rb +59 -0
- data/test/test_template.rb +24 -1
- metadata +5 -4
data/lib/htmlgrid/component.rb
CHANGED
@@ -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
|
@@ -214,16 +214,18 @@ module HtmlGrid
|
|
214
214
|
@attributes.store('tabIndex', tab.to_s)
|
215
215
|
end
|
216
216
|
def to_html(context)
|
217
|
-
_to_html(context, @value).to_s.
|
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)
|
221
221
|
if(value.is_a?(Array))
|
222
222
|
value.collect { |item| _to_html(context, item) }.join(' ')
|
223
223
|
elsif(value.respond_to?(:to_html))
|
224
|
-
value.to_html(context).to_s.force_encoding('utf-8')
|
224
|
+
value.to_html(context).to_s.dup.force_encoding('utf-8')
|
225
225
|
else
|
226
|
-
|
226
|
+
if value && value.is_a?(String)
|
227
|
+
value =CGI.unescape(value.gsub('+', CGI.escape('+')))
|
228
|
+
end
|
227
229
|
end
|
228
230
|
end
|
229
231
|
private
|
data/lib/htmlgrid/grid.rb
CHANGED
@@ -86,7 +86,7 @@ module HtmlGrid
|
|
86
86
|
html = ''
|
87
87
|
@components.each { |component|
|
88
88
|
if component.respond_to? :to_html
|
89
|
-
html << component.to_html(cgi).to_s.force_encoding('utf-8')
|
89
|
+
html << component.to_html(cgi).to_s.dup.force_encoding('utf-8')
|
90
90
|
else
|
91
91
|
html << component.to_s
|
92
92
|
end
|
data/lib/htmlgrid/template.rb
CHANGED
@@ -22,9 +22,10 @@
|
|
22
22
|
# ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
|
23
23
|
# htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
|
24
24
|
#
|
25
|
-
# Template -- htmlgrid -- 19.11.2002 -- hwyss@ywesee.com
|
25
|
+
# Template -- htmlgrid -- 19.11.2002 -- hwyss@ywesee.com
|
26
26
|
|
27
27
|
require 'htmlgrid/composite'
|
28
|
+
require 'uri'
|
28
29
|
|
29
30
|
module HtmlGrid
|
30
31
|
module TemplateMethods
|
@@ -35,17 +36,28 @@ module HtmlGrid
|
|
35
36
|
LEGACY_INTERFACE = true
|
36
37
|
CSS_FILES = []
|
37
38
|
JAVASCRIPTS = []
|
39
|
+
@@local_doc_dir = File.join(Dir.pwd, 'doc')
|
40
|
+
def TemplateMethods.get_inline(ressource)
|
41
|
+
local_file = File.join(@@local_doc_dir, URI(ressource).path)
|
42
|
+
File.exist?(local_file) ? File.read(local_file) : nil
|
43
|
+
end
|
38
44
|
def css_link(context, path=@lookandfeel.resource(:css))
|
39
45
|
properties = {
|
40
46
|
"rel" => "stylesheet",
|
41
47
|
"type" => "text/css",
|
42
|
-
"
|
48
|
+
"async" => "true",
|
49
|
+
'href' => path,
|
43
50
|
}
|
44
|
-
|
51
|
+
if (content = TemplateMethods.get_inline(path))
|
52
|
+
properties.delete('href')
|
53
|
+
context.style(properties) { content }
|
54
|
+
else
|
55
|
+
context.link(properties)
|
56
|
+
end
|
45
57
|
end
|
46
58
|
def css_links(context, path=@lookandfeel.resource(:css))
|
47
|
-
links = self.class.const_get(:CSS_FILES).collect { |key|
|
48
|
-
css_link(context, @lookandfeel.resource(key))
|
59
|
+
links = self.class.const_get(:CSS_FILES).collect { |key|
|
60
|
+
css_link(context, @lookandfeel.resource(key))
|
49
61
|
}
|
50
62
|
links.push(css_link(context, path)) if(path)
|
51
63
|
links.join
|
@@ -71,8 +83,8 @@ module HtmlGrid
|
|
71
83
|
context.head {
|
72
84
|
if(block_given?)
|
73
85
|
block.call
|
74
|
-
|
75
|
-
|
86
|
+
end
|
87
|
+
context.head << title(context) <<
|
76
88
|
meta_tags(context) <<
|
77
89
|
other_html_headers(context) <<
|
78
90
|
css_links(context) <<
|
@@ -85,7 +97,7 @@ module HtmlGrid
|
|
85
97
|
"language" => "JavaScript",
|
86
98
|
"type" => "text/javascript",
|
87
99
|
"src" => @lookandfeel.resource_global(:javascript, "#{key}.js"),
|
88
|
-
}
|
100
|
+
}
|
89
101
|
context.script(properties)
|
90
102
|
}
|
91
103
|
jscripts.join
|
data/lib/htmlgrid/version.rb
CHANGED
data/test/test_component.rb
CHANGED
@@ -25,9 +25,11 @@
|
|
25
25
|
|
26
26
|
$: << File.expand_path("../lib", File.dirname(__FILE__))
|
27
27
|
$: << File.expand_path("../ext", File.dirname(__FILE__))
|
28
|
+
$: << File.dirname(__FILE__)
|
28
29
|
|
29
30
|
require 'minitest/autorun'
|
30
31
|
require 'htmlgrid/component'
|
32
|
+
require 'stub/cgi'
|
31
33
|
|
32
34
|
module HtmlGrid
|
33
35
|
class Component
|
@@ -36,6 +38,9 @@ module HtmlGrid
|
|
36
38
|
end
|
37
39
|
|
38
40
|
class TestComponent < Minitest::Test
|
41
|
+
STRING_WITH_SHARP = "Test_#_gartenhat"
|
42
|
+
STRING_WITH_PLUS = "Test_+_plus"
|
43
|
+
STRING_WITH_UMLAUT = "Test_with_Umlaut_üé"
|
39
44
|
class StubAttributeComponent < HtmlGrid::Component
|
40
45
|
HTML_ATTRIBUTES = { "key" => "val" }
|
41
46
|
end
|
@@ -51,6 +56,14 @@ class TestComponent < Minitest::Test
|
|
51
56
|
class StubContainer
|
52
57
|
attr_accessor :onsubmit
|
53
58
|
end
|
59
|
+
class ToHTMLreturnFrozen
|
60
|
+
def initialize content
|
61
|
+
@content = content
|
62
|
+
end
|
63
|
+
def to_html(what)
|
64
|
+
return @content.to_s.freeze
|
65
|
+
end
|
66
|
+
end
|
54
67
|
def setup
|
55
68
|
@component = HtmlGrid::Component.new(nil, nil)
|
56
69
|
end
|
@@ -71,6 +84,41 @@ class TestComponent < Minitest::Test
|
|
71
84
|
assert_equal("bar", comp.session)
|
72
85
|
assert_equal("baz", comp.container)
|
73
86
|
end
|
87
|
+
def test_to_html
|
88
|
+
comp = HtmlGrid::Component.new("foo", "bar", "baz").to_html(CGI.new)
|
89
|
+
assert_equal("", comp)
|
90
|
+
end
|
91
|
+
# Next is test for https://github.com/zdavatz/oddb.org/issues/118 FrozenError at /de/just-medical
|
92
|
+
def test_to_html_frozen_empty
|
93
|
+
comp = HtmlGrid::Component.new('context')
|
94
|
+
comp.value = ToHTMLreturnFrozen.new('')
|
95
|
+
result = comp.to_html(CGI.new)
|
96
|
+
assert_equal('', result)
|
97
|
+
end
|
98
|
+
def test_gartenhag_to_html
|
99
|
+
comp = HtmlGrid::Component.new('context')
|
100
|
+
comp.value = STRING_WITH_SHARP
|
101
|
+
result = comp.to_html(CGI.new)
|
102
|
+
assert_equal(STRING_WITH_SHARP, result)
|
103
|
+
end
|
104
|
+
def test_minus_to_html
|
105
|
+
comp = HtmlGrid::Component.new('context')
|
106
|
+
comp.value = STRING_WITH_PLUS
|
107
|
+
result = comp.to_html(CGI.new)
|
108
|
+
assert_equal(STRING_WITH_PLUS, result)
|
109
|
+
end
|
110
|
+
def test_umlaut_to_html
|
111
|
+
comp = HtmlGrid::Component.new('context')
|
112
|
+
comp.value = STRING_WITH_UMLAUT
|
113
|
+
result = comp.to_html(CGI.new)
|
114
|
+
assert_equal(STRING_WITH_UMLAUT, result)
|
115
|
+
end
|
116
|
+
def test_escaped_STRING_WITH_UMLAUT_to_html
|
117
|
+
comp = HtmlGrid::Component.new('context')
|
118
|
+
comp.value =CGI.escape(STRING_WITH_UMLAUT)
|
119
|
+
result = comp.to_html(CGI.new)
|
120
|
+
assert_equal(STRING_WITH_UMLAUT, result)
|
121
|
+
end
|
74
122
|
def test_initialize3
|
75
123
|
comp = StubAttributeComponent.new("foo", "bar")
|
76
124
|
expected = { "key" => "val" }
|
data/test/test_dojotoolkit.rb
CHANGED
@@ -27,9 +27,11 @@ $: << File.dirname(__FILE__)
|
|
27
27
|
|
28
28
|
require 'minitest/autorun'
|
29
29
|
require 'stub/cgi'
|
30
|
+
require 'htmlgrid/template'
|
30
31
|
require 'htmlgrid/dojotoolkit'
|
31
32
|
require 'test_helper'
|
32
33
|
require 'flexmock/minitest'
|
34
|
+
require 'sbsm/lookandfeel'
|
33
35
|
|
34
36
|
class TestDojotoolkit < Minitest::Test
|
35
37
|
class StubAttributeComponent < HtmlGrid::Component
|
@@ -72,3 +74,60 @@ class TestDojotoolkit < Minitest::Test
|
|
72
74
|
assert(/href="my_tooltip"/.match(result))
|
73
75
|
end
|
74
76
|
end
|
77
|
+
class StubTemplateLookandfeel < SBSM::Lookandfeel
|
78
|
+
RESOURCES = {
|
79
|
+
:css => "test.css"
|
80
|
+
}
|
81
|
+
DICTIONARIES = {
|
82
|
+
"de" => {
|
83
|
+
:html_title => "Test",
|
84
|
+
}
|
85
|
+
}
|
86
|
+
def lookandfeel
|
87
|
+
self
|
88
|
+
end
|
89
|
+
end
|
90
|
+
class StubTemplateSession
|
91
|
+
def flavor
|
92
|
+
"gcc"
|
93
|
+
end
|
94
|
+
def language
|
95
|
+
"de"
|
96
|
+
end
|
97
|
+
def http_protocol
|
98
|
+
'http'
|
99
|
+
end
|
100
|
+
def server_name
|
101
|
+
"testserver.com"
|
102
|
+
end
|
103
|
+
def server_port
|
104
|
+
'80'
|
105
|
+
end
|
106
|
+
alias :default_language :language
|
107
|
+
end
|
108
|
+
class PublicTemplate < HtmlGrid::Template
|
109
|
+
include HtmlGrid::DojoToolkit::DojoTemplate
|
110
|
+
COMPONENTS = {}
|
111
|
+
def dynamic_html_headers(context)
|
112
|
+
headers = super
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
class TestTemplate < Minitest::Test
|
117
|
+
def setup
|
118
|
+
lookandfeel = StubTemplateLookandfeel.new(StubTemplateSession.new)
|
119
|
+
@template = PublicTemplate.new(nil, lookandfeel, nil)
|
120
|
+
end
|
121
|
+
def test_dynamic_html_headers
|
122
|
+
@cgi = CGI.new
|
123
|
+
result = @template.to_html(@cgi)
|
124
|
+
@session = flexmock('session')
|
125
|
+
comp = HtmlGrid::Component.new("foo", @session)
|
126
|
+
comp.dojo_tooltip = 'my_tooltip'
|
127
|
+
assert_equal("foo", comp.model)
|
128
|
+
assert_equal(false, comp.label?)
|
129
|
+
result= comp.to_html(@cgi)
|
130
|
+
skip 'tooltip test does not work'
|
131
|
+
assert(/href="my_tooltip"/.match(result))
|
132
|
+
end
|
133
|
+
end
|
data/test/test_template.rb
CHANGED
@@ -28,6 +28,7 @@ $LOAD_PATH << File.dirname(__FILE__)
|
|
28
28
|
|
29
29
|
require 'minitest'
|
30
30
|
require 'minitest/autorun'
|
31
|
+
require 'flexmock/minitest'
|
31
32
|
require 'stub/cgi'
|
32
33
|
require 'sbsm/lookandfeel'
|
33
34
|
require 'htmlgrid/template'
|
@@ -44,6 +45,9 @@ class StubTemplateSession
|
|
44
45
|
end
|
45
46
|
def server_name
|
46
47
|
"testserver.com"
|
48
|
+
end
|
49
|
+
def server_port
|
50
|
+
'80'
|
47
51
|
end
|
48
52
|
alias :default_language :language
|
49
53
|
end
|
@@ -60,6 +64,7 @@ class StubTemplateLookandfeel < SBSM::Lookandfeel
|
|
60
64
|
self
|
61
65
|
end
|
62
66
|
end
|
67
|
+
|
63
68
|
class Template < HtmlGrid::Template
|
64
69
|
META_TAGS = [
|
65
70
|
{
|
@@ -86,11 +91,29 @@ class TestTemplate < Minitest::Test
|
|
86
91
|
result << @template.to_html(CGI.new)
|
87
92
|
expected = [
|
88
93
|
'<TITLE>Test</TITLE>',
|
89
|
-
|
94
|
+
'<LINK rel="stylesheet" type="text/css" async="true" href="http://testserver.com:80/resources/gcc/test.css">',
|
90
95
|
'<META http-equiv="robots" content="follow, index">',
|
91
96
|
]
|
92
97
|
expected.each_with_index { |line, idx|
|
93
98
|
assert(result.index(line), "#{idx} Missing: #{line} in #{result}")
|
94
99
|
}
|
95
100
|
end
|
101
|
+
def test_to_html_with_inline_css
|
102
|
+
@lookandfeel = flexmock('lnf', StubTemplateLookandfeel.new(StubTemplateSession.new))
|
103
|
+
@lookandfeel.should_receive(:resource).with(:css).and_return('test/inline.css')
|
104
|
+
@lookandfeel.should_receive(:lookup).with(:html_title).and_return('html_title').by_default
|
105
|
+
@lookandfeel.should_receive(:lookup).with(any).and_return(nil).by_default
|
106
|
+
@template = Template.new(nil, @lookandfeel, nil)
|
107
|
+
result = ""
|
108
|
+
result << @template.to_html(CGI.new)
|
109
|
+
expected = [
|
110
|
+
'<TITLE>html_title</TITLE>',
|
111
|
+
'this is a dummy CSS file, which should be inlined',
|
112
|
+
'<STYLE rel="stylesheet" type="text/css" async="true">',
|
113
|
+
'<META http-equiv="robots" content="follow, index">',
|
114
|
+
]
|
115
|
+
expected.each_with_index { |line, idx|
|
116
|
+
assert(result.index(line), "#{idx} Missing: #{line} in #{result}")
|
117
|
+
}
|
118
|
+
end
|
96
119
|
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.1.
|
4
|
+
version: 1.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masaomi Hatakeyama, Zeno R.R. Davatz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sbsm
|
@@ -157,6 +157,8 @@ extensions: []
|
|
157
157
|
extra_rdoc_files: []
|
158
158
|
files:
|
159
159
|
- Manifest.txt
|
160
|
+
- TooltipDialog.txt
|
161
|
+
- interaction_no_inline.txt
|
160
162
|
- lib/htmlgrid/booleanvalue.rb
|
161
163
|
- lib/htmlgrid/button.rb
|
162
164
|
- lib/htmlgrid/centeredcomposite.rb
|
@@ -244,8 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
244
246
|
- !ruby/object:Gem::Version
|
245
247
|
version: '0'
|
246
248
|
requirements: []
|
247
|
-
|
248
|
-
rubygems_version: 2.6.8
|
249
|
+
rubygems_version: 3.1.2
|
249
250
|
signing_key:
|
250
251
|
specification_version: 4
|
251
252
|
summary: HtmlGrid is a Html-ToolKit for Ruby Webframeworks.
|