class HtmlGrid::Component

Constants

CSS_CLASS

sets the ‘class’ html-attribute

CSS_ID

sets the ‘id’ html-attribute

HTML_ATTRIBUTES

other html-attributes

HTTP_HEADERS

default http-headers

LABEL

precede instances of this class with a label?

Attributes

attributes[R]
dojo_tooltip[RW]
label[W]
model[R]
value[RW]

Public Class Methods

new(model, session = nil, container = nil) click to toggle source
# 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

Public Instance Methods

_to_html(context, value = @value) click to toggle source
# File lib/htmlgrid/component.rb, line 235
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")
  elsif value&.is_a?(String)
    _value = CGI.unescape(value.gsub("+", CGI.escape("+")))
  elsif value&.is_a?(Integer)
    _value = value.to_s
  end
end
autofill?() click to toggle source

delegator to @container, default definition in Form

# File lib/htmlgrid/component.rb, line 143
def autofill?
  @container.autofill? if @container.respond_to?(:autofill?)
end
css_class() click to toggle source

gets the ‘class’ html-attribute if defined

# File lib/htmlgrid/component.rb, line 148
def css_class
  @css_class ||= self.class::CSS_CLASS
end
css_class=(css_class) click to toggle source

sets the ‘class’ html-attribute

# File lib/htmlgrid/component.rb, line 153
def css_class=(css_class)
  @css_class = @attributes["class"] = css_class
end
css_id() click to toggle source

gets the ‘id’ html-attribute if defined

# File lib/htmlgrid/component.rb, line 158
def css_id
  @css_id ||= self.class::CSS_ID
end
css_id=(css_id) click to toggle source

sets the ‘id’ html-attribute

# File lib/htmlgrid/component.rb, line 163
def css_id=(css_id)
  @css_id = @attributes["id"] = css_id
end
dojo_parse_on_load() click to toggle source
# File lib/htmlgrid/dojotoolkit.rb, line 33
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 = "") click to toggle source

DOJO_VERSION >= 1.7.0 only (removed old version support)

# 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) click to toggle source
# File lib/htmlgrid/dojotoolkit.rb, line 27
def dojo_title=(value)
  tooltip = HtmlGrid::Div.new(@model, @session, self)
  tooltip.value = value
  self.dojo_tooltip = tooltip
end
dynamic_html(context) click to toggle source
# File lib/htmlgrid/component.rb, line 167
def dynamic_html(context)
  ""
end
escape(txt) click to toggle source

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

# File lib/htmlgrid/component.rb, line 172
def escape(txt)
  @@html_entities.each_with_object(txt.to_s.dup) { |map, str|
    char, entity = map
    str.gsub!(char, "&" << entity << ";")
  }
end
escape_symbols(txt) click to toggle source

escape symbol-font strings

# File lib/htmlgrid/component.rb, line 180
def escape_symbols(txt)
  esc = ""
  txt.to_s.each_byte { |byte|
    esc << if (entity = @@symbol_entities[byte])
      "&" << entity << ";"
    else
      byte
    end
  }
  esc
end
formname() click to toggle source

delegator to @container, default definition in Form

# File lib/htmlgrid/component.rb, line 193
def formname
  @container.formname if @container.respond_to?(:formname)
end
http_headers() click to toggle source
# File lib/htmlgrid/component.rb, line 197
def http_headers
  self.class::HTTP_HEADERS.dup
end
label?() click to toggle source

precede this instance with a label?

# File lib/htmlgrid/component.rb, line 202
def label?
  @label
end
onclick=(onclick) click to toggle source
# File lib/htmlgrid/component.rb, line 208
def onclick=(onclick)
  @attributes["onclick"] = onclick
end
onload=(onload) click to toggle source

delegator to @container, default definition in Template

# File lib/htmlgrid/component.rb, line 213
def onload=(onload)
  @container.onload = onload if @container.respond_to? :onload=
end
onsubmit=(onsubmit) click to toggle source

delegator to @container, default definition in Form

# File lib/htmlgrid/component.rb, line 218
def onsubmit=(onsubmit)
  @container.onsubmit = onsubmit if @container.respond_to? :onsubmit=
end
set_attribute(key, value) click to toggle source

set a html attribute

# File lib/htmlgrid/component.rb, line 223
def set_attribute(key, value)
  @attributes.store(key, value)
end
tabindex=(tab) click to toggle source
# File lib/htmlgrid/component.rb, line 227
def tabindex=(tab)
  @attributes.store("tabIndex", tab.to_s)
end
to_html(context) click to toggle source
# File lib/htmlgrid/component.rb, line 231
def to_html(context)
  _to_html(context, @value).to_s.encode("utf-8")
end

Private Instance Methods

init() click to toggle source
# File lib/htmlgrid/component.rb, line 249
def init
end