administrate_exportable 0.6.2 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0eeab3dbc1629f67561d23a235d685fdb9587ad09c3e4d64cc967b3e932d94a
4
- data.tar.gz: e428424abb066e9d1b074d6d87ca9826d0bbf02f2dd6c01017489354f0483900
3
+ metadata.gz: 66d0a1d7b10a17a14ff7c4553f751d34c756b1f1138614c15f1144b807e9161f
4
+ data.tar.gz: e7669105bcb5d34ddfb92520a57f07eb9c28871510cc7aa28a7bbd21189818b3
5
5
  SHA512:
6
- metadata.gz: 9334efb3cffad20ee050853d3eae9e512642f7674ba446ffa5a9eaf0942c6412328149eb06dffcccfa7ab7bf9806e07c0275c03521fb245f671d9ff56e6f791e
7
- data.tar.gz: 54c004002db29996a158043fcdb1eb38d703c200e27e4fafe39e3cdf729d57e622739bcdbf92ba10567eb6e26b9efe89e9f1c1be37818e51b24f50303f6c3b77
6
+ metadata.gz: afd7af1c25b548fac0bea63635190d6ac3a98cc30622390db4f02535ea33b7b3494a4bf71d672845466ba6caa5bbbe92e21e2bc2e79a98d96a5ec83bfe745840
7
+ data.tar.gz: 82b748cbd381e7890a2ce35a6f05029a4cab127c676f2c344237398734a59b499472ef863c417d3a7d835840ed3592f2a1ae1200dcfc604a9117727690a4ba2a
@@ -0,0 +1,44 @@
1
+ name: Tests
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - "*"
7
+ push:
8
+ branches:
9
+ - main
10
+ jobs:
11
+ tests:
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ matrix:
15
+ ruby: ["3.1", "3.2", "3.3", "3.4"]
16
+
17
+ steps:
18
+ - uses: actions/checkout@master
19
+
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ bundler: default
25
+ bundler-cache: true
26
+
27
+ - name: StandardRb check
28
+ run: bundle exec standardrb --format progress --format github --color
29
+
30
+ - name: Run tests
31
+ run: |
32
+ bundle exec rspec
33
+ docs:
34
+ runs-on: ubuntu-latest
35
+ steps:
36
+ - uses: actions/checkout@master
37
+ - name: Set up Ruby
38
+ uses: ruby/setup-ruby@v1
39
+ with:
40
+ ruby-version: 3.3
41
+ bundler: default
42
+ bundler-cache: true
43
+ - name: Build docs
44
+ run: bundle exec rake yard
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 2.7.2
1
+ ruby 3.1.6
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  eval_gemfile File.join(File.dirname(__FILE__), "spec/dummy/Gemfile")
data/Gemfile.lock CHANGED
@@ -1,91 +1,137 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- administrate_exportable (0.6.2)
4
+ administrate_exportable (0.7.0)
5
5
  actionview (>= 5.2.2.1)
6
6
  administrate (>= 0.17.0)
7
+ csv (~> 3.0)
7
8
  rails (>= 4.2)
8
9
  railties (>= 5.2.2.1)
9
10
 
10
11
  GEM
11
12
  remote: https://rubygems.org/
12
13
  specs:
13
- actioncable (5.2.8)
14
- actionpack (= 5.2.8)
14
+ actioncable (7.1.6)
15
+ actionpack (= 7.1.6)
16
+ activesupport (= 7.1.6)
15
17
  nio4r (~> 2.0)
16
18
  websocket-driver (>= 0.6.1)
17
- actionmailer (5.2.8)
18
- actionpack (= 5.2.8)
19
- actionview (= 5.2.8)
20
- activejob (= 5.2.8)
19
+ zeitwerk (~> 2.6)
20
+ actionmailbox (7.1.6)
21
+ actionpack (= 7.1.6)
22
+ activejob (= 7.1.6)
23
+ activerecord (= 7.1.6)
24
+ activestorage (= 7.1.6)
25
+ activesupport (= 7.1.6)
26
+ mail (>= 2.7.1)
27
+ net-imap
28
+ net-pop
29
+ net-smtp
30
+ actionmailer (7.1.6)
31
+ actionpack (= 7.1.6)
32
+ actionview (= 7.1.6)
33
+ activejob (= 7.1.6)
34
+ activesupport (= 7.1.6)
21
35
  mail (~> 2.5, >= 2.5.4)
22
- rails-dom-testing (~> 2.0)
23
- actionpack (5.2.8)
24
- actionview (= 5.2.8)
25
- activesupport (= 5.2.8)
26
- rack (~> 2.0, >= 2.0.8)
36
+ net-imap
37
+ net-pop
38
+ net-smtp
39
+ rails-dom-testing (~> 2.2)
40
+ actionpack (7.1.6)
41
+ actionview (= 7.1.6)
42
+ activesupport (= 7.1.6)
43
+ cgi
44
+ nokogiri (>= 1.8.5)
45
+ racc
46
+ rack (>= 2.2.4)
47
+ rack-session (>= 1.0.1)
27
48
  rack-test (>= 0.6.3)
