htmlgrid 1.1.2 → 1.1.7

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,7 +214,7 @@ 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)
@@ -223,7 +223,7 @@ module HtmlGrid
223
223
  elsif(value.respond_to?(:to_html))
224
224
  value.to_html(context).to_s.force_encoding('utf-8')
225
225
  else
226
- value.to_s.gsub(@@nl2br_ptrn, '<br>')
226
+ value =CGI.unescape(value) if value && value.is_a?(String)
227
227
  end
228
228
  end
229
229
  private
@@ -51,6 +51,21 @@ module HtmlGrid
51
51
  CSS_ID = nil
52
52
  DEFAULT_CLASS = Value
53
53
  LOOKANDFEEL_MAP = {}
54
+
55
+ def self.component(klass, key, name=nil)
56
+ methname = klass.to_s.downcase.gsub('::', '_') << '_' << key.to_s
57
+ define_method(methname) { |*args|
58
+ model, session = args
59
+ args = [model.send(key), session || @session, self]
60
+ if(name)
61
+ args.unshift(name)
62
+ lookandfeel_map.store(methname.to_sym, name.to_sym)
63
+ end
64
+ klass.new(*args)
65
+ }
66
+ methname.to_sym
67
+ end
68
+
54
69
  def init
55
70
  super
56
71
  setup_grid()
@@ -102,19 +117,6 @@ module HtmlGrid
102
117
  def symbol_map
103
118
  @symbol_map ||= self::class::SYMBOL_MAP.dup
104
119
  end
105
- def AbstractComposite.component(klass, key, name=nil)
106
- methname = klass.to_s.downcase.gsub('::', '_') << '_' << key.to_s
107
- define_method(methname) { |*args|
108
- model, session = args
109
- args = [model.send(key), session, self]
110
- if(name)
111
- args.unshift(name)
112
- lookandfeel_map.store(methname.to_sym, name.to_sym)
113
- end
114
- klass.new(*args)
115
- }
116
- methname.to_sym
117
- end
118
120
  end
119
121
  class TagComposite < AbstractComposite
120
122
  def compose(model=@model)
@@ -41,21 +41,22 @@ module HtmlGrid
41
41
  # NOTE:
42
42
  # DOJO >= 1.8 has support for type name separated by '/'
43
43
  # but, <= 1.7 must be separated with '.'
44
- 'data-dojo-type' => 'dijit.Tooltip',
45
- 'data-dojo-props' => "connectId:'#{css_id}'",
44
+ 'data-dojo-type' => 'dijit/TooltipDialog',
45
+ 'data-dojo-props' => "connectId:#{css_id}",
46
46
  'id' => "#{css_id}_widget",
47
47
  'style' => 'display: none',
48
48
  }
49
- unless match = @@msie_ptrn.match(@session.user_agent) \
49
+ unless (match = @@msie_ptrn.match(@session.user_agent)) \
50
50
  && match[1].to_i < 7
51
51
  attrs.update({
52
52
  'toggle' => 'fade',
53
53
  'toggleDuration' => '500',
54
54
  })
55
55
  end
56
+ @dojo_tooltip ||= nil
56
57
  if @dojo_tooltip.is_a?(String)
57
58
  if @dojo_tooltip !~ /^http/ # e.g. javascript
58
- attrs.store('href', "'#@dojo_tooltip'")
59
+ attrs.store('href', "#@dojo_tooltip")
59
60
  else
60
61
  attrs.store('href', @dojo_tooltip)
61
62
  end
@@ -101,7 +102,6 @@ module HtmlGrid
101
102
  "preventBackButtonFix: #{!self.class::DOJO_BACK_BUTTON}",
102
103
  "bindEncoding: '#{encoding}'",
103
104
  "searchIds: []",
104
- "async: true",
105
105
  "urchin: ''",
106
106
  "has: {
107
107
  'dojo-firebug': #{self.class::DOJO_DEBUG},
@@ -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
@@ -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
- "href" => path,
48
+ "async" => "true",
49
+ 'href' => path,
43
50
  }
44
- context.link(properties)
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
- end.to_s <<
75
- title(context) <<
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
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
  module HtmlGrid
