class ExpressTemplates::Components::Forms::Radio

Public Instance Methods

collection_from_association() click to toggle source
# File lib/express_templates/components/forms/radio.rb, line 76
def collection_from_association
  related_collection or raise "No association collection for: #{resource_name}.#{field_name}"
end
generate_options_from_specified_values() click to toggle source
# File lib/express_templates/components/forms/radio.rb, line 42
def generate_options_from_specified_values
  if !option_collection.kind_of?(Array) &&
      !option_collection.kind_of?(Hash)
    raise ArgumentError, "Radio collection should be Array or Hash: #{option_collection.inspect}"
  end

  option_collection_hash = option_collection
  if option_collection.kind_of?(Array)
    option_collection_hash = option_collection.inject({}) do |hash, val|
      hash[val] = val
      hash
    end
  end

  option_collection_hash.each_pair do |key, value|
    if label_after?
      div(class: "radio-input-container") {
        radio_button(resource_name, field_name.to_sym, key, class: 'radio')
        label({
          class: config[:label_wrapper_class],
          for: [resource_name, field_name, key].join("_").downcase,
        }) {
          current_arbre_element.add_child value
        }
      }
    else
      label(class: config[:label_wrapper_class]) {
        radio_button(resource_name, field_name.to_sym, key, class: 'radio')
        current_arbre_element.add_child  value
      }
    end
  end
end
option_collection() click to toggle source
# File lib/express_templates/components/forms/radio.rb, line 38
def option_collection
  config[:options]
end
option_values_specified?() click to toggle source
# File lib/express_templates/components/forms/radio.rb, line 34
def option_values_specified?
  [Array, Hash].include?(option_collection.class)
end
use_options_from_collection_radio_buttons_helper() click to toggle source
# File lib/express_templates/components/forms/radio.rb, line 24
def use_options_from_collection_radio_buttons_helper
  collection_radio_buttons(resource_name, field_name.to_sym, collection_from_association,
                           option_value_method, option_name_method,
                           input_attributes) do |b|
    b.label(class: "radio") {
      b.radio_button + b.text
    }
  end
end

Protected Instance Methods

label_after?() click to toggle source
# File lib/express_templates/components/forms/radio.rb, line 82
def label_after?
  !!config[:label_after]
end