28
- rails-dom-testing (~> 2.0)
29
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
30
- actionview (5.2.8)
31
- activesupport (= 5.2.8)
49
+ rails-dom-testing (~> 2.2)
50
+ rails-html-sanitizer (~> 1.6)
51
+ actiontext (7.1.6)
52
+ actionpack (= 7.1.6)
53
+ activerecord (= 7.1.6)
54
+ activestorage (= 7.1.6)
55
+ activesupport (= 7.1.6)
56
+ globalid (>= 0.6.0)
57
+ nokogiri (>= 1.8.5)
58
+ actionview (7.1.6)
59
+ activesupport (= 7.1.6)
32
60
  builder (~> 3.1)
33
- erubi (~> 1.4)
34
- rails-dom-testing (~> 2.0)
35
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
36
- activejob (5.2.8)
37
- activesupport (= 5.2.8)
61
+ cgi
62
+ erubi (~> 1.11)
63
+ rails-dom-testing (~> 2.2)
64
+ rails-html-sanitizer (~> 1.6)
65
+ activejob (7.1.6)
66
+ activesupport (= 7.1.6)
38
67
  globalid (>= 0.3.6)
39
- activemodel (5.2.8)
40
- activesupport (= 5.2.8)
41
- activerecord (5.2.8)
42
- activemodel (= 5.2.8)
43
- activesupport (= 5.2.8)
44
- arel (>= 9.0)
45
- activestorage (5.2.8)
46
- actionpack (= 5.2.8)
47
- activerecord (= 5.2.8)
48
- marcel (~> 1.0.0)
49
- activesupport (5.2.8)
68
+ activemodel (7.1.6)
69
+ activesupport (= 7.1.6)
70
+ activerecord (7.1.6)
71
+ activemodel (= 7.1.6)
72
+ activesupport (= 7.1.6)
73
+ timeout (>= 0.4.0)
74
+ activestorage (7.1.6)
75
+ actionpack (= 7.1.6)
76
+ activejob (= 7.1.6)
77
+ activerecord (= 7.1.6)
78
+ activesupport (= 7.1.6)
79
+ marcel (~> 1.0)
80
+ activesupport (7.1.6)
81
+ base64
82
+ benchmark (>= 0.3)
83
+ bigdecimal
50
84
  concurrent-ruby (~> 1.0, >= 1.0.2)
51
- i18n (>= 0.7, < 2)
52
- minitest (~> 5.1)
53
- tzinfo (~> 1.1)
54
- administrate (0.17.0)
85
+ connection_pool (>= 2.2.5)
86
+ drb
87
+ i18n (>= 1.6, < 2)
88
+ logger (>= 1.4.2)
89
+ minitest (>= 5.1)
90
+ mutex_m
91
+ securerandom (>= 0.3)
92
+ tzinfo (~> 2.0)
93
+ administrate (0.19.0)
55
94
  actionpack (>= 5.0)
56
95
  actionview (>= 5.0)
57
96
  activerecord (>= 5.0)
58
- datetime_picker_rails (~> 0.0.7)
59
97
  jquery-rails (>= 4.0)
60
98
  kaminari (>= 1.0)
61
- momentjs-rails (~> 2.8)
62
99
  sassc-rails (~> 2.1)
63
100
  selectize-rails (~> 0.6)
64
- administrate-field-enumerate (0.0.2)
65
- administrate
66
- enumerate_it
67
- rails (>= 4.2, < 7.0)
68
- arel (9.0.0)
69
- builder (3.2.4)
70
- byebug (11.1.3)
101
+ ast (2.4.3)
102
+ base64 (0.3.0)
103
+ benchmark (0.5.0)
104
+ bigdecimal (4.0.1)
105
+ builder (3.3.0)
106
+ byebug (12.0.0)
107
+ cgi (0.5.1)
71
108
  coderay (1.1.3)
72
- concurrent-ruby (1.1.10)
109
+ concurrent-ruby (1.3.6)
110
+ connection_pool (2.5.5)
73
111
  crass (1.0.6)
74
- datetime_picker_rails (0.0.7)
75
- momentjs-rails (>= 2.8.1)
76
- diff-lcs (1.5.0)
77
- enumerate_it (3.2.2)
78
- activesupport (>= 5.0.7.2)
79
- erubi (1.10.0)
80
- ffi (1.15.5)
81
- globalid (1.0.0)
82
- activesupport (>= 5.0)
83
- i18n (1.10.0)
112
+ csv (3.3.5)
113
+ date (3.5.1)
114
+ diff-lcs (1.6.2)
115
+ drb (2.2.3)
116
+ erb (4.0.4)
117
+ cgi (>= 0.3.3)
118
+ erubi (1.13.1)
119
+ ffi (1.17.3)
120
+ ffi (1.17.3-arm64-darwin)
121
+ globalid (1.3.0)
122
+ activesupport (>= 6.1)
123
+ i18n (1.14.8)
84
124
  concurrent-ruby (~> 1.0)
