Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 4 files changed
  • 0 comments
  • 1 contributor
Jul 19, 2012
Heinrich Lee Yu Fix parameters to render_to_string
render_to_string API is render_to_string(options = nil, &block)
Also changed tabs to newlines for consistency
cf04b6a
Heinrich Lee Yu Fix test case for downloading with filename f104b48
19  lib/axlsx_rails/action_controller.rb
@@ -2,15 +2,18 @@
2 2
 Mime::Type.register "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :xlsx
3 3
 
4 4
 ActionController::Renderers.add :xlsx do |filename, options|
5  
-	disposition   = options.delete(:disposition) || 'attachment'
6  
-	download_name = options.delete(:filename) || "#{filename}.xlsx"
7  
-	download_name += ".xlsx" unless download_name =~ /\.xlsx$/
8  
-	send_data render_to_string(filename, options), :filename => download_name, :type => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :disposition => disposition
  5
+  options[:template] = filename
  6
+
  7
+  disposition   = options.delete(:disposition) || 'attachment'
  8
+  download_name = options.delete(:filename) || "#{filename}.xlsx"
  9
+  download_name += ".xlsx" unless download_name =~ /\.xlsx$/
  10
+
  11
+  send_data render_to_string(options), :filename => download_name, :type => Mime::XLSX, :disposition => disposition
9 12
 end
10 13
 
11 14
 # For respond_to default
12 15
 class ActionController::Responder
13  
-	def to_xlsx
14  
-		controller.render :xlsx => controller.action_name
15  
-	end
16  
-end
  16
+  def to_xlsx
  17
+    controller.render :xlsx => controller.action_name
  18
+  end
  19
+end
6  lib/axlsx_rails/template_handler.rb
@@ -5,9 +5,9 @@ class AxlsxBuilder
5 5
       def default_format
6 6
         Mime::XLSX
7 7
       end
8  
-      
  8
+
9 9
       def self.call(template)
10  
-        "xlsx_package = Axlsx::Package.new(:author => #{axlsx_author.inspect});\n" + 
  10
+        "xlsx_package = Axlsx::Package.new(:author => #{axlsx_author.inspect});\n" +
11 11
           template.source +
12 12
           ";\nxlsx_package.to_stream.string;"
13 13
       end
@@ -21,4 +21,4 @@ def self.axlsx_author
21 21
   end
22 22
 end
23 23
 
24  
-ActionView::Template.register_template_handler :axlsx, ActionView::Template::Handlers::AxlsxBuilder
  24
+ActionView::Template.register_template_handler :axlsx, ActionView::Template::Handlers::AxlsxBuilder
9  spec/axlsx_request_spec.rb
@@ -17,9 +17,10 @@
17 17
 
18 18
   it "downloads an excel file from render statement with filename" do
19 19
     visit '/another.xlsx'
20  
-    page.response_headers['Content-Type'].should == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8"
21  
-    # Not being sent for some reason
22  
-    # page.response_headers['Content-Disposition'].should include("filename=\"filename_test.xlsx\"")
  20
+
  21
+    page.response_headers['Content-Type'].should == Mime::XLSX
  22
+    page.response_headers['Content-Disposition'].should include("filename=\"filename_test.xlsx\"")
  23
+
23 24
     File.open('/tmp/axlsx_temp.xlsx', 'w') {|f| f.write(page.source) }
24 25
     wb = nil
25 26
     expect{ wb = Excelx.new('/tmp/axlsx_temp.xlsx') }.to_not raise_error
@@ -37,4 +38,4 @@
37 38
     wb.cell(3,2).should == 'Bugs'
38 39
   end
39 40
 
40  
-end
  41
+end
2  spec/dummy/app/controllers/home_controller.rb
@@ -8,7 +8,7 @@
8 8
 #---
9 9
 class HomeController < ApplicationController
10 10
   def another
11  
-    render "index", :filename => "filename_test.xlsx"
  11
+    render :xlsx => "index", :filename => "filename_test.xlsx"
12 12
   end
13 13
 
14 14
   def index

No commit comments for this range

Something went wrong with that request. Please try again.