Class: HtmlGrid::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/htmlgrid/component.rb,
lib/htmlgrid/dojotoolkit.rb

Constant Summary collapse

CSS_CLASS =

sets the ‘class’ html-attribute

nil
CSS_ID =

sets the ‘id’ html-attribute

nil
HTML_ATTRIBUTES =

other html-attributes

{}
HTTP_HEADERS =

default http-headers

{
  "Content-Type"  => "text/html",
  "Cache-Control" => "no-cache, max-age=3600, must-revalidate",
}
LABEL =

precede instances of this class with a label?

false
@@html_entities =
[
	['&', 'amp'],
	['<', 'lt'],
	['>', 'gt'],
]
@@symbol_entities =

:nodoc:

{
	34	=>	"forall",
	36	=>	"exist",
	42	=>	"lowast",
	45	=>	"minus",
	64	=>	"cong",
	65	=>	"Alpha",				97	=>	"alpha",
	66	=>	"Beta",     		98	=>	"beta",
	67	=>	"Chi",      		99	=>	"chi",
	68	=>	"Delta",    		100	=>	"delta",
	69	=>	"Epsilon",  		101	=>	"epsilon",
	70	=>	"Phi",      		102	=>	"phi",
	71	=>	"Gamma",    		103	=>	"gamma",
	72	=>	"Eta",      		104	=>	"eta",
	73	=>	"Iota",     		105	=>	"iota",
	75	=>	"Kappa",    		107	=>	"kappa",
	76	=>	"Lambda",   		108	=>	"lambda",
	77	=>	"Mu",       		109	=>	"mu",
	78	=>	"Nu",       		110	=>	"nu",
	79	=>	"Omicron",  		111	=>	"omicron",
	80	=>	"Pi",       		112	=>	"pi",
	81	=>	"Theta",    		113	=>	"theta",
	82	=>	"Rho",      		114	=>	"rho",
	83	=>	"Sigma",    		115	=>	"sigma",
	84	=>	"Tau",      		116	=>	"tau",
	85	=>	"Upsilon",  		117	=>	"upsilon",
	86	=>	"sigmaf",
	87	=>	"Omega",    		119	=>	"omega",
	88	=>	"Xi",       		120	=>	"xi",
	89	=>	"Psi",      		121	=>	"psi",
	90	=>	"Zeta",     		122	=>	"zeta",
	94	=>	"perp",					126	=>	"sim",
                          	163	=>	"le",
													165	=>	"infin",
													166	=>	"fnof",
													171	=>	"harr",
													172	=>	"larr",
													173	=>	"uarr",
													174	=>	"rarr",
													175	=>	"darr",
													179	=>	"ge",
													181	=>	"prop",
													182	=>	"part",
													185	=>	"ne",
													186	=>	"equiv",
													187	=>	"asymp",
													191	=>	"crarr",
													196	=>	"otimes",
													197	=>	"oplus",
													198	=>	"empty",
													199	=>	"cap",
													200	=>	"cup",
													201	=>	"sup",
													202	=>	"supe",
													203	=>	"nsub",
													204	=>	"sub",
													205	=>	"sube",
													206	=>	"isin",
													207	=>	"notin",
													208	=>	"ang",
													209	=>	"nabla",
													213	=>	"prod",
													214	=>	"radic",
													215	=>	"sdot",
													217	=>	"and",
													218	=>	"or",
													219	=>	"hArr",
													220	=>	"lArr",
													221	=>	"uArr",
													222	=>	"rArr",
													223	=>	"dArr",
													229	=>	"sum",
													242	=>	"int",
}
@@nl2br_ptrn =
/(\r\n)|(\n)|(\r)/
@@msie_ptrn =
/MSIE\s*(\d)/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, session = nil, container = nil) ⇒ Component

Returns a new instance of Component.



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/htmlgrid/component.rb', line 125

def initialize(model, session=nil, container=nil)
	@model = model
	@session = session
	@lookandfeel = session.lookandfeel if session.respond_to?(:lookandfeel)
	@container = container
	@attributes = self::class::HTML_ATTRIBUTES.dup
	if(css_class())
		@attributes.store("class", css_class())
	end
	if(css_id())
		@attributes.store("id", css_id())
	end
	@value = nil
	@label = self::class::LABEL
	init()
end

Instance Attribute Details

#attributesObject (readonly)

:nodoc:



123
124
125
# File 'lib/htmlgrid/component.rb', line 123

def attributes
  @attributes
end

#dojo_tooltipObject

Returns the value of attribute dojo_tooltip.



12
13
14
# File 'lib/htmlgrid/dojotoolkit.rb', line 12

def dojo_tooltip
  @dojo_tooltip
end

#modelObject (readonly)

:nodoc:



123
124
125
# File 'lib/htmlgrid/component.rb', line 123

def model
  @model
end

#valueObject

Returns the value of attribute value.



124
125
126
# File 'lib/htmlgrid/component.rb', line 124

def value
  @value
end

Instance Method Details

#_to_html(context, value = @value) ⇒ Object



220
221
222
223
224
225
226
227
228
229
230
# File 'lib/htmlgrid/component.rb', line 220

def _to_html(context, value=@value)
	if(value.is_a?(Array))
		value.collect { |item| _to_html(context, item) }.join(' ')
	elsif(value.respond_to?(:to_html))
		value.to_html(context).to_s.dup.force_encoding('utf-8')
	else
      if value && value.is_a?(String)
        value =CGI.unescape(value.gsub('+', CGI.escape('+')))
      end
	end