85
- jquery-rails (4.4.0)
125
+ io-console (0.8.2)
126
+ irb (1.16.0)
127
+ pp (>= 0.6.0)
128
+ rdoc (>= 4.0.0)
129
+ reline (>= 0.4.2)
130
+ jquery-rails (4.6.1)
86
131
  rails-dom-testing (>= 1, < 3)
87
132
  railties (>= 4.2.0)
88
133
  thor (>= 0.14, < 2.0)
134
+ json (2.18.1)
89
135
  kaminari (1.2.2)
90
136
  activesupport (>= 4.1.0)
91
137
  kaminari-actionview (= 1.2.2)
@@ -98,75 +144,142 @@ GEM
98
144
  activerecord
99
145
  kaminari-core (= 1.2.2)
100
146
  kaminari-core (1.2.2)
101
- loofah (2.18.0)
147
+ language_server-protocol (3.17.0.5)
148
+ lint_roller (1.1.0)
149
+ logger (1.7.0)
150
+ loofah (2.25.0)
102
151
  crass (~> 1.0.2)
103
- nokogiri (>= 1.5.9)
104
- mail (2.7.1)
152
+ nokogiri (>= 1.12.0)
153
+ mail (2.9.0)
154
+ logger
105
155
  mini_mime (>= 0.1.1)
106
- marcel (1.0.2)
107
- method_source (1.0.0)
108
- mini_mime (1.1.2)
109
- mini_portile2 (2.8.0)
110
- minitest (5.15.0)
111
- momentjs-rails (2.29.1.1)
112
- railties (>= 3.1)
113
- nio4r (2.5.8)
114
- nokogiri (1.13.6)
115
- mini_portile2 (~> 2.8.0)
156
+ net-imap
157
+ net-pop
158
+ net-smtp
159
+ marcel (1.1.0)
160
+ method_source (1.1.0)
161
+ mini_mime (1.1.5)
162
+ mini_portile2 (2.8.9)
163
+ minitest (5.27.0)
164
+ mutex_m (0.3.0)
165
+ net-imap (0.5.13)
166
+ date
167
+ net-protocol
168
+ net-pop (0.1.2)
169
+ net-protocol
170
+ net-protocol (0.2.2)
171
+ timeout
172
+ net-smtp (0.5.1)
173
+ net-protocol
174
+ nio4r (2.7.5)
175
+ nokogiri (1.18.10)
176
+ mini_portile2 (~> 2.8.2)
177
+ racc (~> 1.4)
178
+ nokogiri (1.18.10-arm64-darwin)
116
179
  racc (~> 1.4)
117
- pry (0.13.1)
180
+ parallel (1.27.0)
181
+ parser (3.3.10.1)
182
+ ast (~> 2.4.1)
183
+ racc
184
+ pp (0.6.3)
185
+ prettyprint
186
+ prettyprint (0.2.0)
187
+ prism (1.9.0)
188
+ pry (0.15.2)
118
189
  coderay (~> 1.1)
119
190
  method_source (~> 1.0)
120
- pry-byebug (3.9.0)
121
- byebug (~> 11.0)
122
- pry (~> 0.13.0)
123
- racc (1.6.0)
124
- rack (2.2.3)
125
- rack-test (1.1.0)
126
- rack (>= 1.0, < 3)
127
- rails (5.2.8)
128
- actioncable (= 5.2.8)
129
- actionmailer (= 5.2.8)
130
- actionpack (= 5.2.8)
131
- actionview (= 5.2.8)
132
- activejob (= 5.2.8)
133
- activemodel (= 5.2.8)
134
- activerecord (= 5.2.8)
135
- activestorage (= 5.2.8)
136
- activesupport (= 5.2.8)
137
- bundler (>= 1.3.0)
138
- railties (= 5.2.8)
139
- sprockets-rails (>= 2.0.0)
140
- rails-dom-testing (2.0.3)
141
- activesupport (>= 4.2.0)
191
+ pry-byebug (3.11.0)
192
+ byebug (~> 12.0)
193
+ pry (>= 0.13, < 0.16)
194
+ psych (5.3.1)
195
+ date
196
+ stringio
197
+ racc (1.8.1)
198
+ rack (3.2.4)
199
+ rack-session (2.1.1)
200
+ base64 (>= 0.1.0)
201
+ rack (>= 3.0.0)
202
+ rack-test (2.2.0)
203
+ rack (>= 1.3)
204
+ rackup (2.3.1)
205
+ rack (>= 3)
206
+ rails (7.1.6)
207
+ actioncable (= 7.1.6)
208
+ actionmailbox (= 7.1.6)
209
+ actionmailer (= 7.1.6)
210
+ actionpack (= 7.1.6)
211
+ actiontext (= 7.1.6)
212
+ actionview (= 7.1.6)
213
+ activejob (= 7.1.6)
214
+ activemodel (= 7.1.6)
215
+ activerecord (= 7.1.6)
216
+ activestorage (= 7.1.6)
217
+ activesupport (= 7.1.6)
218
+ bundler (>= 1.15.0)
219
+ railties (= 7.1.6)
220
+ rails-dom-testing (2.3.0)
221
+ activesupport (>= 5.0.0)
222
+ minitest
142
223
  nokogiri (>= 1.6)
