Class: ExpressTemplates::Components::Forms::Radio
- Inherits:
-
FormComponent
- Object
- Expander
- Base
- FormComponent
- ExpressTemplates::Components::Forms::Radio
- Includes:
- OptionSupport
- Defined in:
- lib/express_templates/components/forms/radio.rb
Instance Attribute Summary
Attributes inherited from Expander
#handlers, #locals, #stack, #template
Instance Method Summary collapse
- #collection_from_association ⇒ Object
- #field_options ⇒ Object
- #generate_options_from_specified_values ⇒ Object
-
#html_options ⇒ Object
TODO: implement.
- #option_collection ⇒ Object
- #option_values_specified? ⇒ Boolean
- #use_options_from_collection_radio_buttons_helper ⇒ Object
- #wrapper_class ⇒ Object
Methods included from OptionSupport
#belongs_to_association, #related_collection
Methods inherited from FormComponent
#compile, #field_name, #field_name_attribute, #field_wrapper_class, #label_name, #label_text, #parent_form, #resource_class, #resource_name, #resource_var
Methods included from Capabilities::Adoptable
Methods included from Capabilities::Configurable
Methods inherited from Base
Methods included from Capabilities::Iterating
Methods included from Capabilities::Wrapping
Methods included from Capabilities::Rendering
Methods included from Capabilities::Templating
Methods included from Macro
Methods inherited from Expander
#expand, #initialize, #initialize_expander, #method_missing, #process_children!, register_macros_for
Constructor Details
This class inherits a constructor from ExpressTemplates::Expander
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ExpressTemplates::Expander
Instance Method Details
#collection_from_association ⇒ Object
62 63 64 |
# File 'lib/express_templates/components/forms/radio.rb', line 62 def collection_from_association or raise "No association collection for: #{resource_name}.#{field_name}" end |
#field_options ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/express_templates/components/forms/radio.rb', line 66 def # If field_otions is omitted the Expander will be # in last or 3rd position and we don't want that if @args.size > 3 && @args[2].is_a?(Hash) @args[2] else {} end end |
#generate_options_from_specified_values ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/express_templates/components/forms/radio.rb', line 41 def case when option_collection.kind_of?(Array) option_collection.each_with_index do |option, index| label(class: wrapper_class) { (resource_var, field_name.to_sym, option, class: 'radio') null_wrap { option } } end when option_collection.kind_of?(Hash) option_collection.each_pair do |key, value| label(class: wrapper_class) { (resource_var, field_name.to_sym, key, class: 'radio') null_wrap { value } } end else raise "Radio collection should be Array or Hash: #{option_collection.inspect}" end end |
#html_options ⇒ Object
TODO: implement
77 78 79 |
# File 'lib/express_templates/components/forms/radio.rb', line 77 def {} end |
#option_collection ⇒ Object
33 34 35 |
# File 'lib/express_templates/components/forms/radio.rb', line 33 def option_collection @args.second end |
#option_values_specified? ⇒ Boolean
29 30 31 |
# File 'lib/express_templates/components/forms/radio.rb', line 29 def option_values_specified? [Array, Hash].include?(option_collection.class) end |
#use_options_from_collection_radio_buttons_helper ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/express_templates/components/forms/radio.rb', line 18 def # Note {{ }} will get stripped. This prevents the collection finder string being passed as string. (resource_var, field_name.to_sym, "{{#{collection_from_association}}}", option_value_method, option_name_method, , ) do |b| b.label(class: "radio") { b. + b.text } end end |
#wrapper_class ⇒ Object
37 38 39 |
# File 'lib/express_templates/components/forms/radio.rb', line 37 def wrapper_class @config[:wrapper_class] || 'wrapper-class' end |