Sha256: 262483e9d5b0eccb95b171cdb570fdfacb687309abe67a9a6f18ac0b448d8720

Contents?: true

Size: 1.28 KB

Versions: 20

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

require "primer/classify"

module Primer
  module Forms
    # :nodoc:
    class Builder < ActionView::Helpers::FormBuilder
      include Primer::ClassNameHelper

      UTILITY_KEYS = Primer::Classify::Utilities::UTILITIES.keys.freeze

      def label(*args, **options, &block)
        super(*args, classify(options), &block)
      end

      def check_box(method, options = {}, checked_value = 1, unchecked_value = 0, &block)
        super(method, classify(options), checked_value, unchecked_value, &block)
      end

      def radio_button(*args, **options, &block)
        super(*args, classify(options), &block)
      end

      def select(*args, **options, &block)
        super(*args, classify(options), &block)
      end

      def text_field(*args, **options, &block)
        super(*args, classify(options), &block)
      end

      def text_area(*args, **options, &block)
        super(*args, classify(options), &block)
      end

      private

      def classify(options)
        options[:classes] = class_names(options.delete(:class), options[:classes])
        options.merge!(Primer::Classify.call(options))
        options.except!(*UTILITY_KEYS)
        options[:class] = class_names(options[:class], options.delete(:classes))
        options
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
primer_view_components-0.0.114 lib/primer/forms/builder.rb
primer_view_components-0.0.113 lib/primer/forms/builder.rb
primer_view_components-0.0.112 lib/primer/forms/builder.rb
primer_view_components-0.0.111 lib/primer/forms/builder.rb
primer_view_components-0.0.110 lib/primer/forms/builder.rb
primer_view_components-0.0.109 lib/primer/forms/builder.rb
primer_view_components-0.0.108 lib/primer/forms/builder.rb
primer_view_components-0.0.107 lib/primer/forms/builder.rb
primer_view_components-0.0.106 lib/primer/forms/builder.rb
primer_view_components-0.0.105 lib/primer/forms/builder.rb
primer_view_components-0.0.104 lib/primer/forms/builder.rb
primer_view_components-0.0.103 lib/primer/forms/builder.rb
primer_view_components-0.0.102 lib/primer/forms/builder.rb
primer_view_components-0.0.101 lib/primer/forms/builder.rb
primer_view_components-0.0.100 lib/primer/forms/builder.rb
primer_view_components-0.0.99 lib/primer/forms/builder.rb
primer_view_components-0.0.98 lib/primer/forms/builder.rb
primer_view_components-0.0.97 lib/primer/forms/builder.rb
primer_view_components-0.0.96 lib/primer/forms/builder.rb
primer_view_components-0.0.95 lib/primer/forms/builder.rb