Sha256: bf13918f0d4b8d441a0749d3f3022d3c5c6deab1cb53c481cc6fc34d5abbb99f

Contents?: true

Size: 1.44 KB

Versions: 8

Compression:

Stored size: 1.44 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(*, &block)
    template.content_tag('div', class: 'checkbox') do
      template.content_tag('label') do
        template.concat(super)
        template.concat(template.capture(&block))
      end
    end
  end

  def radio_button(*, &block)
    template.content_tag('div', class: 'radio') do
      template.content_tag('label') do
        template.concat(super)
        template.concat(template.capture(&block))
      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

# rubocop:enable Metrics/ParameterLists

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
aaf-lipstick-4.10.0 lib/lipstick/helpers/bootstrap_form_builder.rb
aaf-lipstick-4.9.2 lib/lipstick/helpers/bootstrap_form_builder.rb
aaf-lipstick-4.9.1 lib/lipstick/helpers/bootstrap_form_builder.rb
aaf-lipstick-4.9.0 lib/lipstick/helpers/bootstrap_form_builder.rb
aaf-lipstick-4.8.0 lib/lipstick/helpers/bootstrap_form_builder.rb
aaf-lipstick-4.7.0 lib/lipstick/helpers/bootstrap_form_builder.rb
aaf-lipstick-4.6.0 lib/lipstick/helpers/bootstrap_form_builder.rb
aaf-lipstick-4.5.1 lib/lipstick/helpers/bootstrap_form_builder.rb