Class: HtmlGrid::AbstractComposite

Inherits:
Component
  • Object
show all
Defined in:
lib/htmlgrid/composite.rb

Direct Known Subclasses

Composite, TagComposite

Constant Summary collapse

LABELS =
false
LEGACY_INTERFACE =
true
SYMBOL_MAP =
{}
CSS_MAP =
{}
CSS_ID_MAP =
{}
CSS_STYLE_MAP =
{}
CSS_CLASS =
nil
CSS_ID =
nil
DEFAULT_CLASS =
Value
LOOKANDFEEL_MAP =
{}

Constants inherited from Component

Component::HTML_ATTRIBUTES, Component::HTTP_HEADERS, Component::LABEL

Instance Attribute Summary

Attributes inherited from Component

#attributes, #dojo_tooltip, #label, #model, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Component

#_to_html, #autofill?, #css_class, #css_class=, #css_id, #css_id=, #dojo_dynamic_html, #dojo_parse_on_load, #dojo_tag, #dojo_title=, #dynamic_html, #escape, #escape_symbols, #formname, #http_headers, #initialize, #label?, #onclick=, #onload=, #onsubmit=, #set_attribute, #tabindex=, #to_html

Constructor Details

This class inherits a constructor from HtmlGrid::Component

Class Method Details

.component(klass, key, name = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/htmlgrid/composite.rb', line 55

def self.component(klass, key, name = nil)
  methname = klass.to_s.downcase.gsub("::", "_") << "_" << key.to_s
  define_method(methname) { |*args|
    model, session = args
    args = [model.send(key), session || @session, self]
    if name
      args.unshift(name)
      lookandfeel_map.store(methname.to_sym, name.to_sym)
    end
    klass.new(*args)
  }
  methname.to_sym
end

Instance Method Details

#create(component, model = @model) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/htmlgrid/composite.rb', line 75

def create(component, model = @model)
  if component.is_a? Class
    component.new(model, @session, self)
  elsif component.is_a? Symbol
    if respond_to?(component, true)
      args = [model]
      if self.class::LEGACY_INTERFACE
        args.push(@session)
      end
      send(component, *args)
    elsif (klass = symbol_map[component])
      klass.new(component, model, @session, self)
    else
      self.class::DEFAULT_CLASS.new(component, model, @session, self)
    end
  elsif component.is_a? String
    val = @lookandfeel.lookup(component) { component.to_s }
    val.gsub(@@nl2br_ptrn, "<br>")
  end
rescue => exc
  exc.backtrace.push(sprintf("%s::COMPONENTS[%s] in create(%s)",
    self.class, components.key(component).inspect, component))
  raise exc
end

#initObject



69
70
71
72
73
# File 'lib/htmlgrid/composite.rb', line 69

def init
  super
  setup_grid
  compose
end