administrate-field-active_storage 0.3.6 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +21 -0
  3. data/.gitignore +0 -1
  4. data/.ruby-version +1 -1
  5. data/Gemfile.lock +211 -0
  6. data/README.md +22 -3
  7. data/administrate-field-active_storage.gemspec +4 -3
  8. data/app/assets/stylesheets/administrate-field-active_storage/application.css +15 -0
  9. data/app/views/fields/active_storage/_form.html.erb +4 -1
  10. data/app/views/fields/active_storage/_index.html.erb +20 -12
  11. data/app/views/fields/active_storage/_item.html.erb +2 -1
  12. data/app/views/fields/active_storage/_items.html.erb +8 -1
  13. data/app/views/fields/active_storage/_preview.html.erb +8 -4
  14. data/app/views/fields/active_storage/_show.html.erb +1 -1
  15. data/config/i18n-tasks.yml +8 -0
  16. data/config/locales/administrate-field-active_storage.en.yml +10 -0
  17. data/config/locales/administrate-field-active_storage.ru.yml +10 -0
  18. data/contribute.md +1 -0
  19. data/lib/administrate/field/active_storage.rb +10 -1
  20. data/spec/i18n_spec.rb +35 -0
  21. data/test_app/.browserslistrc +1 -0
  22. data/test_app/.gitattributes +10 -0
  23. data/{example-project → test_app}/.gitignore +9 -7
  24. data/test_app/.ruby-version +1 -0
  25. data/test_app/Gemfile +45 -0
  26. data/test_app/Gemfile.lock +240 -0
  27. data/{example-project → test_app}/README.md +0 -0
  28. data/{example-project → test_app}/Rakefile +1 -1
  29. data/test_app/app/assets/config/manifest.js +4 -0
  30. data/{example-project → test_app}/app/assets/images/.keep +0 -0
  31. data/{example-project → test_app}/app/assets/stylesheets/application.css +0 -0
  32. data/{example-project → test_app}/app/controllers/admin/application_controller.rb +3 -3
  33. data/test_app/app/controllers/admin/posts_controller.rb +46 -0
  34. data/{example-project → test_app}/app/controllers/application_controller.rb +0 -0
  35. data/{example-project/app/dashboards/user_dashboard.rb → test_app/app/dashboards/post_dashboard.rb} +29 -27
  36. data/{example-project → test_app}/app/helpers/application_helper.rb +0 -0
  37. data/test_app/app/javascript/packs/application.js +10 -0
  38. data/{example-project → test_app}/app/models/application_record.rb +0 -0
  39. data/test_app/app/models/post.rb +3 -0
  40. data/test_app/app/views/layouts/application.html.erb +16 -0
  41. data/test_app/bin/bundle +114 -0
  42. data/test_app/bin/rails +4 -0
  43. data/test_app/bin/rake +4 -0
  44. data/{example-project → test_app}/bin/setup +6 -9
  45. data/test_app/config/application.rb +35 -0
  46. data/{example-project/bin/bundle → test_app/config/boot.rb} +2 -2
  47. data/test_app/config/credentials.yml.enc +1 -0
  48. data/{example-project → test_app}/config/database.yml +1 -1
  49. data/{example-project → test_app}/config/environment.rb +1 -1
  50. data/{example-project → test_app}/config/environments/development.rb +21 -11
  51. data/{example-project → test_app}/config/environments/production.rb +36 -24
  52. data/{example-project → test_app}/config/environments/test.rb +20 -14
  53. data/{example-project → test_app}/config/initializers/application_controller_renderer.rb +0 -0
  54. data/{example-project → test_app}/config/initializers/assets.rb +0 -0
  55. data/test_app/config/initializers/backtrace_silencers.rb +8 -0
  56. data/{example-project → test_app}/config/initializers/content_security_policy.rb +5 -0
  57. data/{example-project → test_app}/config/initializers/cookies_serializer.rb +0 -0
  58. data/{example-project → test_app}/config/initializers/filter_parameter_logging.rb +3 -1
  59. data/{example-project → test_app}/config/initializers/inflections.rb +0 -0
  60. data/{example-project → test_app}/config/initializers/mime_types.rb +0 -0
  61. data/test_app/config/initializers/permissions_policy.rb +11 -0
  62. data/{example-project → test_app}/config/initializers/wrap_parameters.rb +0 -0
  63. data/{example-project → test_app}/config/locales/en.yml +1 -1
  64. data/{example-project → test_app}/config/puma.rb +13 -4
  65. data/test_app/config/routes.rb +9 -0
  66. data/{example-project → test_app}/config/storage.yml +0 -0
  67. data/{example-project → test_app}/config.ru +2 -1
  68. data/{example-project/db/migrate/20181221134334_create_active_storage_tables.active_storage.rb → test_app/db/migrate/20210118122804_create_active_storage_tables.active_storage.rb} +15 -5
  69. data/test_app/db/migrate/20210118122927_create_posts.rb +8 -0
  70. data/{example-project → test_app}/db/schema.rb +18 -10
  71. data/{example-project → test_app}/db/seeds.rb +1 -1
  72. data/test_app/lib/active_storage/fixture_set.rb +71 -0
  73. data/{example-project → test_app}/public/404.html +0 -0
  74. data/{example-project → test_app}/public/422.html +0 -0
  75. data/{example-project → test_app}/public/500.html +0 -0
  76. data/{example-project → test_app}/public/apple-touch-icon-precomposed.png +0 -0
  77. data/{example-project → test_app}/public/apple-touch-icon.png +0 -0
  78. data/{example-project → test_app}/public/favicon.ico +0 -0
  79. data/test_app/public/robots.txt +1 -0
  80. data/{example-project → test_app}/test/application_system_test_case.rb +0 -0
  81. data/test_app/test/controllers/admin/posts_controller_test.rb +14 -0
  82. data/test_app/test/fixtures/active_storage/attachments.yml +4 -0
  83. data/test_app/test/fixtures/active_storage/blobs.yml +2 -0
  84. data/test_app/test/fixtures/files/cover_image.jpg +0 -0
  85. data/test_app/test/fixtures/posts.yml +11 -0
  86. data/test_app/test/models/post_test.rb +9 -0
  87. data/test_app/test/test_helper.rb +20 -0
  88. metadata +100 -101
  89. data/Rakefile +0 -22
  90. data/example-project/.ruby-version +0 -1
  91. data/example-project/Gemfile +0 -67
  92. data/example-project/Gemfile.lock +0 -265
  93. data/example-project/app/assets/config/manifest.js +0 -3
  94. data/example-project/app/assets/javascripts/application.js +0 -16
  95. data/example-project/app/assets/javascripts/cable.js +0 -13
  96. data/example-project/app/assets/javascripts/channels/.keep +0 -0
  97. data/example-project/app/channels/application_cable/channel.rb +0 -4
  98. data/example-project/app/channels/application_cable/connection.rb +0 -4
  99. data/example-project/app/controllers/admin/users_controller.rb +0 -27
  100. data/example-project/app/controllers/concerns/.keep +0 -0
  101. data/example-project/app/controllers/users_controller.rb +0 -7
  102. data/example-project/app/jobs/application_job.rb +0 -2
  103. data/example-project/app/mailers/application_mailer.rb +0 -4
  104. data/example-project/app/models/concerns/.keep +0 -0
  105. data/example-project/app/models/user.rb +0 -3
  106. data/example-project/app/views/layouts/application.html.erb +0 -15
  107. data/example-project/app/views/layouts/mailer.html.erb +0 -13
  108. data/example-project/app/views/layouts/mailer.text.erb +0 -1
  109. data/example-project/bin/rails +0 -9
  110. data/example-project/bin/rake +0 -9
  111. data/example-project/bin/spring +0 -17
  112. data/example-project/bin/update +0 -31
  113. data/example-project/bin/yarn +0 -11
  114. data/example-project/config/application.rb +0 -19
  115. data/example-project/config/boot.rb +0 -4
  116. data/example-project/config/cable.yml +0 -10
  117. data/example-project/config/credentials.yml.enc +0 -1
  118. data/example-project/config/initializers/backtrace_silencers.rb +0 -7
  119. data/example-project/config/routes.rb +0 -10
  120. data/example-project/config/spring.rb +0 -6
  121. data/example-project/db/migrate/20181013145025_create_users.rb +0 -9
  122. data/example-project/lib/assets/.keep +0 -0
  123. data/example-project/lib/tasks/.keep +0 -0
  124. data/example-project/log/.keep +0 -0
  125. data/example-project/package.json +0 -5
  126. data/example-project/public/robots.txt +0 -1
  127. data/example-project/test/controllers/.keep +0 -0
  128. data/example-project/test/fixtures/.keep +0 -0
  129. data/example-project/test/fixtures/files/.keep +0 -0
  130. data/example-project/test/fixtures/users.yml +0 -7
  131. data/example-project/test/helpers/.keep +0 -0
  132. data/example-project/test/integration/.keep +0 -0
  133. data/example-project/test/mailers/.keep +0 -0
  134. data/example-project/test/models/.keep +0 -0
  135. data/example-project/test/models/user_test.rb +0 -7
  136. data/example-project/test/system/.keep +0 -0
  137. data/example-project/test/test_helper.rb +0 -10
  138. data/example-project/tmp/.keep +0 -0
  139. data/example-project/vendor/.keep +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3930e26efcb0aa795b6606100a6dd6e8da523f80e7f201def1aa5ab79219217