143
- rails-html-sanitizer (1.4.2)
144
- loofah (~> 2.3)
145
- railties (5.2.8)
146
- actionpack (= 5.2.8)
147
- activesupport (= 5.2.8)
148
- method_source
149
- rake (>= 0.8.7)
150
- thor (>= 0.19.0, < 2.0)
151
- rake (13.0.6)
224
+ rails-html-sanitizer (1.6.2)
225
+ loofah (~> 2.21)
226
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
227
+ railties (7.1.6)
228
+ actionpack (= 7.1.6)
229
+ activesupport (= 7.1.6)
230
+ cgi
231
+ irb
232
+ rackup (>= 1.0.0)
233
+ rake (>= 12.2)
234
+ thor (~> 1.0, >= 1.2.2)
235
+ tsort (>= 0.2)
236
+ zeitwerk (~> 2.6)
237
+ rainbow (3.1.1)
238
+ rake (13.3.1)
152
239
  rb-readline (0.5.5)
153
- rspec-core (3.9.3)
154
- rspec-support (~> 3.9.3)
155
- rspec-expectations (3.9.4)
240
+ rdoc (7.1.0)
241
+ erb
242
+ psych (>= 4.0.0)
243
+ tsort
244
+ regexp_parser (2.11.3)
245
+ reline (0.6.3)
246
+ io-console (~> 0.5)
247
+ rspec-core (3.13.6)
248
+ rspec-support (~> 3.13.0)
249
+ rspec-expectations (3.13.5)
156
250
  diff-lcs (>= 1.2.0, < 2.0)
157
- rspec-support (~> 3.9.0)
158
- rspec-mocks (3.9.1)
251
+ rspec-support (~> 3.13.0)
252
+ rspec-mocks (3.13.7)
159
253
  diff-lcs (>= 1.2.0, < 2.0)
160
- rspec-support (~> 3.9.0)
161
- rspec-rails (3.9.1)
162
- actionpack (>= 3.0)
163
- activesupport (>= 3.0)
164
- railties (>= 3.0)
165
- rspec-core (~> 3.9.0)
166
- rspec-expectations (~> 3.9.0)
167
- rspec-mocks (~> 3.9.0)
168
- rspec-support (~> 3.9.0)
169
- rspec-support (3.9.4)
254
+ rspec-support (~> 3.13.0)
255
+ rspec-rails (6.1.5)
256
+ actionpack (>= 6.1)
257
+ activesupport (>= 6.1)
258
+ railties (>= 6.1)
259
+ rspec-core (~> 3.13)
260
+ rspec-expectations (~> 3.13)
261
+ rspec-mocks (~> 3.13)
262
+ rspec-support (~> 3.13)
263
+ rspec-support (3.13.7)
264
+ rubocop (1.82.1)
265
+ json (~> 2.3)
266
+ language_server-protocol (~> 3.17.0.2)
267
+ lint_roller (~> 1.1.0)
268
+ parallel (~> 1.10)
269
+ parser (>= 3.3.0.2)
270
+ rainbow (>= 2.2.2, < 4.0)
271
+ regexp_parser (>= 2.9.3, < 3.0)
272
+ rubocop-ast (>= 1.48.0, < 2.0)
273
+ ruby-progressbar (~> 1.7)
274
+ unicode-display_width (>= 2.4.0, < 4.0)
275
+ rubocop-ast (1.49.0)
276
+ parser (>= 3.3.7.2)
277
+ prism (~> 1.7)
278
+ rubocop-performance (1.26.1)
279
+ lint_roller (~> 1.1)
280
+ rubocop (>= 1.75.0, < 2.0)
281
+ rubocop-ast (>= 1.47.1, < 2.0)
282
+ ruby-progressbar (1.13.0)
170
283
  sassc (2.4.0)
171
284
  ffi (~> 1.9)
172
285
  sassc-rails (2.1.2)
