cloudxls-rails 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
|
|
1
|
-
# CloudXLSRails::
|
1
|
+
# CloudXLSRails::CSVResponder
|
2
2
|
module CloudXLSRails
|
3
|
-
class
|
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::
|
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::
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
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
|
-
|
6
|
-
|
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
|
-
|
9
|
-
|
10
|
-
xdata.has_key?(:url ) ||
|
11
|
-
xdata.has_key?(:file) )
|
15
|
+
xdata[:text] = CloudXLS::CSVWriter.text(scope, {:columns => columns})
|
16
|
+
end
|
12
17
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
22
|
-
|
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
|
-
|
37
|
+
CloudXLSRails::XLSXResponder.redirect!(controller, resources.last, options)
|
33
38
|
end
|
34
39
|
end
|