Sha256: 2f0d03dd1525ef4714a05f08d2ff483f78b5f1b2111b2a113f0abefeb01c8ddf

Contents?: true

Size: 896 Bytes

Versions: 14

Compression:

Stored size: 896 Bytes

Contents

module ActiveList
  
  class CsvExporter < ActiveList::Exporter

    def file_extension
      "csv"
    end

    def mime_type
      Mime::CSV
    end

    def send_data_code(table)
      record = "r"
      code  = table.select_data_code(:paginate => false)
      code += "data = ActiveList::CSV.generate do |csv|\n"
      code += "  csv << [#{columns_to_array(table, :header).join(', ')}]\n"
      code += "  for #{record} in #{table.records_variable_name}\n"  
      code += "    csv << [#{columns_to_array(table, :body, :record=>record).join(', ')}]\n"
      code += "  end\n"
      code += "end\n"
      code += "send_data(data, :type=>#{self.mime_type.to_s.inspect}, :disposition=>'inline', :filename=>#{table.model.name}.model_name.human.gsub(/[^a-z0-9]/i,'_')+'.#{self.file_extension}')\n"
      return code
    end

  end

end

ActiveList.register_exporter(:csv, ActiveList::CsvExporter)

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
active-list-4.2.4 lib/active-list/exporters/csv_exporter.rb
active-list-4.2.3 lib/active-list/exporters/csv_exporter.rb
active-list-4.2.2 lib/active-list/exporters/csv_exporter.rb
active-list-4.2.1 lib/active-list/exporters/csv_exporter.rb
active-list-4.2.0 lib/active-list/exporters/csv_exporter.rb
active-list-4.1.8 lib/active-list/exporters/csv_exporter.rb
active-list-4.1.7 lib/active-list/exporters/csv_exporter.rb
active-list-4.1.6 lib/active-list/exporters/csv_exporter.rb
active-list-4.1.5 lib/active-list/exporters/csv_exporter.rb
active-list-4.1.3 lib/active-list/exporters/csv_exporter.rb
active-list-4.1.2 lib/active-list/exporters/csv_exporter.rb
active-list-4.1.1 lib/active-list/exporters/csv_exporter.rb
active-list-4.1.0 lib/active-list/exporters/csv_exporter.rb
active-list-4.0.0 lib/active-list/exporters/csv_exporter.rb