end

#autofill?Boolean

delegator to @container, default definition in Form

Returns:

  • (Boolean)


142
143
144
# File 'lib/htmlgrid/component.rb', line 142

def autofill?
	@container.autofill? if @container.respond_to?(:autofill?)
end

#css_classObject

gets the ‘class’ html-attribute if defined



146
147
148
# File 'lib/htmlgrid/component.rb', line 146

def css_class
	@css_class ||= self::class::CSS_CLASS
end

#css_class=(css_class) ⇒ Object

sets the ‘class’ html-attribute



150
151
152
# File 'lib/htmlgrid/component.rb', line 150

def css_class=(css_class)
	@css_class = @attributes['class'] = css_class
end

#css_idObject

gets the ‘id’ html-attribute if defined



154
155
156
# File 'lib/htmlgrid/component.rb', line 154

def css_id
	@css_id ||= self::class::CSS_ID
end

#css_id=(css_id) ⇒ Object

sets the ‘id’ html-attribute



158
159
160
# File 'lib/htmlgrid/component.rb', line 158

def css_id=(css_id)
	@css_id = @attributes['id'] = css_id
end

#dojo_dynamic_htmlObject



37
38
39
# File 'lib/htmlgrid/dojotoolkit.rb', line 37

def dynamic_html(context)
	''
end

#dojo_parse_on_loadObject



31
32
33
34
35
# File 'lib/htmlgrid/dojotoolkit.rb', line 31

def dojo_parse_on_load
  if @container.respond_to?(:dojo_parse_on_load)
    @container.dojo_parse_on_load
  end
end

#dojo_tag(widget, args = {}, inner_html = '') ⇒ Object

DOJO_VERSION >= 1.7.0 only (removed old version support)



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/htmlgrid/dojotoolkit.rb', line 14

def dojo_tag(widget, args={}, inner_html='')
  div = HtmlGrid::Div.new(@model, @session, self)
  div.set_attribute('data-dojo-type', widget)
  args.each { |key, value|
    if value.is_a?(Array)
      value = value.join(',')
    end
    div.set_attribute(key, value)
  }
  div.value = inner_html
  div
end

#dojo_title=(value) ⇒ Object



26
27
28
29
30
# File 'lib/htmlgrid/dojotoolkit.rb', line 26

def dojo_title=(value)
  tooltip = HtmlGrid::Div.new(@model, @session, self)
  tooltip.value = value
  self.dojo_tooltip = tooltip
end

#dynamic_html(context) ⇒ Object



161
162
163
# File 'lib/htmlgrid/component.rb', line 161

def dynamic_html(context)
	''
end

#escape(txt) ⇒ Object

escape ‘&’, ‘<’ and ‘>’ characters in txt



165
166
167
168
169
170
171
# File 'lib/htmlgrid/component.rb', line 165

def escape(txt)
	@@html_entities.inject(txt.to_s.dup) { |str, map|
		char, entity = map
		str.gsub!(char, '&' << entity << ';')
		str
	}
end

#escape_symbols(txt) ⇒ Object

escape symbol-font strings



173
174
175
176
177
178
179
180
181
182
183
# File 'lib/htmlgrid/component.rb', line 173

def escape_symbols(txt)
	esc = ''
	txt.to_s.each_byte { |byte|
		esc << if(entity = @@symbol_entities[byte])
			'&' << entity << ';'
		else
        byte
		end
	}
	esc
end

#formnameObject

delegator to @container, default definition in Form



185
186
187
# File 'lib/htmlgrid/component.rb', line 185

def formname
	@container.formname if @container.respond_to?(:formname)
end

#http_headersObject



188
189
190
# File 'lib/htmlgrid/component.rb', line 188

def http_headers
	self::class::HTTP_HEADERS.dup
end

#label=(boolean) ⇒ Object



195
196
197
# File 'lib/htmlgrid/component.rb', line 195

def label=(boolean)
	@label = boolean
end

#label?Boolean

precede this instance with a label?

Returns:

  • (Boolean)


192
193
194
# File 'lib/htmlgrid/component.rb', line 192

def label?
	@label
end

#onclick=(onclick) ⇒ Object



198
199
200
# File 'lib/htmlgrid/component.rb', line 198

def onclick=(onclick)
    @attributes['onclick'] = onclick
end

#onload=(onload) ⇒ Object

delegator to @container, default definition in Template



202
203
204
# File 'lib/htmlgrid/component.rb', line 202

def onload=(onload)
	@container.onload = onload if(@container.respond_to? :onload=)
end

#onsubmit=(onsubmit) ⇒ Object

delegator to @container, default definition in Form



206
207
208
# File 'lib/htmlgrid/component.rb', line 206

def onsubmit=(onsubmit)
	@container.onsubmit = onsubmit if(@container.respond_to? :onsubmit=)
end

#set_attribute(key, value) ⇒ Object

set a html attribute



210
211
212
# File 'lib/htmlgrid/component.rb', line 210

def set_attribute(key, value)
	@attributes.store(key, value)
end

#tabindex=(tab) ⇒ Object



213
214
215
# File 'lib/htmlgrid/component.rb', line 213

def tabindex=(tab)
	@attributes.store('tabIndex', tab.to_s)
end

#to_html(context) ⇒ Object



216
217
218
# File 'lib/htmlgrid/component.rb', line 216

def to_html(context)
  _to_html(context, @value).to_s.encode('utf-8')
end