class HtmlGrid::Grid::Row::Field
Constants
- ALLOWED_ATTRIBUTES
Attributes
components[R]
tag[R]
Public Class Methods
new()
click to toggle source
# File lib/htmlgrid/grid.rb, line 44 def initialize @components = [] @attributes = {} @tag = nil end
Public Instance Methods
add(item)
click to toggle source
# File lib/htmlgrid/grid.rb, line 50 def add(item) if item.is_a? Array @components += item else @components.push item end end
add_attribute(key, value)
click to toggle source
# File lib/htmlgrid/grid.rb, line 70 def add_attribute(key, value) @attributes.store(key.to_s, value.to_s) end
add_background()
click to toggle source
# File lib/htmlgrid/grid.rb, line 58 def add_background compose @components.each { |component| component.add_background } if @attributes["class"] @attributes["class"] += "-bg" unless /-bg/.match?(@attributes["class"]) else @attributes["class"] = "bg" end end
add_component_style(style)
click to toggle source
# File lib/htmlgrid/grid.rb, line 74 def add_component_style(style) @components.each { |cmp| cmp.set_attribute("class", style) if cmp.respond_to?(:set_attribute) } end
add_style(style)
click to toggle source
# File lib/htmlgrid/grid.rb, line 80 def add_style(style) @attributes["class"] = style end
attribute(key)
click to toggle source
# File lib/htmlgrid/grid.rb, line 84 def attribute(key) @attributes[key] end
colspan()
click to toggle source
# File lib/htmlgrid/grid.rb, line 88 def colspan @attributes.fetch("colspan", 1).to_i end
colspan=(span)
click to toggle source
# File lib/htmlgrid/grid.rb, line 92 def colspan=(span) @attributes["colspan"] = span.to_s if span.to_i > 1 end
component_html(cgi)
click to toggle source
# File lib/htmlgrid/grid.rb, line 96 def component_html(cgi) html = "" @components.each { |component| html << if component.respond_to? :to_html component.to_html(cgi).to_s.dup.force_encoding("utf-8") else component.to_s end } html = " " if html.empty? html end
tag=(tag)
click to toggle source
# File lib/htmlgrid/grid.rb, line 109 def tag=(tag) @tag = tag.to_s.downcase end
to_html(context)
click to toggle source
# File lib/htmlgrid/grid.rb, line 113 def to_html(context) if @tag && context.respond_to?(@tag) context.send(@tag, @attributes) { component_html(context) } else context.td(@attributes) { component_html(context) } end end