<commit_before>module Typus

  module Format

    protected

    def generate_html

      items_count = @resource[:class].count(:joins => @joins, :conditions => @conditions)
      items_per_page = @resource[:class].typus_options_for(:per_page).to_i

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

        @resource[:class].find(:all, 
                               :joins => @joins, 
                               :conditions => @conditions, 
                               :order => @order, 
                               :limit => per_page, 
                               :offset => offset)
      end

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

      select_template :index

    end

    def generate_csv

      require 'fastercsv'

      @items = @resource[:class].find(:all, :joins => @joins, :conditions => @conditions, :order => @order)

      fields = @resource[:class].typus_fields_for(:csv).collect { |i| i.first }
      csv_string = FasterCSV.generate do |csv|
        csv << fields
        @items.each do |item|
          csv << fields.map { |f| item.send(f) }
        end
      end

      filename = "#{Time.now.strftime("%Y%m%d")}_#{@resource[:self]}.csv"
      send_data(csv_string,
               :type => 'text/csv; charset=utf-8; header=present',
               :filename => filename)

    rescue LoadError
      render :text => "FasterCSV is not installed."
    end

    def generate_xml
      @items = @resource[:class].find(:all, :joins => @joins, :conditions => @conditions, :order => @order)
      render :xml => @items
    end

  end

end<commit_msg>Refactored finder.<commit_after>module Typus

  module Format

    protected

    def generate_html

      items_count = @resource[:class].count(:joins => @joins, :conditions => @conditions)
      items_per_page = @resource[:class].typus_options_for(:per_page).to_i

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

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

      select_template :index

    end

    def generate_csv

      require 'fastercsv'

      fields = @resource[:class].typus_fields_for(:csv).collect { |i| i.first }
      csv_string = FasterCSV.generate do |csv|
        csv << fields
        data.each do |item|
          csv << fields.map { |f| item.send(f) }
        end
      end

      filename = "#{Time.now.strftime("%Y%m%d")}_#{@resource[:self]}.csv"
      send_data(csv_string,
               :type => 'text/csv; charset=utf-8; header=present',
               :filename => filename)

    rescue LoadError
      render :text => "FasterCSV is not installed."
    end

    def generate_xml
      render :xml => data
    end

    def data(*args)
      options = { :joins => @joins, :conditions => @conditions, :order => @order }
      options.merge!(args.extract_options!)
      @resource[:class].find(:all, options)
    end

  end

end
{'fraction_non_alphanumeric': 0.13576494427558258, 'fraction_numerical': 0.0006754474839581223, 'mean_word_length': 2.2442497261774372, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '2534476', 'n_tokens_mistral': 938, 'n_tokens_neox': 892, 'n_words': 194}