@@ -175,40 +288,63 @@ GEM
175
288
  sprockets (> 3.0)
176
289
  sprockets-rails
177
290
  tilt
291
+ securerandom (0.4.1)
178
292
  selectize-rails (0.12.6)
179
- sprockets (4.0.3)
293
+ sprockets (4.2.2)
180
294
  concurrent-ruby (~> 1.0)
181
- rack (> 1, < 3)
182
- sprockets-rails (3.4.2)
183
- actionpack (>= 5.2)
184
- activesupport (>= 5.2)
295
+ logger
296
+ rack (>= 2.2.4, < 4)
297
+ sprockets-rails (3.5.2)
298
+ actionpack (>= 6.1)
299
+ activesupport (>= 6.1)
185
300
  sprockets (>= 3.0.0)
186
- sqlite3 (1.4.2)
187
- thor (1.2.1)
188
- thread_safe (0.3.6)
189
- tilt (2.0.10)
190
- tzinfo (1.2.9)
191
- thread_safe (~> 0.1)
192
- websocket-driver (0.7.5)
301
+ sqlite3 (2.8.1)
302
+ mini_portile2 (~> 2.8.0)
303
+ sqlite3 (2.8.1-arm64-darwin)
304
+ standard (1.53.0)
305
+ language_server-protocol (~> 3.17.0.2)
306
+ lint_roller (~> 1.0)
307
+ rubocop (~> 1.82.0)
308
+ standard-custom (~> 1.0.0)
309
+ standard-performance (~> 1.8)
310
+ standard-custom (1.0.2)
311
+ lint_roller (~> 1.0)
312
+ rubocop (~> 1.50)
313
+ standard-performance (1.9.0)
314
+ lint_roller (~> 1.1)
315
+ rubocop-performance (~> 1.26.0)
316
+ stringio (3.2.0)
317
+ thor (1.5.0)
318
+ tilt (2.7.0)
319
+ timeout (0.6.0)
320
+ tsort (0.2.0)
321
+ tzinfo (2.0.6)
322
+ concurrent-ruby (~> 1.0)
323
+ unicode-display_width (3.2.0)
324
+ unicode-emoji (~> 4.1)
325
+ unicode-emoji (4.2.0)
326
+ websocket-driver (0.8.0)
327
+ base64
193
328
  websocket-extensions (>= 0.1.0)
194
329
  websocket-extensions (0.1.5)
330
+ yard (0.9.38)
331
+ zeitwerk (2.6.18)
195
332
 
196
333
  PLATFORMS
334
+ arm64-darwin
197
335
  ruby
198
336
 
199
337
  DEPENDENCIES
200
- administrate (~> 0.17.0)
201
- administrate-field-enumerate
338
+ administrate (~> 0.19.0)
202
339
  administrate_exportable!
203
340
  byebug
204
341
  pry-byebug
205
- rails (~> 5.2.3)
342
+ rails (~> 7.1.0)
206
343
  rb-readline
207
- rspec-rails (~> 3.8)
344
+ rspec-rails (~> 6.0)
208
345
  sqlite3
209
-
210
- RUBY VERSION
211
- ruby 2.7.2p137
346
+ standard
347
+ yard
212
348
 
213
349
  BUNDLED WITH
214
- 2.2.17
350
+ 2.5.11
data/README.md CHANGED
@@ -17,15 +17,19 @@ Or install it yourself as:
17
17
  ## Usage
18
18
 
19
19
  For each resource you want to be exportable, add the following line to the their respective Administrate controller.
20
+
20
21
  ```ruby
21
22
  include AdministrateExportable::Exporter
22
23
  ```
24
+
23
25
  and the following line in the `config/routes.rb` file, correctly nested on resources
26
+
24
27
  ```ruby
25
28
  get :export, on: :collection
26
29
  ```
27
30
 
28
31
  Example:
32
+
29
33
  ```ruby
30
34
  namespace :admin do
31
35
  resources :organizations do
@@ -37,6 +41,7 @@ namespace :admin do
37
41
  By default all the attributes from `ATTRIBUTE_TYPES` will be exported. If you want to exclude an attribute, you can use the option: `export: false`.
38
42
 
39
43
  Example:
44
+
40
45
  ```ruby
41
46
  class BusinessDashboard < Administrate::BaseDashboard
