<commit_before><%-
  require 'csv'

  default = active_admin_application.csv_options
  options = default.merge active_admin_config.csv_builder.options
  columns = active_admin_config.csv_builder.render_columns(self)

  csv_output = CSV.generate(options) do |csv|
    csv << columns.map(&:name)
    collection.each do |resource|
      csv << columns.map do |column|
        call_method_or_proc_on resource, column.data
      end
    end
  end
%>
<%= csv_output.html_safe %><commit_msg>Workaround for CSV#generate encoding issue.<commit_after><%-
  require 'csv'

  default = active_admin_application.csv_options
  options = default.merge active_admin_config.csv_builder.options
  columns = active_admin_config.csv_builder.render_columns(self)

  encoding = options[:encoding]

  csv_output = CSV.generate(options) do |csv|
    csv << columns.map(&:name)
    collection.each do |resource|
      csv << columns.map do |column|
        s = call_method_or_proc_on resource, column.data
        s.encode!(encoding) if !encoding.nil? && s.respond_to?(:encode!)
        s
      end
    end
  end
%>
<%= csv_output.html_safe %>
{'fraction_non_alphanumeric': 0.10912343470483005, 'fraction_numerical': 0.0, 'mean_word_length': 3.8025751072961373, 'pattern_counts': {'":': 0, '<': 15, '<?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': '5316008', 'n_tokens_mistral': 370, 'n_tokens_neox': 348, 'n_words': 72}