Sha256: 31aa6c354b9939310564bccaa9dbec782f6b321e11f616d46bac04bca7a38fc2

Contents?: true

Size: 1.71 KB

Versions: 15

Compression:

Stored size: 1.71 KB

Contents

module Gluttonberg
    class FormBuilder < ActionView::Helpers::FormBuilder
      include ActionView::Helpers::TagHelper

      def text_field(attribute, options={})
        box_class = add_class!('text', options)
        field(super, attribute, options, box_class)
      end

      def text_area(attribute, options={})
        box_class = add_class!('text', options)
        field(super, attribute, options, box_class)
      end

      def radio_button(attribute, value, label, options = {})
        add_class!('radio', options)
        label_for = "#{object_name}_#{attribute}_#{value}"
        super(attribute, value, options) + label(attribute, :label => label, :class => 'inline', :for => label_for)
      end

      def select(attribute, choices, options={})
        box_class = add_class!('text', options)
        field(super, attribute, options, box_class)
      end

      private

      def label(method, options = {})
        if options.has_key?(:label)
          super(method, options.delete(:label), options)
        else
          super(method, nil, options)
        end
      end

      def add_class!(klass, options)
        classes = [klass]
        classes << options[:class] if options.has_key?(:class)
        if options.has_key? :size
          parts = options[:size].split('.')
          classes << parts.last
          options[:class] = classes.join(' ')
          parts.first
        else
          options[:class] = classes.join(' ')
          nil
        end
      end

      def field(field, attribute, options, size = nil)
        content = label(attribute, options) + field
        klass = size ? 'field ' + size : 'field'
        content_tag(:p, content, :class => klass)
      end
    end # FormBuilder
end # Gluttonberg

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
gluttonberg-core-2.6.4 lib/gluttonberg/helpers/form_builder.rb
gluttonberg-core-2.6.3 lib/gluttonberg/helpers/form_builder.rb
gluttonberg-core-2.6.2 lib/gluttonberg/helpers/form_builder.rb
gluttonberg-core-2.6.1 lib/gluttonberg/helpers/form_builder.rb
gluttonberg-core-2.6.0 lib/gluttonberg/helpers/form_builder.rb
gluttonberg-core-2.5.9 lib/gluttonberg/helpers/form_builder.rb
gluttonberg-core-2.5.8 lib/gluttonberg/helpers/form_builder.rb
gluttonberg-core-2.5.7 lib/gluttonberg/helpers/form_builder.rb
gluttonberg-core-2.5.6 lib/gluttonberg/helpers/form_builder.rb
gluttonberg-core-2.5.5 lib/gluttonberg/helpers/form_builder.rb
gluttonberg-core-2.5.4 lib/gluttonberg/helpers/form_builder.rb
gluttonberg-core-2.5.3 lib/gluttonberg/helpers/form_builder.rb
gluttonberg-core-2.5.2 lib/gluttonberg/helpers/form_builder.rb
gluttonberg-core-2.5.1 lib/gluttonberg/helpers/form_builder.rb
gluttonberg-core-2.5 lib/gluttonberg/helpers/form_builder.rb