4
- VERSION = '1.1.2'
4
+ VERSION = '1.1.7'
5
5
  end
@@ -21,13 +21,15 @@
21
21
  # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Zuerich, Switzerland
22
22
  # htmlgrid@ywesee.com, www.ywesee.com/htmlgrid
23
23
  #
24
- # TestComponent -- htmlgrid -- 26.11.2002 -- hwyss@ywesee.com
24
+ # TestComponent -- htmlgrid -- 26.11.2002 -- hwyss@ywesee.com
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,7 @@ module HtmlGrid
36
38
  end
37
39
 
38
40
  class TestComponent < Minitest::Test
41
+ STRING_WITH_UMLAUT = "Test_with_Umlaut_üé"
39
42
  class StubAttributeComponent < HtmlGrid::Component
40
43
  HTML_ATTRIBUTES = { "key" => "val" }
41
44
  end
@@ -59,7 +62,7 @@ class TestComponent < Minitest::Test
59
62
  comp = HtmlGrid::Component.new("foo", "bar")
60
63
  assert_equal("foo", comp.model)
61
64
  assert_equal("bar", comp.session)
62
- assert_equal(nil, comp.container)
65
+ assert_nil(comp.container)
63
66
  assert_equal(false, comp.label?)
64
67
  comp.label = true
65
68
  assert_equal(true, comp.label?)
@@ -71,6 +74,22 @@ class TestComponent < Minitest::Test
71
74
  assert_equal("bar", comp.session)
72
75
  assert_equal("baz", comp.container)
73
76
  end
77
+ def test_to_html
78
+ comp = HtmlGrid::Component.new("foo", "bar", "baz").to_html(CGI.new)
79
+ assert_equal("", comp)
80
+ end
81
+ def test_umlaut_to_html
82
+ comp = HtmlGrid::Component.new('context')
83
+ comp.value = STRING_WITH_UMLAUT
84
+ result = comp.to_html(CGI.new)
85
+ assert_equal(STRING_WITH_UMLAUT, result)
86
+ end
87
+ def test_escaped_STRING_WITH_UMLAUT_to_html
88
+ comp = HtmlGrid::Component.new('context')
89
+ comp.value =CGI.escape(STRING_WITH_UMLAUT)
90
+ result = comp.to_html(CGI.new)
91
+ assert_equal(STRING_WITH_UMLAUT, result)
92
+ end
74
93
  def test_initialize3
75
94
  comp = StubAttributeComponent.new("foo", "bar")
76
95
  expected = { "key" => "val" }
@@ -88,6 +88,9 @@ module CompositeTest
88
88
  public :labels?
89
89
  end
90
90
  class StubCompositeModel
91
+ def qux
92
+ 'qux'
93
+ end
91
94
  end
92
95
  class StubCompositeLookandfeel
93
96
  def event_url(one)
@@ -109,6 +112,9 @@ module CompositeTest
109
112
  def error(key)
110
113
  end
111
114
  end
115
+
116
+ class StubCompositeSession2 < StubCompositeSession; end
117
+
112
118
  class StubCompositeForm < HtmlGrid::Form
113
119
  COMPONENTS = {
114
120
  [0, 0] => StubComposite
@@ -141,6 +147,23 @@ module CompositeTest
141
147
  @composite = StubComposite.new(
142
148
  StubCompositeModel.new, StubCompositeSession.new)
143
149
  end
150
+
151
+ def test_component_session_fallback_assignment_without_session_argment
152
+ StubComposite.component(StubComposite, :qux)
153
+ model = StubCompositeModel.new
154
+ session1 = StubCompositeSession.new
155
+ composite = StubComposite.new(model, session1)
156
+ # via instance variable (without argument)
157
+ composite = composite.compositetest_stubcomposite_qux(model)
158
+ assert_kind_of(StubCompositeSession, composite.session)
159
+ assert_equal(session1, composite.session)
160
+ # via argument
161
+ session2 = StubCompositeSession2.new
162
+ composite = composite.compositetest_stubcomposite_qux(model, session2)
163
+ assert_kind_of(StubCompositeSession2, composite.session)
164
+ assert_equal(session2, composite.session)
165
+ end
166
+
144
167
  def test_create_method
145
168
  foo = nil
146
169
  foo = @composite.create(:foo, @composite.model)
@@ -155,13 +178,13 @@ module CompositeTest
155
178
  composite = StubCompositeColspan1.new(
156
179
  StubCompositeModel.new, StubCompositeSession.new)
157
180
  composite.full_colspan
158
- assert_equal(nil, composite.full_colspan)
181
+ assert_nil(composite.full_colspan)
159
182
  end
160
183
  def test_full_colspan2
161
184
  composite = StubCompositeColspan2.new(
162
185
  StubCompositeModel.new, StubCompositeSession.new)
163
186
  composite.full_colspan
164
- assert_equal(nil, composite.full_colspan)
187
+ assert_nil(composite.full_colspan)
165
188
  end
166
189
  def test_full_colspan3
167
190
  composite = StubCompositeColspan3.new(
@@ -221,9 +244,7 @@ module CompositeTest
221
244
  table = StubComposite4.new(
222
245
  StubCompositeModel.new, StubCompositeSession.new)
223
246
  assert_equal(<<-EXP.gsub(/\n|^\s*/, ''), table.to_html(CGI.new))
224
- <TABLE cellspacing="0">
225
- <TR><TD><A class="standard">brafoo</A></TD></TR>
226
- </TABLE>
247
+ <TABLE cellspacing=\"0\"><TR><TD class=\"dradnats\"><A class=\"standard\">brafoo</A></TD></TR></TABLE>
227
248
  EXP
228
249
  end
229
250
  def test_to_back
@@ -0,0 +1,132 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # HtmlGrid -- HyperTextMarkupLanguage Framework
4
+ # Copyright (C) 2003 ywesee - intellectual capital connected
5
+ # Andreas Schrafl, Benjamin Fay, Hannes Wyss, Markus Huggler
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
+
25
+ $: << File.expand_path('../lib', File.dirname(__FILE__))
26
+ $: << File.dirname(__FILE__)
27
+
28
+ require 'minitest/autorun'
29
+ require 'stub/cgi'
30
+ require 'htmlgrid/dojotoolkit'
31
+ require 'test_helper'
32
+ require 'flexmock/minitest'
33
+ require 'sbsm/lookandfeel'
34
+
35
+ class TestDojotoolkit < Minitest::Test
36
+ class StubAttributeComponent < HtmlGrid::Component
37
+ HTML_ATTRIBUTES = { "key" => "val" }
38
+ end
39
+ class StubInitComponent < HtmlGrid::Component
40
+ attr_reader :init_called
41
+ def init
42
+ @init_called = true
43
+ end
44
+ end
45
+ class StubLabelComponent < HtmlGrid::Component
46
+ LABEL = true
47
+ end
48
+ class StubContainer
49
+ attr_accessor :onsubmit
50
+ end
51
+ def setup
52
+ @component = HtmlGrid::Component.new(nil, nil)
53
+ @session = flexmock('session') do |s|
54
+ s.should_receive(:user_agent).and_return('user_agent').by_default
55
+ end
56
+ @cgi = CGI.new
57
+ end
58
+ def test_dynamic_html
59
+ comp = HtmlGrid::Component.new("foo", @session)
60
+ comp.dojo_tooltip = 'my_tooltip'
61
+ assert_equal("foo", comp.model)
62
+ assert_equal(false, comp.label?)
63
+ result= comp.dynamic_html(@cgi)
64
+ assert(/href="my_tooltip"/.match(result))
65
+ end
66
+ def test_dynamic_html_with_msie
67
+ @session.should_receive(:user_agent).and_return('MSIE 4')
68
+ comp = HtmlGrid::Component.new("foo", @session)
69
+ comp.dojo_tooltip = 'my_tooltip'
70
+ assert_equal("foo", comp.model)
71
+ assert_equal(false, comp.label?)
72
+ result= comp.dynamic_html(@cgi)
73
+ assert(/href="my_tooltip"/.match(result))
74
+ end
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