Sha256: e3f4a22c21deb73b336da01f54c6fb6ef2fccf088685b6437efdfd137b18fade

Contents?: true

Size: 1.01 KB

Versions: 20

Compression:

Stored size: 1.01 KB

Contents

# Register XCSV format unless is already set
Mime::Type.register('text/csv', :xcsv) unless defined? Mime::XCSV

module ActiveList
  module Exporters
    class ExcelCsvExporter < CsvExporter
      def file_extension
        'csv'
      end

      def mime_type
        Mime::XCSV
      end

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
active_list-6.10.0 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.9.4 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.9.3 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.9.2 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.9.1 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.9.0 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.8.3 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.8.2 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.8.1 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.8.0 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.7.6 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.7.5 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.7.4 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.7.3 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.7.2 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.7.1 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.7.0 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.6.2 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.6.1 lib/active_list/exporters/excel_csv_exporter.rb
active_list-6.6.0 lib/active_list/exporters/excel_csv_exporter.rb