Sha256: cb694a5fcb5f955b9304eeceb54ef1e51af9d141e6e62aa1c85600830a41b8b6

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

unless defined? Mime::XLS
  Mime::Type.register "application/vnd.ms-excel", :xls
end

# CloudXLSRails::XLSResponder
module CloudXLSRails
  class XLSResponder
    def self.redirect!(controller, scope, options)
      xdata = options[:data] || {}
      unless (xdata.has_key?(:text) ||
              xdata.has_key?(:url ) ||
              xdata.has_key?(:file)  )

        xdata[:text] = CloudXLS::CSVWriter.text(scope, options)
      end

      xopts = {:data => xdata}
      xopts[:sheet] = options[:sheet] if options[:sheet]
      xopts[:doc]   = options[:doc]   if options[:doc]

      response = CloudXLS.xpipe(xopts)
      controller.redirect_to response.url
    end
  end
end


# For respond_to default
class ActionController::Responder
  def to_xls
    stream = options.delete(:stream) || false
    if stream # either string or boolean
      options[:data] ||= {}
      options[:data][:url] ||= cloudxls_stream_url(stream, 'xls')
    end
    CloudXLSRails::XLSResponder.redirect!(controller, resources.last, options)
  end

protected
  def cloudxls_stream_url(stream, extension = 'xls')
    if stream == true
      controller.request.url.gsub(/#{extension}\Z/, "csv")
    else
      stream.to_s
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cloudxls-rails-0.6.2 lib/cloudxls-rails/handlers/xls.rb
cloudxls-rails-0.6.1 lib/cloudxls-rails/handlers/xls.rb
cloudxls-rails-0.6.0 lib/cloudxls-rails/handlers/xls.rb
cloudxls-rails-0.5.0 lib/cloudxls-rails/handlers/xls.rb