Class: Lifeform::Libraries::Default::Button
- Inherits:
-
Object
- Object
- Lifeform::Libraries::Default::Button
- Includes:
- Streamlined::Renderable
- Defined in:
- lib/lifeform/libraries/default/button.rb
Direct Known Subclasses
Constant Summary collapse
- WRAPPER_TAG =
:form_button
- BUTTON_TAG =
:button
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#field_definition ⇒ Object
readonly
Returns the value of attribute field_definition.
-
#form ⇒ Object
readonly
Returns the value of attribute form.
Instance Method Summary collapse
-
#initialize(form, field_definition, **attributes) ⇒ Button
constructor
A new instance of Button.
- #template(&block) ⇒ Object
Constructor Details
#initialize(form, field_definition, **attributes) ⇒ Button
Returns a new instance of Button.
14 15 16 17 18 19 20 21 |
# File 'lib/lifeform/libraries/default/button.rb', line 14 def initialize(form, field_definition, **attributes) @form = form @field_definition = field_definition @attributes = Lifeform::Form.parameters_to_attributes(field_definition.parameters).merge(attributes) @if = @attributes.delete(:if) @label = @attributes.delete(:label) || "Unlabeled Button" @attributes[:type] ||= "button" end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
9 10 11 |
# File 'lib/lifeform/libraries/default/button.rb', line 9 def attributes @attributes end |
#field_definition ⇒ Object (readonly)
Returns the value of attribute field_definition.
9 10 11 |
# File 'lib/lifeform/libraries/default/button.rb', line 9 def field_definition @field_definition end |
#form ⇒ Object (readonly)
Returns the value of attribute form.
9 10 11 |
# File 'lib/lifeform/libraries/default/button.rb', line 9 def form @form end |
Instance Method Details
#template(&block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lifeform/libraries/default/button.rb', line 23 def template(&block) return "" if !@if.nil? && !@if = dashed self.class.const_get(:BUTTON_TAG) label_text = block ? capture(self, &block) : @label field_body = html -> { <<~HTML # rubocop:disable Bridgetown/InsecureHeredoc <#{}#{html_attributes @attributes, prefix_space: true}>#{text label_text}</#{}> HTML } return field_body unless self.class.const_get(:WRAPPER_TAG) wrapper_tag = dashed self.class.const_get(:WRAPPER_TAG) html -> { <<~HTML # rubocop:disable Bridgetown/InsecureHeredoc <#{wrapper_tag} #{html_attributes name: @attributes[:name]}>#{field_body}</#{wrapper_tag}> HTML } end |