<commit_before>module BootstrapFormHelper
  include ActionView::Helpers

  mattr_accessor :layout
  @@field_helpers = [:email_field, :password_field, :text_field, :text_area, :search_field, :telephone_field,
                     :url_field, :number_field]

  def form_for(record, options = {}, &block)
    html_options = options[:html] ||= {}

    form_layout = case options.delete(:layout).try(:to_sym)
                    when :horizontal
                      self.layout = :horizontal
                      'form form-horizontal'
                    when :inline
                      self.layout = :inline
                      'form form-inline'
                    else
                      self.layout = :basic
                      options[:layout] = :basic
                      'form'
                  end

    html_options[:class] = squeeze_n_strip("#{form_layout} #{html_options[:class]}")
    options[:html]       = html_options

    super
  end

  # TODO: file_field, check_box, radio_button, color_field, date_field, time_field, datetime_field,
  #       datetime_local_field, month_field, week_field, range_field

  @@field_helpers.each do |helper|
    define_method helper do |object_name, method, options={}|
      label_class, field_wrapper = case self.layout
                                     when :inline
                                       'sr-only'
                                     when :horizontal
                                       ['col-sm-3 control-label', true]
                                     else
                                   end

      options[:class] = squeeze_n_strip("form-control #{options[:class]}")

      content_tag :div, class: 'form-group' do
        if field_wrapper
          (label(object_name, method, options[:label], class: label_class) +
            (content_tag :div, class: 'col-sm-9' do
              super(object_name, method, options)
            end)).html_safe
        else
          (label(object_name, method, options[:label], class: label_class) + super(object_name, method, options)).html_safe
        end
      end
    end
  end

  class ActionView::Helpers::FormBuilder
    include BootstrapFormHelper

    attr_accessor :output_buffer

    def submit(value=nil, options={})
      value, options = nil, value if value.is_a?(Hash)
      value ||= submit_default_value

      options[:class] = "btn btn-primary #{options[:class]}"

      if BootstrapFormHelper.layout == :horizontal
        content_tag :div, class: 'form-group' do
          content_tag :div, class: 'col-sm-offset-3 col-sm-9' do
            @template.submit_tag(value, options)
          end
        end
      else
        @template.submit_tag(value, options)
      end
    end
  end

end
<commit_msg>add check_box field and radio_button helpers<commit_after>module BootstrapFormHelper
  include ActionView::Helpers

  mattr_accessor :layout
  @@field_helpers = [:email_field, :password_field, :text_field, :text_area, :search_field, :telephone_field,
                     :url_field, :number_field]

  def form_for(record, options = {}, &block)
    html_options = options[:html] ||= {}

    form_layout = case options.delete(:layout).try(:to_sym)
                    when :horizontal
                      self.layout = :horizontal
                      'form form-horizontal'
                    when :inline
                      self.layout = :inline
                      'form form-inline'
                    else
                      self.layout = :basic
                      options[:layout] = :basic
                      'form'
                  end

    html_options[:class] = squeeze_n_strip("#{form_layout} #{html_options[:class]}")
    options[:html]       = html_options

    super
  end

  # TODO: file_field, check_box, radio_button, color_field, date_field, time_field, datetime_field,
  #       datetime_local_field, month_field, week_field, range_field

  @@field_helpers.each do |helper|
    define_method helper do |object_name, method, options={}|
      label_class, field_wrapper = case self.layout
                                     when :inline
                                       'sr-only'
                                     when :horizontal
                                       ['col-sm-3 control-label', true]
                                     else
                                   end

      options[:class] = squeeze_n_strip("form-control #{options[:class]}")

      content_tag :div, class: 'form-group' do
        if field_wrapper
          (label(object_name, method, options[:label], class: label_class) +
            (content_tag :div, class: 'col-sm-9' do
              super(object_name, method, options)
            end)).html_safe
        else
          (label(object_name, method, options[:label], class: label_class) + super(object_name, method, options)).html_safe
        end
      end
    end
  end

  class ActionView::Helpers::FormBuilder
    include BootstrapFormHelper

    attr_accessor :output_buffer

    def check_box(method, options = {}, checked_value = '1', unchecked_value = '0')
      layout_inline = options.delete(:layout).try(:to_sym) == :inline

      check_box = Proc.new do
        proc = Proc.new do
          @template.check_box(@object_name, method, objectify_options(options), checked_value, unchecked_value) + options[:label]
        end

        if layout_inline
          content_tag :label, class: 'checkbox-inline' do
            proc.call
          end
        else
          content_tag :div, class: 'checkbox' do
            content_tag :label do
              proc.call
            end
          end
        end
      end

      if horizontal_layout?
        content_tag :div, class: 'form-group' do
          content_tag :div, class: 'col-sm-offset-3 col-sm-9' do
            check_box.call
          end
        end
      else
        check_box.call
      end
    end

    def radio_button(method, tag_value, options = {})
      layout_inline = options.delete(:layout).try(:to_sym) == :inline

      radio_button = Proc.new do
        proc = Proc.new do
          @template.radio_button(@object_name, method, tag_value, objectify_options(options)) + options[:label]
        end

        if layout_inline
          content_tag :label, class: 'radio-inline' do
            proc.call
          end
        else
          content_tag :div, class: 'radio' do
            content_tag :label do
              proc.call
            end
          end
        end
      end

      if horizontal_layout?
        content_tag :div, class: 'form-group' do
          content_tag :div, class: 'col-sm-offset-3 col-sm-9' do
            radio_button.call
          end
        end
      else
        radio_button.call
      end
    end

    def submit(value=nil, options={})
      value, options = nil, value if value.is_a?(Hash)
      value ||= submit_default_value

      options[:class] = "btn btn-primary #{options[:class]}"

      if horizontal_layout?
        content_tag :div, class: 'form-group' do
          content_tag :div, class: 'col-sm-offset-3 col-sm-9' do
            @template.submit_tag(value, options)
          end
        end
      else
        @template.submit_tag(value, options)
      end
    end

    private
    def horizontal_layout?
      BootstrapFormHelper.layout == :horizontal
    end
  end

end

{'fraction_non_alphanumeric': 0.09292215731558212, 'fraction_numerical': 0.00190191550061133, 'mean_word_length': 1.7552395209580838, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6184083', 'n_tokens_mistral': 2051, 'n_tokens_neox': 1971, 'n_words': 474}