Class: ActionView::Helpers::AttributeBuilders::Label

Inherits:
Base
  • Object
show all
Defined in:
lib/actionview_attribute_builders/attribute_builders/label.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Attributes inherited from Base

#object

Instance Method Summary collapse

Constructor Details

#initialize(object_name, method_name, template_object, content_or_options, options = nil) ⇒ Label

Returns a new instance of Label.



7
8
9
10
11
12
13
14
15
# File 'lib/actionview_attribute_builders/attribute_builders/label.rb', line 7

def initialize(object_name, method_name, template_object, content_or_options, options = nil)
  options ||= {}
  if content_or_options.is_a?(Hash)
    options.merge! content_or_options
  else
    @content = content_or_options
  end
  super(object_name, method_name, template_object, options)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



17
18
19
# File 'lib/actionview_attribute_builders/attribute_builders/label.rb', line 17

def content
  @content
end

Instance Method Details

#html_attributes(&block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/actionview_attribute_builders/attribute_builders/label.rb', line 19

def html_attributes(&block)
  options = @options.stringify_keys
  name_and_id = options.dup

  if name_and_id["for"]
    name_and_id["id"] = name_and_id["for"]
  else
    name_and_id.delete("id")
  end

  add_default_name_and_id_for_value(options["value"], name_and_id)
  options.delete("index")
  options.delete("namespace")
  options["for"] = name_and_id["id"] unless options.key?("for")

  options
end