htmlgrid 1.1.4 → 1.1.5
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 +5 -5
- data/lib/htmlgrid/dojotoolkit.rb +21 -48
- data/lib/htmlgrid/grid.rb +1 -1
- data/lib/htmlgrid/template.rb +20 -4
- data/lib/htmlgrid/version.rb +1 -1
- data/test/test_dojotoolkit.rb +58 -0
- data/test/test_template.rb +24 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: eda73d2e1ec602956e9dac7af185179cc676906adf4a34fd1a683685c391ed49
|
4
|
+
data.tar.gz: c7668593f88170c009de8cc42839d69ec24834aec487baed336152eab1f979a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c85d82f860af997c13a4c6f3298a5ac1dfc1cfff668d28842b21f0e8723c4cc35cadb19fa4990070ba6fd3d735235d2ec0d1b54585e46a91ef229e3683af5ebf
|
7
|
+
data.tar.gz: 5701ee21b4d273fcef7e6caab0af4401f8d67019aff1214327d092567fa73798690aebec32163aa890cd79eb6f4984c6e90a676eb2ffaee38fbfe7dc0137f80d
|
data/lib/htmlgrid/dojotoolkit.rb
CHANGED
@@ -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,9 +38,6 @@ 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
41
|
'data-dojo-type' => 'dijit/TooltipDialog',
|
45
42
|
'data-dojo-props' => "connectId:#{css_id}",
|
46
43
|
'id' => "#{css_id}_widget",
|
@@ -66,9 +63,7 @@ module HtmlGrid
|
|
66
63
|
html << @dojo_tooltip.to_html(context).force_encoding('utf-8')
|
67
64
|
end
|
68
65
|
unless html.empty? || dojo_parse_on_load
|
69
|
-
html << context.script('type' => 'text/javascript') {
|
70
|
-
"dojoConfig.searchIds.push('#{css_id}')"
|
71
|
-
}
|
66
|
+
html << context.script('type' => 'text/javascript') { "dojoConfig.searchIds.push('#{css_id}')" }
|
72
67
|
end
|
73
68
|
# call original dynamic_html
|
74
69
|
dojo_dynamic_html(context) << html
|
@@ -77,7 +72,7 @@ module HtmlGrid
|
|
77
72
|
end
|
78
73
|
module DojoToolkit
|
79
74
|
module DojoTemplate
|
80
|
-
DOJO_DEBUG =
|
75
|
+
DOJO_DEBUG = true
|
81
76
|
DOJO_BACK_BUTTON = false
|
82
77
|
DOJO_ENCODING = nil
|
83
78
|
DOJO_PARSE_ON_LOAD = true
|
@@ -96,52 +91,30 @@ module HtmlGrid
|
|
96
91
|
"{ name: '#{prefix}', location: '#{path}' }"
|
97
92
|
}.join(",")
|
98
93
|
end
|
99
|
-
|
100
|
-
|
101
|
-
"isDebug: #{self.class::DOJO_DEBUG}",
|
102
|
-
"preventBackButtonFix: #{!self.class::DOJO_BACK_BUTTON}",
|
103
|
-
"bindEncoding: '#{encoding}'",
|
104
|
-
"searchIds: []",
|
105
|
-
"urchin: ''",
|
94
|
+
puts "dynamic_html_headers with pkgs: #{packages}"
|
95
|
+
config =config = [
|
106
96
|
"has: {
|
107
|
-
'dojo-
|
108
|
-
'dojo-debug-messages': #{self.class::DOJO_DEBUG}
|
97
|
+
'dojo-debug-messages': true
|
109
98
|
}",
|
110
|
-
"packages: [ #{packages} ]"
|
111
99
|
].join(',')
|
112
|
-
|
113
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
115
|
+
headers << context.style(:type =>type, :src => path) { "@import \"#{path}\";" }
|
136
116
|
end
|
137
|
-
|
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
|
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
@@ -35,13 +35,29 @@ module HtmlGrid
|
|
35
35
|
LEGACY_INTERFACE = true
|
36
36
|
CSS_FILES = []
|
37
37
|
JAVASCRIPTS = []
|
38
|
+
@@local_doc_dir = File.join(Dir.pwd, 'doc')
|
39
|
+
def get_inline(ressource)
|
40
|
+
local_file = File.join(@@local_doc_dir, URI(ressource).path)
|
41
|
+
if File.exist?(local_file)
|
42
|
+
# puts "Reading #{ressource} #{local_file} #{File.size(local_file)}"
|
43
|
+
File.read(local_file)
|
44
|
+
else
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
end
|
38
48
|
def css_link(context, path=@lookandfeel.resource(:css))
|
39
49
|
properties = {
|
40
50
|
"rel" => "stylesheet",
|
41
51
|
"type" => "text/css",
|
42
|
-
"
|
52
|
+
"async" => "true",
|
53
|
+
'href' => path,
|
43
54
|
}
|
44
|
-
|
55
|
+
if (content = get_inline(path))
|
56
|
+
properties.delete('href')
|
57
|
+
context.style(properties) { content }
|
58
|
+
else
|
59
|
+
context.link(properties)
|
60
|
+
end
|
45
61
|
end
|
46
62
|
def css_links(context, path=@lookandfeel.resource(:css))
|
47
63
|
links = self.class.const_get(:CSS_FILES).collect { |key|
|
@@ -71,8 +87,8 @@ module HtmlGrid
|
|
71
87
|
context.head {
|
72
88
|
if(block_given?)
|
73
89
|
block.call
|
74
|
-
|
75
|
-
|
90
|
+
end
|
91
|
+
context.head << title(context) <<
|
76
92
|
meta_tags(context) <<
|
77
93
|
other_html_headers(context) <<
|
78
94
|
css_links(context) <<
|
data/lib/htmlgrid/version.rb
CHANGED
data/test/test_dojotoolkit.rb
CHANGED
@@ -30,6 +30,7 @@ require 'stub/cgi'
|
|
30
30
|
require 'htmlgrid/dojotoolkit'
|
31
31
|
require 'test_helper'
|
32
32
|
require 'flexmock/minitest'
|
33
|
+
require 'sbsm/lookandfeel'
|
33
34
|
|
34
35
|
class TestDojotoolkit < Minitest::Test
|
35
36
|
class StubAttributeComponent < HtmlGrid::Component
|
@@ -72,3 +73,60 @@ class TestDojotoolkit < Minitest::Test
|
|
72
73
|
assert(/href="my_tooltip"/.match(result))
|
73
74
|
end
|
74
75
|
end
|
76
|
+
class StubTemplateLookandfeel < SBSM::Lookandfeel
|
77
|
+
RESOURCES = {
|
78
|
+
:css => "test.css"
|
79
|
+
}
|
80
|
+
DICTIONARIES = {
|
81
|
+
"de" => {
|
82
|
+
:html_title => "Test",
|
83
|
+
}
|
84
|
+
}
|
85
|
+
def lookandfeel
|
86
|
+
self
|
87
|
+
end
|
88
|
+
end
|
89
|
+
class StubTemplateSession
|
90
|
+
def flavor
|
91
|
+
"gcc"
|
92
|
+
end
|
93
|
+
def language
|
94
|
+
"de"
|
95
|
+
end
|
96
|
+
def http_protocol
|
97
|
+
'http'
|
98
|
+
end
|
99
|
+
def server_name
|
100
|
+
"testserver.com"
|
101
|
+
end
|
102
|
+
def server_port
|
103
|
+
'80'
|
104
|
+
end
|
105
|
+
alias :default_language :language
|
106
|
+
end
|
107
|
+
class PublicTemplate < HtmlGrid::Template
|
108
|
+
include HtmlGrid::DojoToolkit::DojoTemplate
|
109
|
+
COMPONENTS = {}
|
110
|
+
def dynamic_html_headers(context)
|
111
|
+
headers = super
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
class TestTemplate < Minitest::Test
|
116
|
+
def setup
|
117
|
+
lookandfeel = StubTemplateLookandfeel.new(StubTemplateSession.new)
|
118
|
+
@template = PublicTemplate.new(nil, lookandfeel, nil)
|
119
|
+
end
|
120
|
+
def test_dynamic_html_headers
|
121
|
+
@cgi = CGI.new
|
122
|
+
result = @template.to_html(@cgi)
|
123
|
+
@session = flexmock('session')
|
124
|
+
comp = HtmlGrid::Component.new("foo", @session)
|
125
|
+
comp.dojo_tooltip = 'my_tooltip'
|
126
|
+
assert_equal("foo", comp.model)
|
127
|
+
assert_equal(false, comp.label?)
|
128
|
+
result= comp.to_html(@cgi)
|
129
|
+
skip 'tooltip test does not work'
|
130
|
+
assert(/href="my_tooltip"/.match(result))
|
131
|
+
end
|
132
|
+
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.5
|
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-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sbsm
|
@@ -244,8 +244,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
244
244
|
- !ruby/object:Gem::Version
|
245
245
|
version: '0'
|
246
246
|
requirements: []
|
247
|
-
|
248
|
-
rubygems_version: 2.6.8
|
247
|
+
rubygems_version: 3.1.2
|
249
248
|
signing_key:
|
250
249
|
specification_version: 4
|
251
250
|
summary: HtmlGrid is a Html-ToolKit for Ruby Webframeworks.
|