42
47
  ATTRIBUTE_TYPES = {
@@ -49,14 +54,16 @@ class BusinessDashboard < Administrate::BaseDashboard
49
54
  For the default field types from Administrate, we export the values you got from the partial `views/fields/index`. And if it is a custom field, we just run `field.to_s`.
50
55
  But if you want to specify the value to be exported, you can use the option `transform_on_export`, to pass a `Proc` that receives the `field`.
51
56
  Example:
57
+
52
58
  ```ruby
53
59
  ATTRIBUTE_TYPES = {
54
60
  created_at: Field::DateTime.with_options(transform_on_export: -> (field) { field.data.strftime("%F") })
55
61
  ```
56
62
 
57
- By default the gem adds the Export button to the view `views/admin/application/index.html.erb`. But if you have your own Administrate `index` views, you can add the link manually:
63
+ By default the gem adds the Export button to the partial `views/admin/application/_index_header.html.erb`. But if you have your own Administrate `index` views or override that partial in your application you can add the link manually:
64
+
58
65
  ```ruby
59
- link_to('Export', [:export, namespace.to_sym, page.resource_name.to_s.pluralize.to_sym, sanitized_order_params(page, :id).to_h.merge(format: :csv)], class: 'button') if valid_action?(:export)
66
+ link_to('Export', [:export, namespace.to_sym, page.resource_name.to_s.pluralize.to_sym, sanitized_order_params(page, :id).to_h.merge(format: :csv)], class: 'button') if existing_action?(resource_class, :export)
60
67
  ```
61
68
 
62
69
  Example:
@@ -71,17 +78,41 @@ Example:
71
78
  ),
72
79
  [:new, namespace.to_sym, page.resource_path.to_sym],
73
80
  class: "button",
74
- ) if valid_action?(:new) && show_action?(:new, new_resource) %>
81
+ ) if existing_action?(resource_class, :new) && authorized_action?(new_resource, :new) %>
75
82
 
76
83
  <%= link_to(
77
84
  'Export',
78
85
  [:export, namespace.to_sym, page.resource_name.to_s.pluralize.to_sym, sanitized_order_params(page, :id).to_h.merge(format: :csv)],
79
86
  class: 'button'
80
- ) if valid_action?(:export) %>
87
+ ) if existing_action?(resource_class, :export) %>
81
88
  </div>
82
89
  ....
83
90
  ```
84
91
 
92
+ ### Using with Pundit
93
+
94
+ If you are using [Pundit](https://github.com/varvet/pundit) in your project you will receive an error saying `undefined method 'export?' for #<Admin::OrganizationPolicy>`. This is because the `export` action is not defined in the policy.
95
+
96
+ To fix this issue you need to add the `export` action to the policy and define the logic for who can export the resource.
97
+
98
+ Example:
99
+
100
+ ```ruby
101
+ module Admin
102
+ class OrganizationPolicy < ApplicationPolicy
103
+ # ... other methods ...
104
+
105
+ def export?
106
+ # Define the logic for who can export organizations
107
+ # For example, allow only admins to export:
108
+ user.admin?
109
+ end
110
+
111
+ # ... other methods ...
112
+ end
113
+ end
114
+ ```
115
+
85
116
  ## Development
86
117
 
87
118
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require "yard"
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
6
+ YARD::Rake::YardocTask.new
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -1,17 +1,16 @@
1
-
2
1
  lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "administrate_exportable/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "administrate_exportable"
8
- spec.version = AdministrateExportable::VERSION
9
- spec.authors = ["Jônatas Rancan", "Andrei Bondarev"]
10
- spec.email = ["hello@sourcelabs.io"]
11
- spec.homepage = 'https://github.com/SourceLabsLLC/administrate_exportable'
12
- spec.summary = "Simple plugin to add CSV export feature to Administrate"
13
- spec.description = spec.summary
14
- spec.license = "MIT"
6
+ spec.name = "administrate_exportable"
7
+ spec.version = AdministrateExportable::VERSION
8
+ spec.authors = ["Jônatas Rancan", "Andrei Bondarev"]
9
+ spec.email = ["hello@sourcelabs.io"]
10
+ spec.homepage = "https://github.com/SourceLabsLLC/administrate_exportable"
11
+ spec.summary = "Simple plugin to add CSV export feature to Administrate"
12
+ spec.description = spec.summary
13
+ spec.license = "MIT"
15
14
 
16
15
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
16
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -22,19 +21,20 @@ Gem::Specification.new do |spec|
22
21
  # "public gem pushes."
23
22
  # end
24
23
 
25
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
25
  f.match(%r{^(test|spec|features)/})
27
26
  end
28
- spec.bindir = "exe"
29
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
29
  spec.require_paths = ["lib"]
31
30
 
32
31
  spec.add_development_dependency "bundler", "~> 1.16"
33
32
  spec.add_development_dependency "rake", "~> 10.0"
34
33
  spec.add_development_dependency "rspec", "~> 3.0"
35
34
  spec.add_development_dependency "pry-byebug", "~> 3.0"
