Sha256: 4d7563ed298d7ea16c610d02140a0507db887bd1b7f035060eb40756ac1b0beb

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

require 'action_view'

# rubocop:disable Metrics/ParameterLists

class BootstrapFormBuilder < ActionView::Helpers::FormBuilder
  attr_reader :template

  def date_field(field, **opts)
    add_css_class(opts, 'date-picker')
    text_field(field, opts)
  end

  def text_field(field, **opts)
    add_css_class(opts, 'form-control')
    super
  end

  def password_field(field, **opts)
    add_css_class(opts, 'form-control')
    super
  end

  def text_area(method, **opts)
    add_css_class(opts, 'form-control')
    super
  end

  def check_box(*)
    template.content_tag('div', class: 'checkbox') do
      template.content_tag('label') do
        template.concat(super)
        template.concat(template.capture { yield })
      end
    end
  end

  def radio_button(*)
    template.content_tag('div', class: 'radio') do
      template.content_tag('label') do
        template.concat(super)
        template.concat(template.capture { yield })
      end
    end
  end

  def select(method, choices = nil, opts = {}, html_opts = {})
    add_css_class(html_opts, 'form-control')
    super
  end

  def collection_select(method, collection, value_method, text_method,
                        opts = {}, html_opts = {})
    add_css_class(html_opts, 'form-control')
    super
  end

  private

  def add_css_class(opts, class_name)
    opts[:class] = "#{opts[:class]} #{class_name}".strip
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aaf-lipstick-3.0.2 lib/lipstick/helpers/bootstrap_form_builder.rb