lib/cloudxls-rails/handlers/xls.rb in cloudxls-rails-0.4.1 vs lib/cloudxls-rails/handlers/xls.rb in cloudxls-rails-0.4.2

- old
+ new

@@ -1,35 +1,38 @@ 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) + columns = options.fetch(:columns, nil) + xdata = options[:data] || {} + unless (xdata.has_key?(:text) || + xdata.has_key?(:url ) || + xdata.has_key?(:file) ) -ActionController::Renderers.add :xls do |scope, options| - columns = options.fetch(:columns, nil) + xdata[:text] = CloudXLS::CSVWriter.text(scope, {:columns => columns}) + end - xdata = options[:data] || {} - unless (xdata.has_key?(:text) || - xdata.has_key?(:url ) || - xdata.has_key?(:file) ) + xopts = {:data => xdata} + xopts[:sheet] = options[:sheet] if options[:sheet] + xopts[:doc] = options[:doc] if options[:doc] - xdata[:text] = CloudXLS::CSVWriter.text(scope, {:columns => columns}) + response = CloudXLS.xpipe(xopts) + controller.redirect_to response.url + end end - - xopts = {:data => xdata} - xopts[:sheet] = options[:sheet] if options[:sheet] - xopts[:doc] = options[:doc] if options[:doc] - - response = CloudXLS.xpipe(xopts) - redirect_to response.url end # For respond_to default class ActionController::Responder def to_xls if options[:stream] == true options[:data] ||= {} options[:data][:url] ||= controller.request.url.gsub(/xls\Z/, "csv") end - controller.render({:xls => resources.last }.merge(options)) + CloudXLSRails::XLSResponder.redirect!(controller, resources.last, options) end end