Sha256: a23a4730309eabb93e5d83121992675e7bc1071d6d3de25b19e8fcd13d3af2c0

Contents?: true

Size: 1.78 KB

Versions: 9

Compression:

Stored size: 1.78 KB

Contents

require 'active_support/core_ext/module/attribute_accessors'

module ActiveList

  mattr_reader :exporters
  @@exporters = {}

  def self.register_exporter(name, exporter)
    raise ArgumentError.new("ActiveList::Exporter expected (got #{exporter.name}/#{exporter.ancestors.inspect})") unless exporter.ancestors.include? ActiveList::Exporter
    @@exporters[name] = exporter.new(name)
  end
  
  class Exporter
    attr_reader :name

    def initialize(name)
      @name = name
    end

    def file_extension
      "txt"
    end
    
    def mime_type
      Mime::TEXT
    end

    # Not used
    # def condition
    #   "not request.xhr? and params[:format] == '#{name}'"
    # end
       
    def send_data_code(table)
      raise NotImplementedError.new("#{self.class.name}#format_data_code is not implemented.")
    end

    def columns_headers(table, options={})
      headers, columns = [], table.exportable_columns
      for column in columns
        datum = column.header_code
        headers << (options[:iconv] ? "#{options[:iconv]}.iconv("+datum+".to_s)" : datum)
      end
      return headers
    end
    
    def columns_to_array(table, nature, options={})
      columns = table.exportable_columns
      
      array = []
      record = options[:record]||'rekord'
      for column in columns
        if column.is_a? ActiveList::Column
          if nature==:header
            datum = column.header_code
          else
            datum = column.exporting_datum_code(record)
          end
          array << (options[:iconv] ? "#{options[:iconv]}.iconv("+datum+".to_s)" : datum)
        end
      end
      return array
    end

  end

end


require "active-list/exporters/open_document_spreadsheet_exporter"
require "active-list/exporters/csv_exporter"
require "active-list/exporters/excel_csv_exporter"

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
active-list-4.1.8 lib/active-list/exporters.rb
active-list-4.1.7 lib/active-list/exporters.rb
active-list-4.1.6 lib/active-list/exporters.rb
active-list-4.1.5 lib/active-list/exporters.rb
active-list-4.1.3 lib/active-list/exporters.rb
active-list-4.1.2 lib/active-list/exporters.rb
active-list-4.1.1 lib/active-list/exporters.rb
active-list-4.1.0 lib/active-list/exporters.rb
active-list-4.0.0 lib/active-list/exporters.rb