36
- spec.add_dependency 'administrate','>= 0.17.0'
37
- spec.add_dependency 'rails', '>= 4.2'
38
- spec.add_dependency 'actionview', '>= 5.2.2.1'
39
- spec.add_dependency 'railties', '>= 5.2.2.1'
35
+ spec.add_dependency "administrate", ">= 0.17.0"
36
+ spec.add_dependency "rails", ">= 4.2"
37
+ spec.add_dependency "actionview", ">= 5.2.2.1"
38
+ spec.add_dependency "railties", ">= 5.2.2.1"
39
+ spec.add_dependency "csv", "~> 3.0"
40
40
  end
@@ -0,0 +1,35 @@
1
+ <% content_for(:title) do %>
2
+ <%= display_resource_name(page.resource_name) %>
3
+ <% end %>
4
+
5
+ <header class="main-content__header">
6
+ <h1 class="main-content__page-title" id="page-title">
7
+ <%= content_for(:title) %>
8
+ </h1>
9
+
10
+ <% if show_search_bar %>
11
+ <%= render(
12
+ "search",
13
+ search_term: search_term,
14
+ resource_name: display_resource_name(page.resource_name)
15
+ ) %>
16
+ <% end %>
17
+
18
+ <div>
19
+ <%= link_to(
20
+ t(
21
+ "administrate.actions.new_resource",
22
+ name: display_resource_name(page.resource_name, singular: true).downcase
23
+ ),
24
+ [:new, namespace, page.resource_path.to_sym],
25
+ class: "button",
26
+ ) if accessible_action?(new_resource, :new) %>
27
+
28
+ <%= link_to(
29
+ 'Export',
30
+ [:export, namespace, page.resource_name.to_s.pluralize.to_sym, sanitized_order_params(page, :id).to_h.merge(format: :csv)],
31
+ class: 'button',
32
+ target: '_blank'
33
+ ) if existing_action?(resource_class, :export) && authorized_action?(resource_name, :export) %>
34
+ </div>
35
+ </header>
@@ -11,8 +11,8 @@ module AdministrateExportable
11
11
  define_method(:export) do
12
12
  search_term = params[:search].to_s.strip
13
13
  resources = Administrate::Search.new(scoped_resource,
14
- dashboard,
15
- search_term).run
14
+ dashboard,
15
+ search_term).run
16
16
  resources = apply_collection_includes(resources)
17
17
  resources = order.apply(resources)
18
18
 
@@ -1,4 +1,4 @@
1
- require 'csv'
1
+ require "csv"
2
2
 
3
3
  module AdministrateExportable
4
4
  class ExporterService
@@ -14,7 +14,6 @@ module AdministrateExportable
14
14
 
15
15
  def csv
16
16
  CSV.generate(headers: true) do |csv|
17
-
18
17
  csv << headers
19
18
 
20
19
  collection.find_each do |record|
@@ -30,7 +29,7 @@ module AdministrateExportable
30
29
  attr_reader :dashboard, :resource_class, :resources, :sanitizer
31
30
 
32
31
  def record_attribute(record, attribute_key, attribute_type)
33
- field = attribute_type.new(attribute_key, record.send(attribute_key), 'index', resource: record)
32
+ field = attribute_type.new(attribute_key, record.send(attribute_key), "index", resource: record)
34
33
  transform_on_export = attribute_type.respond_to?(:options) && attribute_type.options[:transform_on_export]
35
34
 
36
35
  if transform_on_export.is_a? Proc
@@ -41,7 +40,7 @@ module AdministrateExportable
41
40
  when Administrate::Field::BelongsTo.to_s, Administrate::Field::HasOne.to_s, Administrate::Field::Polymorphic.to_s
42
41
  field.display_associated_resource if field.data
43
42
  when Administrate::Field::HasMany.to_s
44
- field.data.count if field.data
43
+ field.data&.count
45
44
  when Administrate::Field::DateTime.to_s
46
45
  field.datetime if field.data
47
46
  when Administrate::Field::Date.to_s
@@ -61,24 +60,22 @@ module AdministrateExportable
61
60
  attributes_to_export.map do |attribute_key, _|
62
61
  attr_key = attribute_key.to_s
63
62
 
64
- if attr_key.include?('_id')
63
+ if attr_key.include?("_id")
65
64
  attr_key
66
65
  else
