<commit_before>module PaginatedTable
  module ViewHelpers
    def paginated_table(collection, options = {})
      content_tag('table', :class => 'paginated') do
        content_tag('tbody') do
          safe_join(collection.map { |datum|
            content_tag('tr', '') do
              content_tag('td', datum.name)
            end
          })
        end
      end
    end
  end
end

ActionView::Base.send :include, PaginatedTable::ViewHelpers
<commit_msg>Refactor: extracts description and renderer classes<commit_after>module PaginatedTable
  module ViewHelpers
    def paginated_table(collection, options = {})
      describer_class = options.fetch(:describer, TableDescription)
      renderer_class = options.fetch(:renderer, RendersTable)
      description = describer_class.new
      yield description
      renderer = renderer_class.new(self, description, collection)
      renderer.render
    end
  end

  class TableDescription
    attr_reader :columns

    def initialize
      @columns = []
    end

    def column(name)
      @columns << Column.new(name)
    end

    class Column
      attr_reader :name

      def initialize(name)
        @name = name
      end
    end
  end

  class RendersTable
    def initialize(view, description, collection)
      @view = view
      @description = description
      @collection = collection
    end

    def render
      render_table
    end

    def render_table
      @view.content_tag('table', :class => 'paginated') do
        @view.content_tag('tbody') do
          render_rows
        end
      end
    end

    def render_rows
      @view.safe_join(@collection.map { |datum|
        @view.content_tag('tr', '') do
          render_cells(datum)
        end
      })
    end

    def render_cells(datum)
      @view.safe_join(@description.columns.map { |column|
        @view.content_tag('td', datum.send(column.name))
      })
    end
  end
end

ActionView::Base.send :include, PaginatedTable::ViewHelpers

{'fraction_non_alphanumeric': 0.09081684424150177, 'fraction_numerical': 0.0, 'mean_word_length': 2.4596491228070176, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2214085', 'n_tokens_mistral': 578, 'n_tokens_neox': 564, 'n_words': 131}