xlsxtream_rails 0.1.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -14
- data/lib/xlsxtream_rails/action_controller.rb +4 -3
- data/lib/xlsxtream_rails/railtie.rb +0 -5
- data/lib/xlsxtream_rails/version.rb +1 -1
- metadata +4 -5
- data/lib/xlsxtream_rails/template_handler.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5502fc92614bd2379b7af762136ac5d37621264a14a8c95dd0c1675c06f8f8c1
|
4
|
+
data.tar.gz: cf4eb50326cf589174c1dc941392a12f054d5142c48d2293b210100f37551403
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1171bb419c8a365726ed516eb46f53ef6a658462ad1a810629ecec67fb69c040afcbe0c6d41adf785edf7da33161bb41cfd10008d163d5c79ed5ce783c89a81f
|
7
|
+
data.tar.gz: 70566d1a3ff138d3840a343e6e6a6218fd13636764784a87656149856d702f3aa34d48ad5a409221c2ec9da0297adcdc974f09ae5c88abe65601e86269526e58
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# XlsxtreamRails
|
2
|
-
Xlsx stream download for rails
|
2
|
+
Xlsx stream download for rails.
|
3
3
|
|
4
4
|
## Installation
|
5
5
|
Add this line to your application's Gemfile:
|
@@ -27,7 +27,7 @@ class PostsController < ApplicationController
|
|
27
27
|
def index
|
28
28
|
@posts = Post.all
|
29
29
|
respond_to do |format|
|
30
|
-
format.xlsx
|
30
|
+
format.xlsx { render xlsx: @posts }
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
@@ -61,18 +61,6 @@ class Post < ApplicationRecord
|
|
61
61
|
end
|
62
62
|
```
|
63
63
|
|
64
|
-
## View
|
65
|
-
|
66
|
-
If you want to render with template, you can create the template with the .xlsx.xrb extension (index.xlsx.xrb for example)
|
67
|
-
|
68
|
-
```ruby
|
69
|
-
xlsx.write_worksheet do |sheet|
|
70
|
-
@posts.find_each do |post|
|
71
|
-
sheet.add_row [post.id, post.title]
|
72
|
-
end
|
73
|
-
end
|
74
|
-
```
|
75
|
-
|
76
64
|
## This gem is inspired by the following
|
77
65
|
|
78
66
|
[spreadsheet_architect](https://github.com/westonganger/spreadsheet_architect)
|
@@ -9,12 +9,13 @@ ActionController::Renderers.add :xlsx do |data, options|
|
|
9
9
|
# disposition / filename
|
10
10
|
options[:disposition] = options.delete(:disposition) || "attachment"
|
11
11
|
|
12
|
-
if defined?(ActiveRecord) && data.is_a?(ActiveRecord::Relation)
|
13
|
-
|
12
|
+
options[:filename] ||= if defined?(ActiveRecord) && data.is_a?(ActiveRecord::Relation)
|
13
|
+
"#{data.klass.model_name.human}_#{Time.now.to_i}"
|
14
|
+
else
|
15
|
+
Time.now.to_i
|
14
16
|
end
|
15
17
|
|
16
18
|
options[:filename] = options[:filename] ? options[:filename].strip.sub(/\.xlsx$/i, "") : "data"
|
17
|
-
options[:filename] += ".xlsx"
|
18
19
|
|
19
20
|
headers["Content-Type"] = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
20
21
|
headers["Content-disposition"] = "attachment; filename=\"#{options[:filename]}.xlsx\""
|
@@ -1,11 +1,6 @@
|
|
1
1
|
module XlsxtreamRails
|
2
2
|
class Railtie < ::Rails::Railtie
|
3
3
|
initializer "xlsxtream_rails.initialization" do
|
4
|
-
ActiveSupport.on_load(:action_view) do
|
5
|
-
require "xlsxtream_rails/template_handler"
|
6
|
-
ActionView::Template.register_template_handler :xrb, ActionView::Template::Handlers::XrbBuilder.new
|
7
|
-
end
|
8
|
-
|
9
4
|
ActiveSupport.on_load(:action_controller) do
|
10
5
|
require "xlsxtream_rails/action_controller"
|
11
6
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xlsxtream_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- doabit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.4.0
|
41
|
-
description: Xlsx stream download for rails
|
41
|
+
description: Xlsx stream download for rails.
|
42
42
|
email:
|
43
43
|
- doinsist@gmail.com
|
44
44
|
executables: []
|
@@ -52,7 +52,6 @@ files:
|
|
52
52
|
- lib/xlsxtream_rails.rb
|
53
53
|
- lib/xlsxtream_rails/action_controller.rb
|
54
54
|
- lib/xlsxtream_rails/railtie.rb
|
55
|
-
- lib/xlsxtream_rails/template_handler.rb
|
56
55
|
- lib/xlsxtream_rails/utils.rb
|
57
56
|
- lib/xlsxtream_rails/version.rb
|
58
57
|
homepage: https://github.com/ruby-gems/xlsxtream_rails
|
@@ -80,5 +79,5 @@ requirements: []
|
|
80
79
|
rubygems_version: 3.2.3
|
81
80
|
signing_key:
|
82
81
|
specification_version: 4
|
83
|
-
summary: Xlsx stream download for rails
|
82
|
+
summary: Xlsx stream download for rails.
|
84
83
|
test_files: []
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require "action_view"
|
2
|
-
require "stringio"
|
3
|
-
|
4
|
-
module ActionView
|
5
|
-
module Template::Handlers
|
6
|
-
class XrbBuilder
|
7
|
-
def default_format
|
8
|
-
Mime[:xlsx].symbol
|
9
|
-
end
|
10
|
-
|
11
|
-
def call(template, source = nil)
|
12
|
-
builder = StringIO.new
|
13
|
-
builder << "# encoding: utf-8\n"
|
14
|
-
builder << (source || template.source)
|
15
|
-
builder.string
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|