cloudxls-rails 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
- # CloudXLSRails::CSVStream
1
+ # CloudXLSRails::CSVResponder
2
2
  module CloudXLSRails
3
- class CSVStream
3
+ class CSVResponder
4
4
  def initialize(controller, stream)
5
5
  @controller = controller
6
6
  @stream = stream
@@ -36,7 +36,7 @@ ActionController::Renderers.add :csv do |scope, options|
36
36
  columns = options[:columns]
37
37
 
38
38
  if options[:stream] == true
39
- CloudXLSRails::CSVStream.stream!(self, scope, options)
39
+ CloudXLSRails::CSVResponder.stream!(self, scope, options)
40
40
  else # no stream:
41
41
  data = CloudXLS::CSVWriter.text(scope, {:columns => columns})
42
42
 
@@ -49,7 +49,7 @@ end
49
49
  class ActionController::Responder
50
50
  def to_csv
51
51
  if options[:stream] == true
52
- CloudXLSRails::CSVStream.stream!(controller, resources.last, options)
52
+ CloudXLSRails::CSVResponder.stream!(controller, resources.last, options)
53
53
  else
54
54
  controller.render({:csv => resources.last, :stream => false }.merge(options))
55
55
  end
@@ -2,24 +2,27 @@ unless defined? Mime::XLS
2
2
  Mime::Type.register "application/vnd.ms-excel", :xls
3
3
  end
4
4
 
5
-
6
- ActionController::Renderers.add :xls do |scope, options|
7
- columns = options.fetch(:columns, nil)
8
-
9
- xdata = options[:data] || {}
10
- unless (xdata.has_key?(:text) ||
11
- xdata.has_key?(:url ) ||
12
- xdata.has_key?(:file) )
13
-
14
- xdata[:text] = CloudXLS::CSVWriter.text(scope, {:columns => columns})
5
+ # CloudXLSRails::XLSResponder
6
+ module CloudXLSRails
7
+ class XLSResponder
8
+ def self.redirect!(controller, scope, options)
9
+ columns = options.fetch(:columns, nil)
10
+ xdata = options[:data] || {}
11
+ unless (xdata.has_key?(:text) ||
12
+ xdata.has_key?(:url ) ||
13
+ xdata.has_key?(:file) )
14
+
15
+ xdata[:text] = CloudXLS::CSVWriter.text(scope, {:columns => columns})
16
+ end
17
+
18
+ xopts = {:data => xdata}
19
+ xopts[:sheet] = options[:sheet] if options[:sheet]
20
+ xopts[:doc] = options[:doc] if options[:doc]
21
+
22
+ response = CloudXLS.xpipe(xopts)
23
+ controller.redirect_to response.url
24
+ end
15
25
  end
16
-
17
- xopts = {:data => xdata}
18
- xopts[:sheet] = options[:sheet] if options[:sheet]
19
- xopts[:doc] = options[:doc] if options[:doc]
20
-
21
- response = CloudXLS.xpipe(xopts)
22
- redirect_to response.url
23
26
  end
24
27
 
25
28
 
@@ -30,6 +33,6 @@ class ActionController::Responder
30
33
  options[:data] ||= {}
31
34
  options[:data][:url] ||= controller.request.url.gsub(/xls\Z/, "csv")
32
35
  end
33
- controller.render({:xls => resources.last }.merge(options))
36
+ CloudXLSRails::XLSResponder.redirect!(controller, resources.last, options)
34
37
  end
35
38
  end
@@ -2,26 +2,31 @@ unless defined? Mime::XLSX
2
2
  Mime::Type.register "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :xlsx
3
3
  end
4
4
 
5
- ActionController::Renderers.add :xlsx do |scope, options|
6
- columns = options.fetch(:columns, nil)
5
+ # CloudXLSRails::XLSResponder
6
+ module CloudXLSRails
7
+ class XLSXResponder
8
+ def self.redirect!(controller, scope, options)
9
+ columns = options.fetch(:columns, nil)
10
+ xdata = options[:data] || {}
11
+ unless (xdata.has_key?(:text) ||
12
+ xdata.has_key?(:url ) ||
13
+ xdata.has_key?(:file) )
7
14
 
8
- xdata = options[:data] || {}
9
- unless (xdata.has_key?(:text) ||
10
- xdata.has_key?(:url ) ||
11
- xdata.has_key?(:file) )
15
+ xdata[:text] = CloudXLS::CSVWriter.text(scope, {:columns => columns})
16
+ end
12
17
 
13
- xdata[:text] = CloudXLS::CSVWriter.text(scope, {:columns => columns})
14
- end
15
-
16
- xopts = {:data => xdata}
17
- xopts[:sheet] = options[:sheet] if options[:sheet]
18
- xopts[:doc] = options[:doc] || {}
19
- xopts[:doc][:format] = 'xlsx'
18
+ xopts = {:data => xdata}
19
+ xopts[:sheet] = options[:sheet] if options[:sheet]
20
+ xopts[:doc] = options[:doc] || {}
21
+ xopts[:doc][:format] = 'xlsx'
20
22
 
21
- response = CloudXLS.xpipe(xopts)
22
- redirect_to response.url
23
+ response = CloudXLS.xpipe(xopts)
24
+ controller.redirect_to response.url
25
+ end
26
+ end
23
27
  end
24
28
 
29
+
25
30
  # For respond_to default
26
31
  class ActionController::Responder
27
32
  def to_xlsx
@@ -29,6 +34,6 @@ class ActionController::Responder
29
34
  options[:data] ||= {}
30
35
  options[:data][:url] ||= controller.request.url.gsub(/xlsx\Z/, "csv")
31
36
  end
32
- controller.render({:xlsx => resources.last }.merge(options))
37
+ CloudXLSRails::XLSXResponder.redirect!(controller, resources.last, options)
33
38
  end
34
39
  end
@@ -1,3 +1,3 @@
1
1
  module CloudXLSRails
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudxls-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: