Class: Lifeform::Libraries::Default::Button
- Inherits:
-
Phlex::HTML
- Object
- Phlex::HTML
- Lifeform::Libraries::Default::Button
- Includes:
- CapturingRenderable
- 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
Methods included from CapturingRenderable
Constructor Details
#initialize(form, field_definition, **attributes) ⇒ Button
Returns a new instance of Button.
17 18 19 20 21 22 23 24 |
# File 'lib/lifeform/libraries/default/button.rb', line 17 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.
10 11 12 |
# File 'lib/lifeform/libraries/default/button.rb', line 10 def attributes @attributes end |
#field_definition ⇒ Object (readonly)
Returns the value of attribute field_definition.
10 11 12 |
# File 'lib/lifeform/libraries/default/button.rb', line 10 def field_definition @field_definition end |
#form ⇒ Object (readonly)
Returns the value of attribute form.
10 11 12 |
# File 'lib/lifeform/libraries/default/button.rb', line 10 def form @form end |
Instance Method Details
#template(&block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/lifeform/libraries/default/button.rb', line 26 def template(&block) return if !@if.nil? && !@if wrapper_tag = self.class.const_get(:WRAPPER_TAG) = self.class.const_get(:BUTTON_TAG) field_body = proc { send(, **@attributes) do unsafe_raw(@label.to_s) unless block yield_content(&block) end } return field_body.() unless wrapper_tag send wrapper_tag, name: @attributes[:name], &field_body end |