activeadmin-xls 1.0.5 → 1.1.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/CHANGELOG.md +23 -4
- data/README.md +25 -21
- data/Rakefile +2 -1
- data/gemfiles/rails_42.gemfile +1 -1
- data/lib/active_admin/xls/builder.rb +10 -1
- data/lib/active_admin/xls/dsl.rb +1 -0
- data/lib/active_admin/xls/engine.rb +4 -1
- data/lib/active_admin/xls/version.rb +1 -1
- data/spec/support/rails_template.rb +28 -14
- data/spec/support/rails_template_with_data.rb +17 -11
- data/spec/xls/unit/builder_spec.rb +25 -5
- data/spec/xls/unit/dsl_spec.rb +2 -0
- data/spec/xls/unit/resource_controller_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a30a7f1fc93455cecb1aac5d28026454061ebdcd
|
4
|
+
data.tar.gz: a1342476206f3a3b7ba04c15df545d620af315eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acd27c54cbf49c5148d94625f4872b89291513fbea277ff8fb0e96231a40ce8172fb9cae4d91ad4e1adeda135ce45feb704a5396a2c66252a49f97abf3ab9de8
|
7
|
+
data.tar.gz: 9baa56bf539d13050c67b6a9e911323a0d5bd04bd43b6182eb32f0de4e6c125aaca61b32adafa86addd387072d751db5497f1b3273320abbd2aa044912b19f0e
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,33 +1,52 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [Unreleased]
|
4
|
+
|
5
|
+
## 1.1.0
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
* Add only_columns [#7][]
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
|
13
|
+
* Fix typo in README.md [#11][] by [@cpunion][]
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
17
|
+
* Update tests for ActiveAdmin 1.2
|
18
|
+
|
3
19
|
## 1.0.5
|
4
20
|
|
5
|
-
###
|
21
|
+
### Fixed
|
6
22
|
|
7
23
|
* Fix #1 - Unnecessary database access
|
8
24
|
* Fix broken tests
|
9
25
|
|
10
26
|
## 1.0.4
|
11
27
|
|
12
|
-
###
|
28
|
+
### Fixed
|
13
29
|
|
14
30
|
* Minor bug fixes / typo corrections
|
15
31
|
|
16
32
|
## 1.0.3
|
17
33
|
|
18
|
-
###
|
34
|
+
### Fixed
|
19
35
|
|
20
36
|
* Move require rake from gemspec to lib/activeadmin-xls.rb [#4][] by [@ejaypcanaria][]
|
21
37
|
|
22
38
|
## 1.0.2
|
23
39
|
|
24
|
-
###
|
40
|
+
### Fixed
|
25
41
|
|
26
42
|
* Fixes undefined local variable or `method max_per_page` [#3][] by [@rewritten][]
|
27
43
|
|
28
44
|
<!--- Link List --->
|
29
45
|
[#3]: https://github.com/thambley/activeadmin-xls/issues/3
|
30
46
|
[#4]: https://github.com/thambley/activeadmin-xls/pull/4
|
47
|
+
[#7]: https://github.com/thambley/activeadmin-xls/issues/7
|
48
|
+
[#11]: https://github.com/thambley/activeadmin-xls/pull/11
|
31
49
|
|
32
50
|
[@rewritten]: https://github.com/rewritten
|
33
51
|
[@ejaypcanaria]: https://github.com/ejaypcanaria
|
52
|
+
[@cpunion]: https://github.com/cpunion
|
data/README.md
CHANGED
@@ -1,16 +1,8 @@
|
|
1
|
-
# Active Admin Xls
|
1
|
+
# Active Admin Xls
|
2
2
|
|
3
|
-
|
3
|
+
Excel Spreadsheet Export for [Active Admin](https://www.activeadmin.info/)
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
**Copyright**: 2014 ~ 2017
|
8
|
-
|
9
|
-
**License**: MIT License
|
10
|
-
|
11
|
-
**Latest Version**: 1.0.4
|
12
|
-
|
13
|
-
**Release Date**: 2017.11.22
|
5
|
+
[](https://badge.fury.io/rb/activeadmin-xls)
|
14
6
|
|
15
7
|
## Synopsis
|
16
8
|
|
@@ -25,10 +17,16 @@ All resource index views will now include a link for download directly
|
|
25
17
|
to xls.
|
26
18
|
|
27
19
|
```ruby
|
28
|
-
gem 'activeadmin-xls'
|
20
|
+
gem 'activeadmin-xls', '~>1.1.0'
|
21
|
+
```
|
22
|
+
|
23
|
+
For Active Admin 1.0, you will also have to update config/initializers/active_admin.rb. Update the download\_links setting to include xls:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
config.download_links = %i[csv xml json xls]
|
29
27
|
```
|
30
28
|
|
31
|
-
##
|
29
|
+
## Examples
|
32
30
|
|
33
31
|
Here are a few quick examples of things you can easily tweak.
|
34
32
|
|
@@ -71,6 +69,15 @@ ActiveAdmin.register Post do
|
|
71
69
|
end
|
72
70
|
```
|
73
71
|
|
72
|
+
### Restrict columns to a list
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
# app/admin/posts.rb
|
76
|
+
ActiveAdmin.register Post do
|
77
|
+
config.xls_builder.only_columns :title, :author
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
74
81
|
## Using the DSL
|
75
82
|
|
76
83
|
Everything that you do with the config's default builder can be done via
|
@@ -91,10 +98,13 @@ ActiveAdmin.register Post do
|
|
91
98
|
# Do not serialize the header, only output data.
|
92
99
|
# skip_header
|
93
100
|
|
101
|
+
# restrict columns to a list without customization
|
102
|
+
# only_columns :title, :author
|
103
|
+
|
94
104
|
# deleting columns from the report
|
95
105
|
delete_columns :id, :created_at, :updated_at
|
96
106
|
|
97
|
-
# adding a column to the report
|
107
|
+
# adding a column to the report with customization
|
98
108
|
column(:author) { |post| "#{post.author.first_name} #{post.author.last_name}" }
|
99
109
|
|
100
110
|
# inserting additional data with after_filter
|
@@ -110,7 +120,7 @@ ActiveAdmin.register Post do
|
|
110
120
|
end
|
111
121
|
```
|
112
122
|
|
113
|
-
##
|
123
|
+
## Testing
|
114
124
|
|
115
125
|
Running specs for this gem requires that you construct a rails application.
|
116
126
|
|
@@ -143,9 +153,3 @@ BUNDLE_GEMFILE=gemfiles/rails_42.gemfile bundle exec rake setup
|
|
143
153
|
```text
|
144
154
|
BUNDLE_GEMFILE=gemfiles/rails_42.gemfile bundle exec rake
|
145
155
|
```
|
146
|
-
|
147
|
-
## Copyright and License
|
148
|
-
|
149
|
-
activeadmin-xls © 2014 by [Todd Hambley](mailto:thambley@travelleaders.com).
|
150
|
-
|
151
|
-
activeadmin-xls is licensed under the MIT license. Please see the LICENSE document for more information.
|
data/Rakefile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
+
require File.expand_path('../lib/active_admin/xls/version', __FILE__)
|
2
3
|
require 'rspec/core/rake_task'
|
3
4
|
|
4
5
|
desc 'Creates a test rails app for the specs to run against'
|
5
6
|
task :setup do
|
6
7
|
require 'rails/version'
|
7
8
|
system('mkdir spec/rails') unless File.exist?('spec/rails')
|
8
|
-
puts "system \"bundle exec rails new spec/rails/rails-#{Rails::VERSION::STRING} -m spec/support/rails_template_with_data.rb\""
|
9
9
|
system "bundle exec rails new spec/rails/rails-#{Rails::VERSION::STRING} -m spec/support/rails_template_with_data.rb"
|
10
10
|
end
|
11
11
|
|
@@ -17,6 +17,7 @@ desc 'build the gem'
|
|
17
17
|
task :build do
|
18
18
|
system 'gem build activeadmin-xls.gemspec'
|
19
19
|
end
|
20
|
+
|
20
21
|
desc 'build and release the gem'
|
21
22
|
task release: :build do
|
22
23
|
system "gem push activeadmin-xls-#{ActiveAdmin::Xls::VERSION}.gem"
|
data/gemfiles/rails_42.gemfile
CHANGED
@@ -6,7 +6,7 @@ ruby_minor_version = RUBY_VERSION.split('.')[1].to_i
|
|
6
6
|
|
7
7
|
eval_gemfile(File.expand_path(File.join('..', 'Gemfile'), __dir__))
|
8
8
|
|
9
|
-
gem 'activeadmin', '1.
|
9
|
+
gem 'activeadmin', '1.2.1'
|
10
10
|
gem 'devise', '~> 4.2'
|
11
11
|
gem 'rails', '4.2.10'
|
12
12
|
gem 'turbolinks', '~> 5.0.0'
|
@@ -26,7 +26,7 @@ module ActiveAdmin
|
|
26
26
|
#
|
27
27
|
# }
|
28
28
|
# end
|
29
|
-
# @see ActiveAdmin::
|
29
|
+
# @see ActiveAdmin::xls::DSL
|
30
30
|
def initialize(resource_class, options = {}, &block)
|
31
31
|
@skip_header = false
|
32
32
|
@resource_class = resource_class
|
@@ -138,6 +138,15 @@ module ActiveAdmin
|
|
138
138
|
end
|
139
139
|
end
|
140
140
|
|
141
|
+
# remove all columns, and add columns by name
|
142
|
+
# each column_name should be a symbol
|
143
|
+
def only_columns(*column_names)
|
144
|
+
clear_columns
|
145
|
+
column_names.each do |column_name|
|
146
|
+
column column_name
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
141
150
|
# Serializes the collection provided
|
142
151
|
# @return [Spreadsheet::Workbook]
|
143
152
|
def serialize(collection, view_context = nil)
|
data/lib/active_admin/xls/dsl.rb
CHANGED
@@ -13,7 +13,10 @@ module ActiveAdmin
|
|
13
13
|
|
14
14
|
ActiveAdmin::ResourceDSL.send :include, ActiveAdmin::Xls::DSL
|
15
15
|
ActiveAdmin::Resource.send :include, ActiveAdmin::Xls::ResourceExtension
|
16
|
-
ActiveAdmin::ResourceController.send
|
16
|
+
ActiveAdmin::ResourceController.send(
|
17
|
+
:include,
|
18
|
+
ActiveAdmin::Xls::ResourceControllerExtension
|
19
|
+
)
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
@@ -10,9 +10,11 @@ gsub_file 'config/database.yml', /^test:.*\n/, "test: &test\n"
|
|
10
10
|
gsub_file 'config/database.yml',
|
11
11
|
/\z/,
|
12
12
|
"\ncucumber:\n <<: *test\n database: db/cucumber.sqlite3"
|
13
|
-
gsub_file
|
14
|
-
|
15
|
-
|
13
|
+
gsub_file(
|
14
|
+
'config/database.yml',
|
15
|
+
/\z/,
|
16
|
+
"\ncucumber_with_reloading:\n <<: *test\n database: db/cucumber.sqlite3"
|
17
|
+
)
|
16
18
|
|
17
19
|
# Generate some test models
|
18
20
|
generate :model, 'post title:string body:text published_at:datetime author_id:integer category_id:integer'
|
@@ -20,26 +22,36 @@ inject_into_file 'app/models/post.rb', " belongs_to :author, class_name: 'User'
|
|
20
22
|
# Rails 3.2.3 model generator declare attr_accessible
|
21
23
|
if Rails::VERSION::MAJOR == 3
|
22
24
|
inject_into_file 'app/models/post.rb',
|
23
|
-
|
24
|
-
|
25
|
+
" attr_accessible :author\n",
|
26
|
+
before: 'end'
|
25
27
|
end
|
26
28
|
generate :model, 'user type:string first_name:string last_name:string username:string age:integer'
|
27
|
-
inject_into_file 'app/models/user.rb',
|
29
|
+
inject_into_file 'app/models/user.rb',
|
30
|
+
" has_many :posts, foreign_key: 'author_id'\n",
|
31
|
+
after: "class User < ActiveRecord::Base\n"
|
28
32
|
generate :model, 'publisher --migration=false --parent=User'
|
29
33
|
generate :model, 'category name:string description:text'
|
30
|
-
inject_into_file 'app/models/category.rb',
|
34
|
+
inject_into_file 'app/models/category.rb',
|
35
|
+
" has_many :posts\n accepts_nested_attributes_for :posts\n",
|
36
|
+
after: "class Category < ActiveRecord::Base\n"
|
31
37
|
generate :model, 'store name:string'
|
32
38
|
|
33
39
|
# Generate a model with string ids
|
34
40
|
generate :model, 'tag name:string'
|
35
|
-
gsub_file(
|
41
|
+
gsub_file(
|
42
|
+
Dir['db/migrate/*_create_tags.rb'][0],
|
43
|
+
/\:tags\sdo\s.*/,
|
44
|
+
":tags, id: false, primary_key: :id do |t|\n\t\t\tt.string :id\n"
|
45
|
+
)
|
36
46
|
id_model_setup = <<-MODEL
|
37
47
|
self.primary_key = :id
|
38
48
|
before_create :set_id
|
39
49
|
|
40
50
|
private
|
41
51
|
def set_id
|
42
|
-
self.id = 8.times.inject('')
|
52
|
+
self.id = 8.times.inject('') do |s,e|
|
53
|
+
s << (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr
|
54
|
+
end
|
43
55
|
end
|
44
56
|
MODEL
|
45
57
|
|
@@ -54,14 +66,16 @@ if Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR == 1 # Rails 3.1 Gotcha
|
|
54
66
|
end
|
55
67
|
|
56
68
|
# Configure default_url_options in test environment
|
57
|
-
inject_into_file
|
58
|
-
|
59
|
-
|
69
|
+
inject_into_file(
|
70
|
+
'config/environments/test.rb',
|
71
|
+
" config.action_mailer.default_url_options = { host: 'example.com' }\n",
|
72
|
+
after: "config.cache_classes = true\n"
|
73
|
+
)
|
60
74
|
|
61
|
-
|
75
|
+
lib_path = File.expand_path('../../../lib/activeadmin-xls', __FILE__)
|
62
76
|
# Add our local Active Admin to the load path
|
63
77
|
inject_into_file 'config/environment.rb',
|
64
|
-
"\nrequire
|
78
|
+
"\nrequire '#{lib_path}'\n",
|
65
79
|
after: "require File.expand_path('../application', __FILE__)"
|
66
80
|
|
67
81
|
# Add some translations
|
@@ -10,35 +10,41 @@ scopes = <<-SCOPES
|
|
10
10
|
scope :all, default: true
|
11
11
|
|
12
12
|
scope :drafts do |posts|
|
13
|
-
posts.where([
|
13
|
+
posts.where(['published_at IS NULL'])
|
14
14
|
end
|
15
15
|
|
16
16
|
scope :scheduled do |posts|
|
17
|
-
posts.where([
|
17
|
+
posts.where(['posts.published_at IS NOT NULL AND posts.published_at > ?', Time.now.utc])
|
18
18
|
end
|
19
19
|
|
20
20
|
scope :published do |posts|
|
21
|
-
posts.where([
|
21
|
+
posts.where(['posts.published_at IS NOT NULL AND posts.published_at < ?', Time.now.utc])
|
22
22
|
end
|
23
23
|
|
24
24
|
scope :my_posts do |posts|
|
25
|
-
posts.where(:
|
25
|
+
posts.where(author_id: current_admin_user.id)
|
26
26
|
end
|
27
27
|
SCOPES
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
if File.exist?('app/admin/post.rb')
|
30
|
+
inject_into_file 'app/admin/post.rb',
|
31
|
+
scopes,
|
32
|
+
after: "ActiveAdmin.register Post do\n"
|
33
|
+
else
|
34
|
+
inject_into_file 'app/admin/posts.rb',
|
35
|
+
scopes,
|
36
|
+
after: "ActiveAdmin.register Post do\n"
|
37
|
+
end
|
32
38
|
|
33
39
|
# Setup some default data
|
34
40
|
append_file 'db/seeds.rb', <<-SEEDS
|
35
41
|
|
36
42
|
users = ['Jimi Hendrix', 'Jimmy Page', 'Yngwie Malmsteen', 'Eric Clapton', 'Kirk Hammett'].collect do |name|
|
37
43
|
first, last = name.split(" ")
|
38
|
-
User.create!
|
39
|
-
|
40
|
-
|
41
|
-
|
44
|
+
User.create! first_name: first,
|
45
|
+
last_name: last,
|
46
|
+
username: [first, last].join('-').downcase,
|
47
|
+
age: rand(80)
|
42
48
|
end
|
43
49
|
|
44
50
|
categories = ['Rock', 'Pop Rock', 'Alt-Country', 'Blues', 'Dub-Step'].collect do |name|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module ActiveAdmin
|
4
|
+
# tests for builder
|
4
5
|
module Xls
|
5
6
|
describe Builder do
|
6
7
|
let(:builder) { Builder.new(Post) }
|
@@ -24,6 +25,11 @@ module ActiveAdmin
|
|
24
25
|
expect(builder.columns.size).to eq(content_columns.size - 1)
|
25
26
|
end
|
26
27
|
|
28
|
+
it 'lets us use specific columns in a list' do
|
29
|
+
builder.only_columns :title, :author
|
30
|
+
expect(builder.columns.size).to eq(2)
|
31
|
+
end
|
32
|
+
|
27
33
|
it 'lets us say we dont want the header' do
|
28
34
|
builder.skip_header
|
29
35
|
expect(builder.instance_values['skip_header']).to be_truthy
|
@@ -53,7 +59,9 @@ module ActiveAdmin
|
|
53
59
|
end
|
54
60
|
|
55
61
|
it 'evaluates custom column blocks' do
|
56
|
-
expect(builder.columns.last.data.call(post)).to eq(
|
62
|
+
expect(builder.columns.last.data.call(post)).to eq(
|
63
|
+
'Hot Dawg - with cheese'
|
64
|
+
)
|
57
65
|
end
|
58
66
|
end
|
59
67
|
end
|
@@ -61,10 +69,16 @@ module ActiveAdmin
|
|
61
69
|
context 'sheet generation without headers' do
|
62
70
|
let!(:users) { [User.new(first_name: 'bob', last_name: 'nancy')] }
|
63
71
|
|
64
|
-
let!(:posts)
|
72
|
+
let!(:posts) do
|
73
|
+
[Post.new(title: 'bob', body: 'is a swell guy', author: users.first)]
|
74
|
+
end
|
65
75
|
|
66
76
|
let!(:builder) do
|
67
|
-
|
77
|
+
options = {
|
78
|
+
header_format: { weight: :bold },
|
79
|
+
i18n_scope: %i[xls post]
|
80
|
+
}
|
81
|
+
Builder.new(Post, options) do
|
68
82
|
skip_header
|
69
83
|
end
|
70
84
|
end
|
@@ -117,7 +131,11 @@ module ActiveAdmin
|
|
117
131
|
|
118
132
|
context 'Sheet generation with a highly customized configuration.' do
|
119
133
|
let!(:builder) do
|
120
|
-
|
134
|
+
options = {
|
135
|
+
header_style: { size: 10, color: 'red' },
|
136
|
+
i18n_scope: %i[xls post]
|
137
|
+
}
|
138
|
+
Builder.new(Post, options) do
|
121
139
|
delete_columns :id, :created_at, :updated_at
|
122
140
|
column(:author) do |resource|
|
123
141
|
"#{resource.author.first_name} #{resource.author.last_name}"
|
@@ -178,7 +196,9 @@ module ActiveAdmin
|
|
178
196
|
|
179
197
|
it 'translates the header row based on our i18n scope' do
|
180
198
|
header_row = @book.worksheets.first.row(2)
|
181
|
-
expect(header_row).to eq(
|
199
|
+
expect(header_row).to eq(
|
200
|
+
['Title', 'Content', 'Published On', 'Publisher']
|
201
|
+
)
|
182
202
|
end
|
183
203
|
|
184
204
|
it 'processes the before filter' do
|
data/spec/xls/unit/dsl_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module ActiveAdmin
|
4
|
+
# tests for dsl
|
4
5
|
module Xls
|
5
6
|
describe ::ActiveAdmin::ResourceDSL do
|
6
7
|
context 'in a registration block' do
|
@@ -42,6 +43,7 @@ module ActiveAdmin
|
|
42
43
|
it 'has a before filter set' do
|
43
44
|
expect(builder.instance_values['before_filter']).to be_a(Proc)
|
44
45
|
end
|
46
|
+
|
45
47
|
it 'has an after filter set' do
|
46
48
|
expect(builder.instance_values['after_filter']).to be_a(Proc)
|
47
49
|
end
|
@@ -43,7 +43,7 @@ describe ActiveAdmin::ResourceController do
|
|
43
43
|
expect(controller.send(:per_page)).to eq(max_csv_records)
|
44
44
|
end
|
45
45
|
|
46
|
-
it 'uses
|
46
|
+
it 'uses the default per_page when we do not specify xls mime type' do
|
47
47
|
controller.request.accept = 'text/html'
|
48
48
|
aa_default_per_page = ActiveAdmin.application.default_per_page
|
49
49
|
expect(controller.send(:per_page)).to eq(aa_default_per_page)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin-xls
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Hambley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeadmin
|