htmlgrid 1.1.5 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.force_encoding('utf-8')
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
- value.to_s.gsub(@@nl2br_ptrn, '<br>')
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
@@ -5,12 +5,12 @@
5
5
 
6
6
  require 'htmlgrid/component'
7
7
  require 'htmlgrid/div'
8
- require 'htmlgrid/template'
9
8
 
10
9
  module HtmlGrid
11
10
  class Component
12
11
  @@msie_ptrn = /MSIE\s*(\d)/
13
12
  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,6 +38,9 @@ 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 '.'
41
44
  'data-dojo-type' => 'dijit/TooltipDialog',
42
45
  'data-dojo-props' => "connectId:#{css_id}",
43
46
  'id' => "#{css_id}_widget",
@@ -63,7 +66,9 @@ module HtmlGrid
63
66
  html << @dojo_tooltip.to_html(context).force_encoding('utf-8')
64
67
  end
65
68
  unless html.empty? || dojo_parse_on_load
66
- html << context.script('type' => 'text/javascript') { "dojoConfig.searchIds.push('#{css_id}')" }
69
+ html << context.script('type' => 'text/javascript') {
70
+ "dojoConfig.searchIds.push('#{css_id}')"
71
+ }
67
72
  end
68
73
  # call original dynamic_html
69
74
  dojo_dynamic_html(context) << html
@@ -72,7 +77,7 @@ module HtmlGrid
72
77
  end
73
78
  module DojoToolkit
74
79
  module DojoTemplate
75
- DOJO_DEBUG = true
80
+ DOJO_DEBUG = false
76
81
  DOJO_BACK_BUTTON = false
77
82
  DOJO_ENCODING = nil
78
83
  DOJO_PARSE_ON_LOAD = true
@@ -91,30 +96,52 @@ module HtmlGrid
91
96
  "{ name: '#{prefix}', location: '#{path}' }"
92
97
  }.join(",")
93
98
  end
94
- puts "dynamic_html_headers with pkgs: #{packages}"
95
- config =config = [
99
+ config = [
100
+ "parseOnLoad: #{self.class::DOJO_PARSE_ON_LOAD}",
101
+ "isDebug: #{self.class::DOJO_DEBUG}",
102
+ "preventBackButtonFix: #{!self.class::DOJO_BACK_BUTTON}",
103
+ "bindEncoding: '#{encoding}'",
104
+ "searchIds: []",
105
+ "urchin: ''",
96
106
  "has: {
97
- 'dojo-debug-messages': true
107
+ 'dojo-firebug': #{self.class::DOJO_DEBUG},
108
+ 'dojo-debug-messages': #{self.class::DOJO_DEBUG}
98
109
  }",
110
+ "packages: [ #{packages} ]"
99
111
  ].join(',')
100
- headers << %(<script>
101
- var dojoConfig = {
102
- parseOnLoad: true,
103
- isDebug: true,
104
- async: true,
105
- urchin: '',
106
- };
107
- </script>)
112
+ args.store('data-dojo-config', config)
113
+ args.store('src', dojo_path)
108
114
  headers << context.script(args)
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 }
115
+ args = { 'type' => 'text/javascript' }
116
+ headers << context.script(args) {
117
+ package_paths = self.class::DOJO_REQUIRE.map { |req|
118
+ "'#{req}'"
119
+ }.join(',')
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
+ "});"
114
134
  else
115
- headers << context.style(:type =>type, :src => path) { "@import \"#{path}\";" }
135
+ script = "require([#{package_paths}]);"
116
136
  end
117
- end
137
+ script
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
+ }
118
145
  headers
119
146
  end
120
147
  def dojo_parse_on_load
@@ -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
@@ -36,14 +37,10 @@ module HtmlGrid
36
37
  CSS_FILES = []
37
38
  JAVASCRIPTS = []
38
39
  @@local_doc_dir = File.join(Dir.pwd, 'doc')
39
- def get_inline(ressource)
40
+ def TemplateMethods.get_inline(ressource)
41
+ return nil unless ressource
40
42
  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
43
+ File.exist?(local_file) ? File.read(local_file) : nil
47
44
  end
48
45
  def css_link(context, path=@lookandfeel.resource(:css))
49
46
  properties = {
@@ -52,7 +49,7 @@ module HtmlGrid
52
49
  "async" => "true",
53
50
  'href' => path,
54
51
  }
55
- if (content = get_inline(path))
52
+ if (content = TemplateMethods.get_inline(path))
56
53
  properties.delete('href')
57
54
  context.style(properties) { content }
58
55
  else
@@ -60,8 +57,8 @@ module HtmlGrid
60
57
  end
61
58
  end
62
59
  def css_links(context, path=@lookandfeel.resource(:css))
63
- links = self.class.const_get(:CSS_FILES).collect { |key|
64
- css_link(context, @lookandfeel.resource(key))
60
+ links = self.class.const_get(:CSS_FILES).collect { |key|
61
+ css_link(context, @lookandfeel.resource(key))
65
62
  }
66
63
  links.push(css_link(context, path)) if(path)
67
64
  links.join
@@ -101,7 +98,7 @@ module HtmlGrid
101
98
  "language" => "JavaScript",
102
99
  "type" => "text/javascript",
103
100
  "src" => @lookandfeel.resource_global(:javascript, "#{key}.js"),
104
- }
101
+ }
105
102
  context.script(properties)
106
103
  }
107
104
  jscripts.join
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
  module HtmlGrid
4
- VERSION = '1.1.5'
4
+ VERSION = '1.2.0'
5
5
  end
@@ -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" }
@@ -27,6 +27,7 @@ $: << 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'
@@ -21,7 +21,7 @@
21
21
  # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
22
22
  # htmlgrid@ywesee.com, downloads.ywesee.com/ruby/htmlgrid
23
23
  #
24
- # TestTemplate -- htmlgrid -- 19.11.2002 -- hwyss@ywesee.com
24
+ # TestTemplate -- htmlgrid -- 19.11.2002 -- hwyss@ywesee.com
25
25
 
26
26
  $LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
27
27
  $LOAD_PATH << File.dirname(__FILE__)
@@ -73,7 +73,7 @@ class Template < HtmlGrid::Template
73
73
  },
74
74
  ]
75
75
  COMPONENTS = {
76
- [0,0] => :foo,
76
+ [0,0] => :foo,
77
77
  }
78
78
  LEGACY_INTERFACE = false
79
79
  def foo(model)
@@ -116,4 +116,7 @@ class TestTemplate < Minitest::Test
116
116
  assert(result.index(line), "#{idx} Missing: #{line} in #{result}")
117
117
  }
118
118
  end
119
+ def test_to_html_with_nil_inline
120
+ assert_nil(cpHtmlGrid::TemplateMethods.get_inline(nil))
121
+ end
119
122
  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.5
4
+ version: 1.2.0
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: 2020-06-04 00:00:00.000000000 Z
11
+ date: 2021-01-22 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,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
244
246
  - !ruby/object:Gem::Version
245
247
  version: '0'
246
248
  requirements: []
247
- rubygems_version: 3.1.2
249
+ rubygems_version: 3.2.4
248
250
  signing_key:
249
251
  specification_version: 4
250
252
  summary: HtmlGrid is a Html-ToolKit for Ruby Webframeworks.