4
- data.tar.gz: '0286fd8dcca57e38402f283fef4971b62cb88d909d4a6d00255aaffa3581286e'
3
+ metadata.gz: 325bb9d01b865e2f1040d323dadadfdba96ef0a1dd2931392f24943012491764
4
+ data.tar.gz: fd8cdf3df0ba4638eea1125bb557878646cc40979c41a1522487c0af162fa052
5
5
  SHA512:
6
- metadata.gz: 2942162811a236a3adc02f9607a2d941f002e40b422b3a39c83a148666390542eb15235ae3a6f65d906b3a2075b19e7946e4278091af55ce254ad423886ae923
7
- data.tar.gz: 4e7800b780d17f2bf6ee6faa0d0b11a1e22e1456397d46d8e38a04d619be800ae7fc2778364c23f1041ef1e42c34276b11db8ca58fd34906db5822d42a99ccb1
6
+ metadata.gz: 0fa9781cf805f7e80bf482c27ad0cf88180f014bc88a8234c6aa219855bd6d7d745b45783b2128c4482be9785cac0884b00e2e2bb401b1a158707cf6fbfded1f
7
+ data.tar.gz: 4dfc6fe7861abd65ff323effba94baf3485a00c43d0889e8efc6d68a3540d8a93509c762c7dd3dce94c6320b15badf2afc9b842d41cb29ec574f3c34ee9a0280
@@ -0,0 +1,21 @@
1
+ name: CI
2
+
3
+ on: [push,pull_request]
4
+
5
+ env:
6
+ RAILS_MASTER_KEY: ca18e029a12884a87e96cf6a64a12fb5
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - uses: ruby/setup-ruby@v1
14
+ - uses: actions/cache@v2
15
+ with:
16
+ path: vendor/bundle
17
+ key: bundle-use-ruby-${{ matrix.os }}-${{ matrix.ruby }}-${{ hashFiles('**/Gemfile.lock') }}
18
+ restore-keys: |
19
+ bundle-use-ruby-${{ matrix.os }}-${{ matrix.ruby }}-
20
+ - run: test_app/bin/setup
21
+ - run: cd test_app && bundle exec rails test
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.5
1
+ 3.0.3
data/Gemfile.lock ADDED
@@ -0,0 +1,211 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ administrate-field-active_storage (0.3.8)
5
+ administrate (>= 0.2.2)
6
+ rails (>= 6.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (7.0.0)
12
+ actionpack (= 7.0.0)
13
+ activesupport (= 7.0.0)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ actionmailbox (7.0.0)
17
+ actionpack (= 7.0.0)
18
+ activejob (= 7.0.0)
19
+ activerecord (= 7.0.0)
20
+ activestorage (= 7.0.0)
21
+ activesupport (= 7.0.0)
22
+ mail (>= 2.7.1)
23
+ actionmailer (7.0.0)
24
+ actionpack (= 7.0.0)
25
+ actionview (= 7.0.0)
26
+ activejob (= 7.0.0)
27
+ activesupport (= 7.0.0)
28
+ mail (~> 2.5, >= 2.5.4)
29
+ rails-dom-testing (~> 2.0)
30
+ actionpack (7.0.0)
31
+ actionview (= 7.0.0)
32
+ activesupport (= 7.0.0)
33
+ rack (~> 2.0, >= 2.2.0)
34
+ rack-test (>= 0.6.3)
35
+ rails-dom-testing (~> 2.0)
36
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
37
+ actiontext (7.0.0)
38
+ actionpack (= 7.0.0)
39
+ activerecord (= 7.0.0)
40
+ activestorage (= 7.0.0)
41
+ activesupport (= 7.0.0)
42
+ globalid (>= 0.6.0)
43
+ nokogiri (>= 1.8.5)
44
+ actionview (7.0.0)
45
+ activesupport (= 7.0.0)
46
+ builder (~> 3.1)
47
+ erubi (~> 1.4)
48
+ rails-dom-testing (~> 2.0)
49
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
50
+ activejob (7.0.0)
51
+ activesupport (= 7.0.0)
52
+ globalid (>= 0.3.6)
53
+ activemodel (7.0.0)
54
+ activesupport (= 7.0.0)
55
+ activerecord (7.0.0)
56
+ activemodel (= 7.0.0)
57
+ activesupport (= 7.0.0)
58
+ activestorage (7.0.0)
59
+ actionpack (= 7.0.0)
60
+ activejob (= 7.0.0)
61
+ activerecord (= 7.0.0)
62
+ activesupport (= 7.0.0)
63
+ marcel (~> 1.0)
64
+ mini_mime (>= 1.1.0)
65
+ activesupport (7.0.0)
66
+ concurrent-ruby (~> 1.0, >= 1.0.2)
67
+ i18n (>= 1.6, < 2)
68
+ minitest (>= 5.1)
69
+ tzinfo (~> 2.0)
70
+ administrate (0.16.0)
71
+ actionpack (>= 5.0)
72
+ actionview (>= 5.0)
73
+ activerecord (>= 5.0)
74
+ datetime_picker_rails (~> 0.0.7)
75
+ jquery-rails (>= 4.0)
76
+ kaminari (>= 1.0)
77
+ momentjs-rails (~> 2.8)
78
+ sassc-rails (~> 2.1)
79
+ selectize-rails (~> 0.6)
80
+ ast (2.4.2)
81
+ builder (3.2.4)
82
+ concurrent-ruby (1.1.9)
83
+ crass (1.0.6)
84
+ datetime_picker_rails (0.0.7)
85
+ momentjs-rails (>= 2.8.1)
86
+ erubi (1.10.0)
87
+ ffi (1.15.4)
88
+ globalid (1.0.0)
89
+ activesupport (>= 5.0)
90
+ highline (2.0.3)
91
+ i18n (1.8.11)
92
+ concurrent-ruby (~> 1.0)
93
+ i18n-tasks (0.9.37)
94
+ activesupport (>= 4.0.2)
95
+ ast (>= 2.1.0)
96
+ erubi
97
+ highline (>= 2.0.0)
98
+ i18n
99
+ parser (>= 2.2.3.0)
100
+ rails-i18n
101
+ rainbow (>= 2.2.2, < 4.0)
102
+ terminal-table (>= 1.5.1)
103
+ jquery-rails (4.4.0)
104
+ rails-dom-testing (>= 1, < 3)
105
+ railties (>= 4.2.0)
106
+ thor (>= 0.14, < 2.0)
107
+ kaminari (1.2.2)
108
+ activesupport (>= 4.1.0)
109
+ kaminari-actionview (= 1.2.2)
110
+ kaminari-activerecord (= 1.2.2)
111
+ kaminari-core (= 1.2.2)
112
+ kaminari-actionview (1.2.2)
113
+ actionview
114
+ kaminari-core (= 1.2.2)
115
+ kaminari-activerecord (1.2.2)
116
+ activerecord
117
+ kaminari-core (= 1.2.2)
118
+ kaminari-core (1.2.2)
119
+ loofah (2.13.0)
120
+ crass (~> 1.0.2)
121
+ nokogiri (>= 1.5.9)
122
+ mail (2.7.1)
123
+ mini_mime (>= 0.1.1)
124
+ marcel (1.0.2)
125
+ method_source (1.0.0)
126
+ mini_mime (1.1.2)
127
+ minitest (5.15.0)
128
+ momentjs-rails (2.29.1)
129
+ railties (>= 3.1)
130
+ nio4r (2.5.8)
131
+ nokogiri (1.13.3-x86_64-darwin)
132
+ racc (~> 1.4)
133
+ nokogiri (1.13.3-x86_64-linux)
134
+ racc (~> 1.4)
135
+ parser (3.0.3.2)
136
+ ast (~> 2.4.1)
137
+ racc (1.6.0)
138
+ rack (2.2.3)
139
+ rack-test (1.1.0)
140
+ rack (>= 1.0, < 3)
141
+ rails (7.0.0)
142
+ actioncable (= 7.0.0)
143
+ actionmailbox (= 7.0.0)
144
+ actionmailer (= 7.0.0)
145
+ actionpack (= 7.0.0)
146
+ actiontext (= 7.0.0)
147
+ actionview (= 7.0.0)
148
+ activejob (= 7.0.0)
149
+ activemodel (= 7.0.0)
150
+ activerecord (= 7.0.0)
151
+ activestorage (= 7.0.0)
152
+ activesupport (= 7.0.0)
153
+ bundler (>= 1.15.0)
154
+ railties (= 7.0.0)
155
+ rails-dom-testing (2.0.3)
156
+ activesupport (>= 4.2.0)
157
+ nokogiri (>= 1.6)
158
+ rails-html-sanitizer (1.4.2)
159
+ loofah (~> 2.3)
160
+ rails-i18n (7.0.1)
161
+ i18n (>= 0.7, < 2)
162
+ railties (>= 6.0.0, < 8)
163
+ railties (7.0.0)
164
+ actionpack (= 7.0.0)
165
+ activesupport (= 7.0.0)
166
+ method_source
167
+ rake (>= 12.2)
168
+ thor (~> 1.0)
169
+ zeitwerk (~> 2.5)
170
+ rainbow (3.0.0)
171
+ rake (13.0.6)
172
+ sassc (2.4.0)
173
+ ffi (~> 1.9)
174
+ sassc-rails (2.1.2)
175
+ railties (>= 4.0.0)
176
+ sassc (>= 2.0)
177
+ sprockets (> 3.0)
178
+ sprockets-rails
179
+ tilt
180
+ selectize-rails (0.12.6)
181
+ sprockets (4.0.2)
182
+ concurrent-ruby (~> 1.0)
183
+ rack (> 1, < 3)
184
+ sprockets-rails (3.4.2)
185
+ actionpack (>= 5.2)
186
+ activesupport (>= 5.2)
187
+ sprockets (>= 3.0.0)
188
+ sqlite3 (1.4.2)
189
+ terminal-table (3.0.2)
190
+ unicode-display_width (>= 1.1.1, < 3)
191
+ thor (1.1.0)
192
+ tilt (2.0.10)
193
+ tzinfo (2.0.4)
194
+ concurrent-ruby (~> 1.0)
195
+ unicode-display_width (2.1.0)
196
+ websocket-driver (0.7.5)
197
+ websocket-extensions (>= 0.1.0)
198
+ websocket-extensions (0.1.5)
199
+ zeitwerk (2.5.2)
200
+
201
+ PLATFORMS
202
+ x86_64-darwin-20
203
+ x86_64-linux
204
+
205
+ DEPENDENCIES
206
+ administrate-field-active_storage!
207
+ i18n-tasks (~> 0.9.34)
208
+ sqlite3 (~> 1.4)
209
+
210
+ BUNDLED WITH
211
+ 2.2.33
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Administrate::Field::ActiveStorage
2
2
  ![rails](https://img.shields.io/badge/rails-%3E%3D5.2.0-red.svg)
3
+ ![CI](https://github.com/Dreamersoul/administrate-field-active_storage/workflows/CI/badge.svg)
3
4
 
4
5
  ## Things To Know:
5
6
  - To preview pdf files you need to install `mupdf` or `Poppler`.
@@ -16,7 +17,7 @@ gem "image_processing"
16
17
 
17
18
  for rails 5.x use the following
18
19
  ```ruby
19
- gem 'administrate-field-active_storage' -v 0.1.8
20
+ gem 'administrate-field-active_storage', "0.1.8"
20
21
  ```
21
22
 
22
23
  Install:
@@ -59,6 +60,8 @@ class ModelDashboard < Administrate::BaseDashboard
59
60
  ```
60
61
  I know it is not ideal, if you have a workaround please submit a PR.
61
62
 
63
+ Note: Rails 6 introduced a new config to determine the behavior on updates to `has_many_attached`. Setting `Rails.application.config.active_storage.replace_on_assign_to_many` to `true` will overwrite any existing values (purging the old ones), and setting it to `false` will append the new values.
64
+
62
65
  ### Prevent N+1 queries
63
66
  In order to prevent N+1 queries from active storage you have to modify your admin model controller, below an example for a model called `User` and with attached avatars
64
67
  ```ruby
@@ -187,6 +190,17 @@ for documentation.
187
190
 
188
191
  Default to `[150, 150]` and `[800, 800]`, respectively.
189
192
 
193
+ ### index_preview_variant and show_preview_variant
194
+
195
+ Use a named variant for image preview for the `index` and `show` actions, respectively.
196
+ Named image variants were [added in Rails 7](https://guides.rubyonrails.org/v7.0/active_storage_overview.html#has-one-attached).
197
+
198
+ It might be necessary to add to app/assets/config/manifest.js:
199
+ ```rb
200
+ //= link 'administrate-field-active_storage/application.css'
201
+ ```
202
+ When set, this takes precedence over `index_preview_size` and `show_preview_size`.
203
+
190
204
  ### index_display_count
191
205
 
192
206
  Displays the number of attachments in the `index` action.
@@ -201,6 +215,10 @@ Defaults to `false`.
201
215
 
202
216
  Don't forget to include [ActiveStorage JavaScript](https://edgeguides.rubyonrails.org/active_storage_overview.html#direct-uploads). You can use `rails generate administrate:assets:javascripts` to be able to customize Administrate JavaScripts in your application.
203
217
 
218
+ ## I18n
219
+
220
+ You can see translation example [here](https://github.com/Dreamersoul/administrate-field-active_storage/blob/master/config/locales/administrate-field-active_storage.en.yml).
221
+
204
222
  ## Things To Do:
205
223
  - [x] upload single file
206
224
  - [x] adding image support through url_for to support 3rd party cloud storage
@@ -215,8 +233,9 @@ Don't forget to include [ActiveStorage JavaScript](https://edgeguides.rubyonrail
215
233
 
216
234
  ## Contribution Guide:
217
235
  1. contributers are welcome (code, suggestions, and bugs).
218
- 2. please document your code.
219
- 3. add your name to the `contribute.md`.
236
+ 2. please test your code: `cd test_app && bundle && bundle exec rails test`.
237
+ 3. please document your code.
238
+ 4. add your name to the `contribute.md`.
220
239
 
221
240
  ---
222
241
  Based on the [Administrate::Field::Image](https://github.com/thoughtbot/administrate-field-image) template, and inspired by [Administrate::Field::Paperclip](https://github.com/picandocodigo/administrate-field-paperclip).
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "administrate-field-active_storage"
5
- gem.version = "0.3.6"
5
+ gem.version = "0.4.0"
6
6
  gem.authors = ["Hamad AlGhanim"]
7
7
  gem.email = ["hamadyalghanim@gmail.com"]
8
8
  gem.homepage = "https://github.com/Dreamersoul/administrate-field-active_storage"
@@ -15,7 +15,8 @@ Gem::Specification.new do |gem|
15
15
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
16
 
17
17
  gem.add_dependency "administrate", ">= 0.2.2"
18
- gem.add_dependency "rails", ">= 6.0"
18
+ gem.add_dependency "rails", ">= 7.0"
19
19
 
20
- gem.add_development_dependency "rspec", "~> 3.4"
20
+ gem.add_development_dependency 'sqlite3', '~> 1.4'
21
+ gem.add_development_dependency 'i18n-tasks', '~> 0.9.34'
21
22
  end
@@ -0,0 +1,15 @@
1
+ td img {
2
+ max-height: unset !important;
3
+ }
4
+ .as-field {
5
+ height: auto;
6
+ overflow: hidden;
7
+ }
8
+ .as-field-index img {
9
+ width: 50%;
10
+ }
11
+ .as-field-video {
12
+ object-fit: contain;
13
+ width: 100%;
14
+ height: 100%;
15
+ }
@@ -25,7 +25,10 @@ By default, the input is a text field for the image's URL.
25
25
  <% end %>
26
26
 
27
27
  <div>
28
- <%= field.can_add_attachment? ? "Add:" : "Replace:" %>
28
+ <%= field.can_add_attachment? ?
29
+ I18n.t("administrate.fields.active_storage.add", default: 'Add') :
30
+ I18n.t("administrate.fields.active_storage.replace", default: 'Replace')
31
+ %>
29
32
  <%= f.file_field field.attribute, multiple: field.many?, direct_upload: field.direct? %>
30
33
  </div>
31
34
  </div>
@@ -16,23 +16,31 @@ By default, the attribute is rendered as an image tag.
16
16
  %>
17
17
 
18
18
  <% if field.attached? %>
19
- <style> <%# figure out a way to remove this %>
20
- td img {
21
- max-height: unset !important;
22
- }
23
- </style>
24
19
  <% if field.index_display_preview? %>
25
- <%= render partial: 'fields/active_storage/preview',
26
- locals: {
27
- field: field,
28
- attachment: field.data,
29
- size: field.index_preview_size
30
- } %>
20
+ <% if field.many? %>
21
+ <%= render partial: 'fields/active_storage/items',
22
+ locals: {
23
+ field: field,
24
+ variant: field.index_preview_variant,
25
+ size: field.index_preview_size
26
+ } %>
27
+ <% else %>
28
+ <%= render partial: 'fields/active_storage/item',
29
+ locals: {
30
+ field: field,
31
+ attachment: field.data,
32
+ variant: field.index_preview_variant,
33
+ size: field.index_preview_size
34
+ } %>
35
+ <% end %>
31
36
  <% end %>
32
37
 
33
38
  <% if field.index_display_count? %>
34
39
  <div class="attachments-count">
35
- <%= pluralize(field.attachments.count, 'Attachment') %>
40
+ <%= pluralize(field.attachments.count,
41
+ I18n.t("administrate.fields.active_storage.attachment", default: 'Attachment')
42
+ )
43
+ %>
36
44
  </div>
37
45
  <% end %>
38
46
  <% end %>
@@ -36,7 +36,8 @@ controlled via a boolean local variable.
36
36
  <% if field.destroy_url.present? %>
37
37
  <% destroy_url = field.destroy_url.call(namespace, field.data.record, attachment) %>
38
38
  <div>
39
- <%= link_to 'Remove', destroy_url, method: :delete, class: 'remove-attachment-link', data: { confirm: t("administrate.actions.confirm") } %>
39
+ <%= link_to I18n.t("administrate.fields.active_storage.remove", default: 'Remove'),
40
+ destroy_url, method: :delete, class: 'remove-attachment-link', data: { confirm: t("administrate.actions.confirm") } %>
40
41
  </div>
41
42
  <hr>
42
43
  <% end %>
@@ -11,10 +11,16 @@ This partial renders one or more attachments
11
11
  - `removable`:
12
12
  A boolean used to control the display of a `Remove` link which
13
13
  is used to destroy a single attachment. Defaults to `false`
14
+ - `size`:
15
+ [x, y]
16
+ Maximum size of the ActiveStorage preview.
17
+ Defaults to `field.show_preview_size`.
14
18
  %>
15
19
 
16
20
  <%
17
21
  removable = local_assigns.fetch(:removable, false)
22
+ variant = local_assigns.fetch(:variant, field.show_preview_variant)
23
+ size = local_assigns.fetch(:size, field.show_preview_size)
18
24
  %>
19
25
 
20
26
  <% field.attachments.each do |attachment| %>
@@ -24,7 +30,8 @@ This partial renders one or more attachments
24
30
  field: field,
25
31
  attachment: attachment,
26
32
  removable: removable,
27
- size: field.show_preview_size
33
+ variant: variant,
34
+ size: size
28
35
  } %>
29
36
  </div>
30
37
  <% end %>
@@ -1,7 +1,11 @@
1
- <div style="width: <%=size[0]%>px; height: auto; overflow: hidden;">
1
+ <div class="as-field as-field-<%= action_name %>">
2
2
  <% if attachment.image? %>
3
3
  <% if attachment.variable? %>
4
- <%= image_tag(field.variant(attachment, resize_to_limit: size)) %>
4
+ <% if variant.nil? %>
5
+ <%= image_tag(field.variant(attachment, resize_to_limit: size)) %>
6
+ <% else %>
7
+ <%= image_tag(attachment.variant(variant)) %>
8
+ <% end %>
5
9
  <% else %>
6
10
  <%= image_tag(field.url(attachment)) %>
7
11
  <% end %>
@@ -11,9 +15,9 @@
11
15
  poster: field.preview(attachment, resize_to_limit: size),
12
16
  controls: true,
13
17
  autobuffer: true,
14
- style: "object-fit: contain; width: 100%; height: 100%;") %>
18
+ id: "as-field-video-#{attachment.id}") %>
15
19
  <% else %>
16
- <%= video_tag(field.url(attachment), controls: true, autobuffer: true, style: "object-fit: contain; width: 100%; height: 100%;") %>
20
+ <%= video_tag(field.url(attachment), controls: true, autobuffer: true, class: "as-field-video") %>
17
21
  <% end %>
18
22
  <% elsif attachment.audio? %>
19
23
  <%= audio_tag(field.url(attachment), autoplay: false, controls: true) %>
@@ -18,5 +18,5 @@ By default, the attribute is rendered as an image tag.
18
18
  <% if field.attached? %>
19
19
  <%= render partial: 'fields/active_storage/items', locals: { field: field } %>
20
20
  <% else %>
21
- No attachment
21
+ <%= I18n.t("administrate.fields.active_storage.no_attachment", default: 'No attachment') %>
22
22
  <% end %>
@@ -0,0 +1,8 @@
1
+ base_locale: en
2
+
3
+ data:
4
+ read:
5
+ - config/locales/administrate-field-active_storage.%{locale}.yml
6
+
7
+ ignore:
8
+ - 'administrate.actions.*'
@@ -0,0 +1,10 @@
1
+ ---
2
+ en:
3
+ administrate:
4
+ fields:
5
+ active_storage:
6
+ add: Add
7
+ attachment: Attachment
8
+ no_attachment: No attachment
9
+ remove: Remove
10
+ replace: Replace
@@ -0,0 +1,10 @@
1
+ ---
2
+ ru:
3
+ administrate:
4
+ fields:
5
+ active_storage:
6
+ add: Добавить
7
+ attachment: Вложение
8
+ no_attachment: Нет
9
+ remove: Удалить
10
+ replace: Заменить
data/contribute.md CHANGED
@@ -13,3 +13,4 @@
13
13
  - Sébastien Dubois [@sedubois](https://github.com/sedubois)
14
14
  - Jazzy Gasper [@jazzygasper](https://github.com/jazzygasper)
15
15
  - David Ma [@taikon](https://github.com/taikon)
16
+ - Dmitry Davydov [@haukot](https://github.com/haukot)
@@ -5,6 +5,7 @@ module Administrate
5
5
  module Field
6
6
  class ActiveStorage < Administrate::Field::Base
7
7
  class Engine < ::Rails::Engine
8
+ Administrate::Engine.add_stylesheet "administrate-field-active_storage/application"
8
9
  end
9
10
 
10
11
  def index_display_preview?
@@ -15,6 +16,10 @@ module Administrate
15
16
  options.fetch(:index_preview_size, [150, 150])
16
17
  end
17
18
 
19
+ def index_preview_variant
20
+ options.fetch(:index_preview_variant, nil)
21
+ end
22
+
18
23
  def index_display_count?
19
24
  options.fetch(:index_display_count) { attached? && attachments.count != 1 }
20
25
  end
@@ -27,6 +32,10 @@ module Administrate
27
32
  options.fetch(:show_preview_size, [800, 800])
28
33
  end
29
34
 
35
+ def show_preview_variant
36
+ options.fetch(:show_preview_variant, nil)
37
+ end
38
+
30
39
  def many?
31
40
  data.is_a? ::ActiveStorage::Attached::Many
32
41
  end
@@ -70,7 +79,7 @@ module Administrate
70
79
  end
71
80
 
72
81
  def attachments
73
- data.attachments if attached?
82
+ many? ? data.attachments : [data.attachment] if attached?
74
83
  end
75
84
  end
76
85
  end
data/spec/i18n_spec.rb ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'i18n/tasks'
4
+
5
+ # Template i18n-tasks test file from https://github.com/glebm/i18n-tasks/blob/main/templates/rspec/i18n_spec.rb
6
+ RSpec.describe I18n do
7
+ let(:i18n) { I18n::Tasks::BaseTask.new }
8
+ let(:missing_keys) { i18n.missing_keys }
9
+ let(:unused_keys) { i18n.unused_keys }
10
+ let(:inconsistent_interpolations) { i18n.inconsistent_interpolations }
11
+
12
+ it 'does not have missing keys' do
13
+ expect(missing_keys).to be_empty,
14
+ "Missing #{missing_keys.leaves.count} i18n keys, run `i18n-tasks missing' to show them"
15
+ end
16
+
17
+ it 'does not have unused keys' do
18
+ expect(unused_keys).to be_empty,
19
+ "#{unused_keys.leaves.count} unused i18n keys, run `i18n-tasks unused' to show them"
20
+ end
21
+
22
+ it 'files are normalized' do
23
+ non_normalized = i18n.non_normalized_paths
24
+ error_message = "The following files need to be normalized:\n" \
25
+ "#{non_normalized.map { |path| " #{path}" }.join("\n")}\n" \
26
+ "Please run `i18n-tasks normalize' to fix"
27
+ expect(non_normalized).to be_empty, error_message
28
+ end
29
+
30
+ it 'does not have inconsistent interpolations' do
31
+ error_message = "#{inconsistent_interpolations.leaves.count} i18n keys have inconsistent interpolations.\n" \
32
+ "Run `i18n-tasks check-consistent-interpolations' to show them"
33
+ expect(inconsistent_interpolations).to be_empty, error_message
34
+ end
35
+ end
@@ -0,0 +1 @@
1
+ defaults
@@ -0,0 +1,10 @@
1
+ # See https://git-scm.com/docs/gitattributes for more about git attribute files.
2
+
3
+ # Mark the database schema as having been generated.
4
+ db/schema.rb linguist-generated
5
+
6
+ # Mark the yarn lockfile as having been generated.
7
+ yarn.lock linguist-generated
8
+
9
+ # Mark any vendored files as having been vendored.
10
+ vendor/* linguist-vendored
@@ -9,22 +9,24 @@
9
9
 
10
10
  # Ignore the default SQLite database.
11
11
  /db/*.sqlite3
12
- /db/*.sqlite3-journal
12
+ /db/*.sqlite3-*
13
13
 
14
14
  # Ignore all logfiles and tempfiles.
15
15
  /log/*
16
16
  /tmp/*
17
- !/log/.keep
18
- !/tmp/.keep
19
17
 
20
- # Ignore uploaded files in development
18
+ # Ignore uploaded files in development.
21
19
  /storage/*
22
20
 
23
- /node_modules
24
- /yarn-error.log
25
-
26
21
  /public/assets
27
22
  .byebug_history
28
23
 
29
24
  # Ignore master key for decrypting credentials and more.
30
25
  /config/master.key
26
+
27
+ /public/packs
28
+ /public/packs-test
29
+ /node_modules
30
+ /yarn-error.log
31
+ yarn-debug.log*
32
+ .yarn-integrity
@@ -0,0 +1 @@
1
+ ruby-3.0.0