Class: HtmlGrid::Label

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Enumerable
Defined in:
lib/htmlgrid/label.rb

Instance Method Summary collapse

Constructor Details

#initialize(component, session, label_key = nil) ⇒ Label



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/htmlgrid/label.rb', line 46

def initialize(component, session, label_key=nil)
  @component = component
  @attributes = {}
  @session = session
  @lookandfeel = session.lookandfeel
  @label_key = label_key 
  if(@component.respond_to? :name)
    @attributes['for'] = @component.name.to_s
    @label_key ||= @component.name
  end
  if(@component.respond_to?(:data_origin) \
     && (origin = @component.data_origin))
    @attributes.store('title', origin.to_s)
  end
  if(@session.error(@label_key) \
       || (@component.respond_to?(:name) && @session.error(@component.name)))
    @attributes["class"] = "error" 
  end
  if(@component.respond_to?(:attributes) \
    && (id = @component.attributes['id']))
    @attributes.store('id', "label_#{id}")
  end
  super(component)
end

Instance Method Details

#each {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



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

def each
  yield self if(@component.respond_to?(:label?) && @component.label?)
  yield @component
end

#to_html(context) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/htmlgrid/label.rb', line 74

def to_html(context)
    key = @label_key
  label = @lookandfeel.lookup(key) 
    if(!label && @component.respond_to?(:name))
      key = @component.name
    label = @lookandfeel.lookup(key)
  end
    state = @session.state
    if(label && state.respond_to?(:mandatory?) && state.mandatory?(key))
      label += "*"
    end 
  if(label)
    context.label(@attributes) { label }
  end
end