class HtmlGrid::Composite
Constants
- COLSPAN_MAP
- COMPONENT_CSS_MAP
- CSS_MAP
- DEFAULT_CLASS
- VERTICAL
Public Instance Methods
compose(model = @model, offset = [0, 0], bg_flag = false)
click to toggle source
# File lib/htmlgrid/composite.rb, line 215 def compose(model = @model, offset = [0, 0], bg_flag = false) comps = components css = css_map cids = css_id_map ccss = component_css_map colsp = colspan_map suffix = resolve_suffix(model, bg_flag) comps.keys.concat(css.keys).concat(colsp.keys).uniq.sort_by { |key| [key.size, key] }.each { |key| nkey = key[0, 2] matrix = resolve_offset(key, offset) nmatrix = resolve_offset(nkey, offset) comp = compose_component(model, comps[key], matrix) if (style = css[key]) @grid.add_style(style + suffix, *matrix) elsif (style = css[nkey]) @grid.add_style(style + suffix, *nmatrix) end if (id = cids[key] || cids[nkey]) comp.css_id = id end if (span = colsp[key]) @grid.set_colspan(matrix.at(0), matrix.at(1), span) end } # component-styles depend on components having been initialized # -> separate iteration ccss.each { |key, cstyle| matrix = resolve_offset(key, offset) @grid.add_component_style(cstyle + suffix, *matrix) } # compose_components(model, offset) # compose_css(offset) # compose_colspan(offset) end
Also aliased as: _compose
compose_colspan(offset)
click to toggle source
# File lib/htmlgrid/composite.rb, line 252 def compose_colspan(offset) colspan_map.each { |matrix, span| res = resolve_offset(matrix, offset) @grid.set_colspan(res.at(0), res.at(1), span) } end
event()
click to toggle source
# File lib/htmlgrid/composite.rb, line 259 def event @container.event if @container.respond_to?(:event) end
full_colspan()
click to toggle source
def explode!
@grid.explode! super
end
# File lib/htmlgrid/composite.rb, line 267 def full_colspan raw_span = components.keys.collect { |key| key.at(0) }.max.to_i raw_span > 0 ? raw_span + 1 : nil end
insert_row(ypos, txt, css_class = nil)
click to toggle source
# File lib/htmlgrid/composite.rb, line 274 def insert_row(ypos, txt, css_class = nil) @grid.insert_row(ypos, txt) @grid.set_colspan(0, ypos) @grid.add_style(css_class, 0, ypos) if css_class end
to_html(context)
click to toggle source
Calls superclass method
HtmlGrid::Component#to_html
# File lib/htmlgrid/composite.rb, line 280 def to_html(context) @grid.set_attributes(@attributes) super << @grid.to_html(context).force_encoding("utf-8") end
Private Instance Methods
back(model = @model, session = @session)
click to toggle source
# File lib/htmlgrid/composite.rb, line 287 def back(model = @model, session = @session) bak = HtmlGrid::Button.new(:back, model, session, self) url = @lookandfeel.event_url(:back) bak.set_attribute("onClick", "document.location.href='#{url}';") bak end
colspan_map()
click to toggle source
# File lib/htmlgrid/composite.rb, line 294 def colspan_map @colspan_map ||= self.class::COLSPAN_MAP.dup end
component_css_map()
click to toggle source
# File lib/htmlgrid/composite.rb, line 298 def component_css_map @component_css_map ||= self.class::COMPONENT_CSS_MAP.dup end
compose_component(model, component, matrix)
click to toggle source
# File lib/htmlgrid/composite.rb, line 302 def compose_component(model, component, matrix) if component comp = create(component, model) if (tab = matrix.at(3)) && comp.respond_to?(:tabindex=) comp.tabindex = tab end @grid.add(label(comp, component), matrix.at(0), matrix.at(1), self.class::VERTICAL) comp end end
compose_components(model = @model, offset = [0, 0])
click to toggle source
compose_components
: legacy-code
# File lib/htmlgrid/composite.rb, line 315 def compose_components(model = @model, offset = [0, 0]) warn "HtmlGrid::List#compose_components is deprecated" each_component { |matrix, component| res = resolve_offset(matrix, offset) comp = create(component, model) if (tab = matrix.at(3)) && comp.respond_to?(:tabindex=) comp.tabindex = tab end @grid.add(label(comp, component), res.at(0), res.at(1), self.class::VERTICAL) } end
compose_css(offset = [0, 0], suffix = "")
click to toggle source
compose_css
: legacy-code
# File lib/htmlgrid/composite.rb, line 329 def compose_css(offset = [0, 0], suffix = "") warn "HtmlGrid::List#compose_css is deprecated" each_css { |matrix, style| @grid.add_style(style + suffix, *resolve_offset(matrix, offset)) } each_component_css { |matrix, style| @grid.add_component_style(style + suffix, *resolve_offset(matrix, offset)) } end
each_component(&block)
click to toggle source
# File lib/htmlgrid/composite.rb, line 339 def each_component(&block) (@sorted_components ||= components.sort).each(&block) end
each_component_css(&block)
click to toggle source
# File lib/htmlgrid/composite.rb, line 343 def each_component_css(&block) (@sorted_component_css_map ||= component_css_map.sort).each(&block) end
each_css(&block)
click to toggle source
# File lib/htmlgrid/composite.rb, line 347 def each_css(&block) (@sorted_css_map ||= css_map.sort).each(&block) end
label(component, key = nil)
click to toggle source
# File lib/htmlgrid/composite.rb, line 351 def label(component, key = nil) if labels? HtmlGrid::Label.new(component, @session, lookandfeel_key(key)) else component end end
lookandfeel_key(component)
click to toggle source
# File lib/htmlgrid/composite.rb, line 359 def lookandfeel_key(component) lookandfeel_map.fetch(component) { component } end
resolve_offset(matrix, offset = [0, 0])
click to toggle source
# File lib/htmlgrid/composite.rb, line 373 def resolve_offset(matrix, offset = [0, 0]) result = [] matrix.each_with_index { |value, index| result.push(value + offset.at(index).to_i) } result end
resolve_suffix(model, bg_flag = false)
click to toggle source
# File lib/htmlgrid/composite.rb, line 381 def resolve_suffix(model, bg_flag = false) bg_flag ? self.class::BACKGROUND_SUFFIX : "" end
setup_grid()
click to toggle source
# File lib/htmlgrid/composite.rb, line 365 def setup_grid @grid = Grid.new end
submit(model = @model, session = @session, name = event())
click to toggle source
# File lib/htmlgrid/composite.rb, line 369 def submit(model = @model, session = @session, name = event()) Submit.new(name, model, session, self) end