67
- I18n.t(
66
+ I18n.t(
68
67
  "helpers.label.#{resource_class.name.downcase}.#{attr_key}",
69
- default: attr_key,
68
+ default: attr_key
70
69
  ).titleize
71
70
  end
72
71
  end
73
72
  end
74
73
 
75
74
  def attributes_to_export
76
- @attributes_to_export ||= begin
77
- dashboard.class::ATTRIBUTE_TYPES.select do |attribute_key, attribute_type|
78
- attribute_options = attribute_type.try(:options)
75
+ @attributes_to_export ||= dashboard.class::ATTRIBUTE_TYPES.select do |attribute_key, attribute_type|
76
+ attribute_options = attribute_type.try(:options)
79
77
 
80
- !attribute_options || attribute_options[:export] != false
81
- end
78
+ !attribute_options || attribute_options[:export] != false
82
79
  end
83
80
  end
84
81
 
@@ -1,3 +1,3 @@
1
1
  module AdministrateExportable
2
- VERSION = "0.6.2"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -4,7 +4,7 @@ require "administrate_exportable/exporter"
4
4
  require "administrate/version"
5
5
 
6
6
  module AdministrateExportable
7
- PAGE_PARAM = Gem::Version.create(Administrate::VERSION) >= Gem::Version.create('0.15.0') ? '_page' : 'page'
7
+ PAGE_PARAM = (Gem::Version.create(Administrate::VERSION) >= Gem::Version.create("0.15.0")) ? "_page" : "page"
8
8
 
9
9
  class Engine < ::Rails::Engine
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate_exportable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jônatas Rancan
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-02-03 00:00:00.000000000 Z
12
+ date: 2026-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -123,6 +123,20 @@ dependencies:
123
123
  - - ">="
124
124
  - !ruby/object:Gem::Version
125
125
  version: 5.2.2.1
126
+ - !ruby/object:Gem::Dependency
127
+ name: csv
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '3.0'
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '3.0'
126
140
  description: Simple plugin to add CSV export feature to Administrate
127
141
  email:
128
142
  - hello@sourcelabs.io
@@ -130,6 +144,7 @@ executables: []
130
144
  extensions: []
131
145
  extra_rdoc_files: []
132
146
  files:
147
+ - ".github/workflows/ci.yml"
133
148
  - ".gitignore"
134
149
  - ".rspec"
135
150
  - ".tool-versions"
@@ -140,8 +155,8 @@ files:
140
155
  - README.md
141
156
  - Rakefile
142
157
  - administrate_exportable.gemspec
158
+ - app/views/admin/application/_index_header.html.erb
143
159
  - app/views/admin/application/_pagination.html.erb
144
- - app/views/admin/application/index.html.erb
145
160
  - bin/console
146
161
  - bin/setup
147
162
  - lib/administrate_exportable.rb
@@ -167,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
182
  - !ruby/object:Gem::Version
168
183
  version: '0'
169
184
  requirements: []
170
- rubygems_version: 3.1.4
185
+ rubygems_version: 3.3.27
171
186
  signing_key:
172
187
  specification_version: 4
173
188
  summary: Simple plugin to add CSV export feature to Administrate
@@ -1,68 +0,0 @@
1
- <%#
2
- # Index
3
- This view is the template for the index page.
4
- It is responsible for rendering the search bar, header and pagination.
5
- It renders the `_table` partial to display details about the resources.
6
- ## Local variables:
7
- - `page`:
8
- An instance of [Administrate::Page::Collection][1].
9
- Contains helper methods to help display a table,
10
- and knows which attributes should be displayed in the resource's table.
11
- - `resources`:
12
- An instance of `ActiveRecord::Relation` containing the resources
13
- that match the user's search criteria.
14
- By default, these resources are passed to the table partial to be displayed.
15
- - `search_term`:
16
- A string containing the term the user has searched for, if any.
17
- - `show_search_bar`:
18
- A boolean that determines if the search bar should be shown.
19
- [1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
20
- %>
21
-
22
- <% content_for(:title) do %>
23
- <%= display_resource_name(page.resource_name) %>
24
- <% end %>
25
-
26
- <header class="main-content__header" role="banner">
27
- <h1 class="main-content__page-title" id="page-title">
28
- <%= content_for(:title) %>
29
- </h1>
30
-
31
- <% if show_search_bar %>
32
- <%= render(
33
- "search",
34
- search_term: search_term,
35
- resource_name: display_resource_name(page.resource_name)
36
- ) %>
37
- <% end %>
38
-
39
- <div>
40
- <%= link_to(
41
- t(
42
- "administrate.actions.new_resource",
43
- name: page.resource_name.titleize.downcase
44
- ),
45
- [:new, namespace, page.resource_path.to_sym],
46
- class: "button",
47
- ) if valid_action?(:new) && show_action?(:new, new_resource) %>
48
- <%= link_to(
49
- 'Export',
50
- [:export, namespace, page.resource_name.to_s.pluralize.to_sym, sanitized_order_params(page, :id).to_h.merge(format: :csv)],
51
- class: 'button',
52
- target: '_blank'
53
- ) if valid_action?(:export) && show_action?(:export, resource_name) %>
54
- </div>
55
- </header>
56
-
57
- <section class="main-content__body main-content__body--flush">
58
- <%= render(
59
- "collection",
60
- collection_presenter: page,
61
- collection_field_name: resource_name,
62
- page: page,
63
- resources: resources,
64
- table_title: "page-title"
65
- ) %>
66
-
67
- <%= render("pagination", resources: resources) %>
68
- </section>