Class: ViewComponent::Form::LabelComponent
- Inherits:
-
FieldComponent
- Object
- BaseComponent
- FieldComponent
- ViewComponent::Form::LabelComponent
- Defined in:
- app/components/view_component/form/label_component.rb
Instance Attribute Summary collapse
-
#attribute_content ⇒ Object
readonly
Returns the value of attribute attribute_content.
Attributes inherited from FieldComponent
Attributes inherited from BaseComponent
Instance Method Summary collapse
- #builder ⇒ Object
- #call ⇒ Object
-
#initialize(form, object_name, method_name, content_or_options = nil, options = nil) ⇒ LabelComponent
constructor
A new instance of LabelComponent.
Methods inherited from FieldComponent
#label_text, #method_errors, #method_errors?, #object_method_names, #optional?, #required?, #validators, #value
Methods inherited from BaseComponent
#html_class, #object_errors, #object_errors?
Methods included from ClassNamesHelper
#build_tag_values, #class_names
Constructor Details
#initialize(form, object_name, method_name, content_or_options = nil, options = nil) ⇒ LabelComponent
Returns a new instance of LabelComponent.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/components/view_component/form/label_component.rb', line 8 def initialize(form, object_name, method_name, = nil, = nil) ||= {} = .is_a?(Hash) if .merge! @attribute_content = nil else @attribute_content = end super(form, object_name, method_name, ) end |
Instance Attribute Details
#attribute_content ⇒ Object (readonly)
Returns the value of attribute attribute_content.
6 7 8 |
# File 'app/components/view_component/form/label_component.rb', line 6 def attribute_content @attribute_content end |
Instance Method Details
#builder ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/components/view_component/form/label_component.rb', line 32 def builder @builder ||= begin tag_value = .delete("value") ActionView::Helpers::Tags::Label::LabelBuilder.new(@view_context, object_name, method_name, object, tag_value) end end |
#call ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'app/components/view_component/form/label_component.rb', line 22 def call = nil = content || attribute_content if content.present? || attribute_content.present? ActionView::Helpers::Tags::Label.new(object_name, method_name, @view_context, , ).render end |