<commit_before>module ActionView
  module Helpers
    class FormBuilder
      def form_row(attribute = nil, options = {}, &block)
        @form_row = FormRow.new(object: object, attribute: attribute, options: options)
        @template.render({layout: 'dough/helpers/form_row/form_row', locals: @form_row.locals}, &block)
      end

      private

      class FormRow
        attr_reader :object, :attribute, :options, :html_options

        def initialize(options = {})
          @object = options[:object]
          @attribute = options[:attribute]
          @options = options[:options]
          @html_options = HtmlOptions.new(options[:options][:html_options])
          process_html_options
        end

        def locals
          {html_options: html_options}
        end

        private

        def process_html_options
          html_options.classes << ' form__row'
          html_options.classes << ' is-errored' if errored?
        end

        def errored?
          if present?
            object.errors[attribute].any?
          else
            false
          end
        end

        def present?
          object && attribute
        end
      end

      class HtmlOptions < OpenStruct
        # magic
        def method_missing(m, *args, &block)
          unless respond_to?(m)
            self[m] = ''
          end

          super
        end
      end
    end
  end
end<commit_msg>FormRow is now dough namespaced<commit_after>module ActionView
  module Helpers
    class FormBuilder
      def form_row(attribute = nil, options = {}, &block)
        @form_row = Dough::Helpers::FormRow.new(object: object, attribute: attribute, options: options)
        @template.render({layout: 'dough/helpers/form_row/form_row', locals: @form_row.locals}, &block)
      end
    end
  end
end

module Dough
  module Helpers
    class FormRow
      attr_reader :object, :attribute, :options, :html_options

      def initialize(options = {})
        @object = options[:object]
        @attribute = options[:attribute]
        @options = options[:options]
        @html_options = HtmlOptions.new(options[:options][:html_options])
        process_html_options
      end

      def locals
        {html_options: html_options}
      end

      private

      def process_html_options
        html_options.classes << ' form__row'
        html_options.classes << ' is-errored' if errored?
      end

      def errored?
        if present?
          object.errors[attribute].any?
        else
          false
        end
      end

      def present?
        object && attribute
      end
    end

    class HtmlOptions < OpenStruct
      # magic
      def method_missing(m, *args, &block)
        unless respond_to?(m)
          self[m] = ''
        end

        super
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08645944980350125, 'fraction_numerical': 0.0, 'mean_word_length': 1.9504741833508956, 'pattern_counts': {'":': 0, '<': 13, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '944128', 'n_tokens_mistral': 791, 'n_tokens_neox': 772, 'n_words': 192}