<commit_before>module Typus

  module Format

    protected

    def generate_html
      items_count = @resource.count(:joins => @joins, :conditions => @conditions)
      items_per_page = @resource.typus_options_for(:per_page)

      @pager = ::Paginator.new(items_count, items_per_page) do |offset, per_page|
        data(:limit => per_page, :offset => offset)
      end

      @items = @pager.page(params[:page])
    end

    #--
    # TODO: Find in batches only works properly if it's used on
    #       models, not controllers, so in this action does nothing.
    #       We should find a way to be able to process data.
    #++
    def generate_csv
      fields = @resource.typus_fields_for(:csv)

      require 'csv'
      if CSV.const_defined?(:Reader)
        # Old CSV version so we enable faster CSV.
        begin
          require 'fastercsv'
        rescue Exception => error
          raise error.message
        end
        csv = FasterCSV
      else
        csv = CSV
      end

      filename = Rails.root.join("tmp", "export-#{@resource.to_resource}-#{Time.zone.now.to_s(:number)}.csv")

      options = { :conditions => @conditions, :batch_size => 1000 }

      csv.open(filename, 'w', :col_sep => ';') do |csv|<commit_msg>Cleaned how we support CSV on Ruby 1.9<commit_after>if RUBY_VERSION >= '1.9'
  require 'csv'
  FasterCSV = CSV
end

module Typus

  module Format

    protected

    def generate_html
      items_count = @resource.count(:joins => @joins, :conditions => @conditions)
      items_per_page = @resource.typus_options_for(:per_page)

      @pager = ::Paginator.new(items_count, items_per_page) do |offset, per_page|
        data(:limit => per_page, :offset => offset)
      end

      @items = @pager.page(params[:page])
    end

    #--
    # TODO: Find in batches only works properly if it's used on
    #       models, not controllers, so in this action does nothing.
    #       We should find a way to be able to process data.
    #++
    def generate_csv
      fields = @resource.typus_fields_for(:csv)

      filename = Rails.root.join("tmp", "export-#{@resource.to_resource}-#{Time.zone.now.to_s(:number)}.csv")

      options = { :conditions => @conditions, :batch_size => 1000 }

      FasterCSV.open(filename, 'w', :col_sep => ';') do |csv|
{'fraction_non_alphanumeric': 0.12101354303189166, 'fraction_numerical': 0.005242463958060288, 'mean_word_length': 2.65814696485623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4583185', 'n_tokens_mistral': 752, 'n_tokens_neox': 710, 'n_words': 193}