Sha256: 6c5db63e5f4475aa43208248afbb1b4f0e487f185ce2899c6b1e191d7567e6d5
Contents?: true
Size: 1.89 KB
Versions: 3
Compression:
Stored size: 1.89 KB
Contents
module SelectableAttrRails::Helpers module RadioButtonGroupHelper class Builder < SelectableAttrRails::Helpers::AbstractSelectionBuilder attr_reader :entry_hash_array attr_reader :entry_hash attr_accessor :radio_button_id def initialize(object, object_name, method, options, template) super(object, object_name, method, options, template) @entry_hash_array ||= enum_hash_array_from_class end def each(&block) @entry_hash_array.each do |entry_hash| @entry_hash = entry_hash tag_value = @entry_hash[:id].to_s.gsub(/\s/, "_").gsub(/\W/, "").downcase @radio_button_id = "#{@object_name}_#{@method}_#{tag_value}" yield(self) end end def radio_button(options = nil) @template.radio_button(@object_name, @method, @entry_hash[:id], update_options({:id => @radio_button_id}, options)) end def label(text = nil, options = nil) @template.content_tag("label", text || @entry_hash[:name], update_options({:for => @radio_button_id}, options)) end end module Base def radio_button_group(object_name, method, options = nil, &block) object = (options || {})[:object] || instance_variable_get("@#{object_name}") builder = Builder.new(object, object_name, method, options, self) if block_given? yield(builder) return nil else result = '' builder.each do result << builder.radio_button result << builder.label end return result.respond_to?(:html_safe) ? result.html_safe : result end end end module FormBuilder def radio_button_group(method, options = nil, &block) @template.radio_button_group(@object_name, method, (options || {}).merge(:object => @object), &block) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems