xlsxtream_rails 0.2.0 → 0.5.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 +1 -13
- data/lib/xlsxtream_rails/action_controller.rb +4 -2
- data/lib/xlsxtream_rails/class_methods.rb +8 -0
- data/lib/xlsxtream_rails/railtie.rb +0 -5
- data/lib/xlsxtream_rails/version.rb +1 -1
- data/lib/xlsxtream_rails.rb +6 -2
- metadata +5 -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: 9a54b0cad604244bd9547c4b096192ac193b7e326dc4b013eab909b78edea6c2
|
4
|
+
data.tar.gz: e565f309ddb38b134d307c1558dad4a2b0696787688af64853923de4bbbde1d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cac8f0033dd5a7d1b2af96243e011d573da24885a2013ce819d66d806da6b28b88c18d30f6c9cd9bd96d61402df45bdd6081efe57a9ea2b2badcbec67728e66d
|
7
|
+
data.tar.gz: 1dfa9fffbdc4092d0ae4641d5311eaa27940fcad75af1b28645f75109622ea4543243ec3ef70fb45172c065359158326647d88b80995098243431f61590e1a7d
|
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:
|
@@ -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,8 +9,10 @@ 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"
|
@@ -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
|
data/lib/xlsxtream_rails.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
require "xlsxtream"
|
2
|
+
require "xlsxtream_rails/class_methods"
|
2
3
|
require "xlsxtream_rails/utils"
|
3
4
|
require "xlsxtream_rails/version"
|
4
5
|
require "xlsxtream_rails/railtie"
|
5
6
|
|
6
7
|
module XlsxtreamRails
|
8
|
+
def self.included(base)
|
9
|
+
base.send(:extend, ClassMethods)
|
10
|
+
end
|
11
|
+
|
7
12
|
def xlsx_columns(opts = {})
|
8
|
-
|
9
|
-
column_names.map { |x| x.to_sym }
|
13
|
+
self.class.to_xlsx
|
10
14
|
end
|
11
15
|
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.5.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: []
|
@@ -51,8 +51,8 @@ files:
|
|
51
51
|
- lib/tasks/xlsxtream_rails_tasks.rake
|
52
52
|
- lib/xlsxtream_rails.rb
|
53
53
|
- lib/xlsxtream_rails/action_controller.rb
|
54
|
+
- lib/xlsxtream_rails/class_methods.rb
|
54
55
|
- lib/xlsxtream_rails/railtie.rb
|
55
|
-
- lib/xlsxtream_rails/template_handler.rb
|
56
56
|
- lib/xlsxtream_rails/utils.rb
|
57
57
|
- lib/xlsxtream_rails/version.rb
|
58
58
|
homepage: https://github.com/ruby-gems/xlsxtream_rails
|
@@ -80,5 +80,5 @@ requirements: []
|
|
80
80
|
rubygems_version: 3.2.3
|
81
81
|
signing_key:
|
82
82
|
specification_version: 4
|
83
|
-
summary: Xlsx stream download for rails
|
83
|
+
summary: Xlsx stream download for rails.
|
84
84
|
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
|