<commit_before># makes a standard looking form
module ElmoFormHelper

  # renders a form using the ElmoFormBuilder
  def elmo_form_for(obj, *args, &block)
    options = args.extract_options!

    args << options.deep_merge(
      builder: ElmoFormBuilder,
      html: {
        class: "#{obj.class.model_name.singular}_form elmo_form"
      }
    ) do |key,oldval,newval|
      if key == :class
        "#{oldval} #{newval}"
      else
        newval
      end
    end

    form_for(obj, *args, &block)
  end

  # renders a set of form fields using the ElmoFormBuilder
  def elmo_fields_for(field_name, obj, *args, &block)
    options = args.extract_options!
    fields_for(field_name, obj, *(args << options.merge(:builder => ElmoFormBuilder)), &block)
  end

  # gets the mode a form should be displayed in: one of new, edit, or show
  def form_mode
    @form_mode || {new: :new, create: :new, show: :show}[controller.action_name.to_sym] || :edit
  end

  # Tests if form_mode == :show. Note that some the ElmoFormBuilder overrides form_mode when rendering custom partials
  # using the :partial directive. This is also why a ? is not used as a suffix.
  def read_only
    form_mode == :show
  end

  # renders the standard 'required' symbol, which is an asterisk
  def reqd_sym
    content_tag(:div, '*', :class => 'reqd_sym')
  end
end<commit_msg>2343: Make elmo_form_for easier to read<commit_after># makes a standard looking form
module ElmoFormHelper

  # renders a form using the ElmoFormBuilder
  def elmo_form_for(obj, *args, &block)
    options = args.extract_options!

    defaults = {
      builder: ElmoFormBuilder,
      html: {
        class: "#{obj.class.model_name.singular}_form elmo_form"
      }
    }

    # deep merge the user-provided options with the defaults;
    args << options.deep_merge(defaults) do |key,oldval,newval|
      # if the key is :class, merge the old and new values into a space-separated list
      key == :class ?  "#{oldval} #{newval}" : newval
    end

    form_for(obj, *args, &block)
  end

  # renders a set of form fields using the ElmoFormBuilder
  def elmo_fields_for(field_name, obj, *args, &block)
    options = args.extract_options!
    fields_for(field_name, obj, *(args << options.merge(:builder => ElmoFormBuilder)), &block)
  end

  # gets the mode a form should be displayed in: one of new, edit, or show
  def form_mode
    @form_mode || {new: :new, create: :new, show: :show}[controller.action_name.to_sym] || :edit
  end

  # Tests if form_mode == :show. Note that some the ElmoFormBuilder overrides form_mode when rendering custom partials
  # using the :partial directive. This is also why a ? is not used as a suffix.
  def read_only
    form_mode == :show
  end

  # renders the standard 'required' symbol, which is an asterisk
  def reqd_sym
    content_tag(:div, '*', :class => 'reqd_sym')
  end
end
{'fraction_non_alphanumeric': 0.09933774834437085, 'fraction_numerical': 0.0013942140118508191, 'mean_word_length': 3.3950995405819295, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2111992', 'n_tokens_mistral': 941, 'n_tokens_neox': 911, 'n_words': 311}