columnify 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +146 -0
- data/README.md +12 -0
- data/columnify.gemspec +1 -0
- data/lib/columnify.rb +2 -2
- data/lib/columnify/columnify_template.rb +5 -26
- data/lib/columnify/railtie.rb +2 -0
- data/lib/columnify/version.rb +1 -1
- data/lib/columnify/worksheet.rb +62 -0
- metadata +25 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb341ed259e90cc3c387e4b9d5ca32f52a492d929382297470da93bd6570c13e
|
4
|
+
data.tar.gz: b85795e08d28b364ca3cdab2c657c2ce567795db9045c09bc1a8b68e5a5ff846
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0859c1b06a9db307b586c247329ad959609cb8e8ba5647df9871fe1a33b26850d00844538ee6108b5cb7859c8a91ec821a097cfb35e2e034850744ab18c1489b'
|
7
|
+
data.tar.gz: 3a96c7b355368521a2805a037f91d04e6a421ec1a222c7606498d1808c13bce7bfa12fc8bbbbd16819037721658edfa2c2d21c8bacada986d3867293e5e9192a
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
columnify (0.1.0)
|
5
|
+
rails (>= 5.0, <= 6.0)
|
6
|
+
spreadsheet
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actioncable (5.2.3)
|
12
|
+
actionpack (= 5.2.3)
|
13
|
+
nio4r (~> 2.0)
|
14
|
+
websocket-driver (>= 0.6.1)
|
15
|
+
actionmailer (5.2.3)
|
16
|
+
actionpack (= 5.2.3)
|
17
|
+
actionview (= 5.2.3)
|
18
|
+
activejob (= 5.2.3)
|
19
|
+
mail (~> 2.5, >= 2.5.4)
|
20
|
+
rails-dom-testing (~> 2.0)
|
21
|
+
actionpack (5.2.3)
|
22
|
+
actionview (= 5.2.3)
|
23
|
+
activesupport (= 5.2.3)
|
24
|
+
rack (~> 2.0)
|
25
|
+
rack-test (>= 0.6.3)
|
26
|
+
rails-dom-testing (~> 2.0)
|
27
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
28
|
+
actionview (5.2.3)
|
29
|
+
activesupport (= 5.2.3)
|
30
|
+
builder (~> 3.1)
|
31
|
+
erubi (~> 1.4)
|
32
|
+
rails-dom-testing (~> 2.0)
|
33
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
34
|
+
activejob (5.2.3)
|
35
|
+
activesupport (= 5.2.3)
|
36
|
+
globalid (>= 0.3.6)
|
37
|
+
activemodel (5.2.3)
|
38
|
+
activesupport (= 5.2.3)
|
39
|
+
activerecord (5.2.3)
|
40
|
+
activemodel (= 5.2.3)
|
41
|
+
activesupport (= 5.2.3)
|
42
|
+
arel (>= 9.0)
|
43
|
+
activestorage (5.2.3)
|
44
|
+
actionpack (= 5.2.3)
|
45
|
+
activerecord (= 5.2.3)
|
46
|
+
marcel (~> 0.3.1)
|
47
|
+
activesupport (5.2.3)
|
48
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
49
|
+
i18n (>= 0.7, < 2)
|
50
|
+
minitest (~> 5.1)
|
51
|
+
tzinfo (~> 1.1)
|
52
|
+
arel (9.0.0)
|
53
|
+
builder (3.2.4)
|
54
|
+
concurrent-ruby (1.1.6)
|
55
|
+
crass (1.0.6)
|
56
|
+
diff-lcs (1.3)
|
57
|
+
erubi (1.9.0)
|
58
|
+
globalid (0.4.2)
|
59
|
+
activesupport (>= 4.2.0)
|
60
|
+
i18n (1.8.2)
|
61
|
+
concurrent-ruby (~> 1.0)
|
62
|
+
loofah (2.4.0)
|
63
|
+
crass (~> 1.0.2)
|
64
|
+
nokogiri (>= 1.5.9)
|
65
|
+
mail (2.7.1)
|
66
|
+
mini_mime (>= 0.1.1)
|
67
|
+
marcel (0.3.3)
|
68
|
+
mimemagic (~> 0.3.2)
|
69
|
+
method_source (0.9.2)
|
70
|
+
mimemagic (0.3.4)
|
71
|
+
mini_mime (1.0.2)
|
72
|
+
mini_portile2 (2.4.0)
|
73
|
+
minitest (5.14.0)
|
74
|
+
nio4r (2.5.2)
|
75
|
+
nokogiri (1.10.9)
|
76
|
+
mini_portile2 (~> 2.4.0)
|
77
|
+
rack (2.2.2)
|
78
|
+
rack-test (1.1.0)
|
79
|
+
rack (>= 1.0, < 3)
|
80
|
+
rails (5.2.3)
|
81
|
+
actioncable (= 5.2.3)
|
82
|
+
actionmailer (= 5.2.3)
|
83
|
+
actionpack (= 5.2.3)
|
84
|
+
actionview (= 5.2.3)
|
85
|
+
activejob (= 5.2.3)
|
86
|
+
activemodel (= 5.2.3)
|
87
|
+
activerecord (= 5.2.3)
|
88
|
+
activestorage (= 5.2.3)
|
89
|
+
activesupport (= 5.2.3)
|
90
|
+
bundler (>= 1.3.0)
|
91
|
+
railties (= 5.2.3)
|
92
|
+
sprockets-rails (>= 2.0.0)
|
93
|
+
rails-dom-testing (2.0.3)
|
94
|
+
activesupport (>= 4.2.0)
|
95
|
+
nokogiri (>= 1.6)
|
96
|
+
rails-html-sanitizer (1.3.0)
|
97
|
+
loofah (~> 2.3)
|
98
|
+
railties (5.2.3)
|
99
|
+
actionpack (= 5.2.3)
|
100
|
+
activesupport (= 5.2.3)
|
101
|
+
method_source
|
102
|
+
rake (>= 0.8.7)
|
103
|
+
thor (>= 0.19.0, < 2.0)
|
104
|
+
rake (10.5.0)
|
105
|
+
rspec (3.9.0)
|
106
|
+
rspec-core (~> 3.9.0)
|
107
|
+
rspec-expectations (~> 3.9.0)
|
108
|
+
rspec-mocks (~> 3.9.0)
|
109
|
+
rspec-core (3.9.1)
|
110
|
+
rspec-support (~> 3.9.1)
|
111
|
+
rspec-expectations (3.9.0)
|
112
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
113
|
+
rspec-support (~> 3.9.0)
|
114
|
+
rspec-mocks (3.9.1)
|
115
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
116
|
+
rspec-support (~> 3.9.0)
|
117
|
+
rspec-support (3.9.2)
|
118
|
+
ruby-ole (1.2.12.2)
|
119
|
+
spreadsheet (1.2.6)
|
120
|
+
ruby-ole (>= 1.0)
|
121
|
+
sprockets (4.0.0)
|
122
|
+
concurrent-ruby (~> 1.0)
|
123
|
+
rack (> 1, < 3)
|
124
|
+
sprockets-rails (3.2.1)
|
125
|
+
actionpack (>= 4.0)
|
126
|
+
activesupport (>= 4.0)
|
127
|
+
sprockets (>= 3.0.0)
|
128
|
+
thor (1.0.1)
|
129
|
+
thread_safe (0.3.6)
|
130
|
+
tzinfo (1.2.6)
|
131
|
+
thread_safe (~> 0.1)
|
132
|
+
websocket-driver (0.7.1)
|
133
|
+
websocket-extensions (>= 0.1.0)
|
134
|
+
websocket-extensions (0.1.4)
|
135
|
+
|
136
|
+
PLATFORMS
|
137
|
+
ruby
|
138
|
+
|
139
|
+
DEPENDENCIES
|
140
|
+
bundler (~> 1.17)
|
141
|
+
columnify!
|
142
|
+
rake (~> 10.0)
|
143
|
+
rspec (~> 3.0)
|
144
|
+
|
145
|
+
BUNDLED WITH
|
146
|
+
1.17.2
|
data/README.md
CHANGED
@@ -7,6 +7,7 @@ The `columnify` gem helps you easily render Excel files through your controller
|
|
7
7
|
- [Columnify](#columnify)
|
8
8
|
- [Table of contents](#table-of-contents)
|
9
9
|
- [Installing Columnify](#installing-columnify)
|
10
|
+
- [Usage](#usage)
|
10
11
|
- [Contributing](#contributing)
|
11
12
|
- [License](#license)
|
12
13
|
- [Code of Conduct](#code-of-conduct)
|
@@ -39,6 +40,17 @@ $ rails g columnify:install
|
|
39
40
|
|
40
41
|
This will just register the `xls` mime type inside the `config/initializers/mime_types.rb` file.
|
41
42
|
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
The gem will add a renderer and a template handler for you to easily handle the creation of the Excel file:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
# app/views/posts/index.xls.columnify
|
49
|
+
spreadsheet.worksheet @posts, :id, :title, :content
|
50
|
+
```
|
51
|
+
|
52
|
+
So the usage for the views is just to call the `workbook` method, send the array or active record collection, followed by the set of attributes or methods you want to appear on the `xls` file.
|
53
|
+
|
42
54
|
## Contributing
|
43
55
|
|
44
56
|
Bug reports and pull requests are welcome on GitHub at https://github.com/kurenn/columnify. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/columnify.gemspec
CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
26
|
spec.add_dependency "spreadsheet"
|
27
|
+
spec.add_dependency 'rails', '>= 5.0', '<= 6.0'
|
27
28
|
|
28
29
|
spec.add_development_dependency "bundler", "~> 1.17"
|
29
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
data/lib/columnify.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'action_dispatch/http/mime_type'
|
4
|
+
require 'spreadsheet'
|
5
|
+
require 'columnify/worksheet'
|
5
6
|
|
6
7
|
class ColumnifyTemplate
|
7
8
|
class << self
|
@@ -15,31 +16,9 @@ class ColumnifyTemplate
|
|
15
16
|
super(*args)
|
16
17
|
end
|
17
18
|
|
18
|
-
def workbook
|
19
|
-
@workbook ||= Spreadsheet::Workbook.new
|
20
|
-
end
|
21
|
-
|
22
19
|
def worksheet(resources, *args)
|
23
|
-
|
24
|
-
|
25
|
-
sheet.row(0).concat args.map(&:to_s).map(&:humanize)
|
26
|
-
|
27
|
-
resources.each_with_index do |resource, index|
|
28
|
-
args.each do |method_name|
|
29
|
-
sheet.row(index + 1).push(resource.send(method_name))
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
buffer = StringIO.new
|
34
|
-
workbook.write(buffer)
|
35
|
-
buffer.rewind
|
36
|
-
buffer.read
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
|
-
def worksheet_name
|
42
|
-
DateTime.now.to_i
|
20
|
+
worksheet = Columnify::Worksheet.new(resources, *args)
|
21
|
+
worksheet.create
|
43
22
|
end
|
44
23
|
end
|
45
24
|
|
data/lib/columnify/railtie.rb
CHANGED
data/lib/columnify/version.rb
CHANGED
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Columnify
|
4
|
+
class Worksheet
|
5
|
+
def initialize(resources, *args)
|
6
|
+
@options = args.extract_options!
|
7
|
+
@column_names = @options[:column_names].presence || args
|
8
|
+
@attributes = args
|
9
|
+
@resources = resources
|
10
|
+
@buffer = StringIO.new
|
11
|
+
@workbook = Spreadsheet::Workbook.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
inject_column_names
|
16
|
+
inject_data
|
17
|
+
write_workbook_buffer
|
18
|
+
read
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def read
|
24
|
+
@buffer.rewind
|
25
|
+
@buffer.read
|
26
|
+
end
|
27
|
+
|
28
|
+
def write_workbook_buffer
|
29
|
+
@workbook.write(@buffer)
|
30
|
+
end
|
31
|
+
|
32
|
+
def inject_column_names
|
33
|
+
sheet.row(0).concat humanized_columns
|
34
|
+
end
|
35
|
+
|
36
|
+
def inject_data
|
37
|
+
@resources.each_with_index do |resource, index|
|
38
|
+
sheet.column(index).default_format = cell_format
|
39
|
+
@attributes.each do |method_name|
|
40
|
+
sheet.row(index + 1).default_format = cell_format
|
41
|
+
sheet.row(index + 1).push(resource.send(method_name))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def cell_format
|
47
|
+
@cell_format ||= Spreadsheet::Format.new text_wrap: true
|
48
|
+
end
|
49
|
+
|
50
|
+
def humanized_columns
|
51
|
+
@humanized_columns ||= @column_names.map(&:to_s).map(&:humanize)
|
52
|
+
end
|
53
|
+
|
54
|
+
def sheet
|
55
|
+
@sheet ||= @workbook.create_worksheet(name: worksheet_name)
|
56
|
+
end
|
57
|
+
|
58
|
+
def worksheet_name
|
59
|
+
Time.now.to_i.to_s
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: columnify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abraham Kuri
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spreadsheet
|
@@ -24,6 +24,26 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
- - "<="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '6.0'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '5.0'
|
44
|
+
- - "<="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '6.0'
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: bundler
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,6 +98,7 @@ files:
|
|
78
98
|
- ".travis.yml"
|
79
99
|
- CODE_OF_CONDUCT.md
|
80
100
|
- Gemfile
|
101
|
+
- Gemfile.lock
|
81
102
|
- LICENSE.txt
|
82
103
|
- README.md
|
83
104
|
- Rakefile
|
@@ -89,6 +110,7 @@ files:
|
|
89
110
|
- lib/columnify/columnify_template.rb
|
90
111
|
- lib/columnify/railtie.rb
|
91
112
|
- lib/columnify/version.rb
|
113
|
+
- lib/columnify/worksheet.rb
|
92
114
|
- lib/generators/columnify/install_generator.rb
|
93
115
|
homepage: https://github.com/kurenn/columnify
|
94
116
|
licenses:
|
@@ -109,8 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
131
|
- !ruby/object:Gem::Version
|
110
132
|
version: '0'
|
111
133
|
requirements: []
|
112
|
-
|
113
|
-
rubygems_version: 2.7.6
|
134
|
+
rubygems_version: 3.0.3
|
114
135
|
signing_key:
|
115
136
|
specification_version: 4
|
116
137
|
summary: A simple Excel & CSV Rails Responder
|