viniBaxter-field-active_storage 0.2.4
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 +7 -0
- data/.gitignore +11 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +166 -0
- data/Rakefile +22 -0
- data/_config.yml +1 -0
- data/app/views/fields/active_storage/_form.html.erb +30 -0
- data/app/views/fields/active_storage/_index.html.erb +32 -0
- data/app/views/fields/active_storage/_item.html.erb +57 -0
- data/app/views/fields/active_storage/_items.html.erb +25 -0
- data/app/views/fields/active_storage/_show.html.erb +20 -0
- data/contribute.md +13 -0
- data/lib/viniBaxter/field/active_storage.rb +72 -0
- data/spec/lib/administrate/field/active_storage_spec.rb +14 -0
- data/viniBaxter-field-active_storage.gemspec +21 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c1ff2205756df8663416ec7f31ea9683b5ccd891678bd69caa625ee86582aaaa
|
4
|
+
data.tar.gz: d299bb0e1dacb5ee7a51140d508758b76b8439b554402842e7cbdba30e9d84a3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1ac5aeab30b570d71724ee54069b0522b6e4dd3a00d8fcd9e733789e54ff9328c10ee8a9b1e92fb1cbdcfe6778b81805329be145b8b20a609b2a43486086c278
|
7
|
+
data.tar.gz: 85c58922bca220c7c074f758bf30a5bdc2224cbec29cea7f9776cef978417ae081eb78351f6c3db21e15bb3bb93619bc716a32bb394d19d3ff1e362c8ae45b1a
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.3
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2008-2017 thoughtbot, inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
# Administrate::Field::ActiveStorage
|
2
|
+

|
3
|
+
|
4
|
+
## Things To Know:
|
5
|
+
- To preview pdf files you need to install `mupdf` or `Poppler`.
|
6
|
+
- To preview video files you need to install `ffmpeg`.
|
7
|
+
- To preview Office files as pictures you need to install [activestorage-office-previewer](https://github.com/basecamp/activestorage-office-previewer) by basecamp
|
8
|
+
|
9
|
+
## How To Use:
|
10
|
+
Add `administrate-field-active_storage` and `mini_magick` to your Gemfile (rails 6):
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'administrate-field-active_storage'
|
14
|
+
gem 'mini_magick'
|
15
|
+
```
|
16
|
+
|
17
|
+
for rails 5.x use the following
|
18
|
+
```ruby
|
19
|
+
gem 'administrate-field-active_storage' -v 0.1.8
|
20
|
+
```
|
21
|
+
|
22
|
+
Install:
|
23
|
+
|
24
|
+
```
|
25
|
+
$ bundle install
|
26
|
+
```
|
27
|
+
|
28
|
+
### `has_one_attached`:
|
29
|
+
Assuming your model name is `Model` and field name is `attachment`
|
30
|
+
```ruby
|
31
|
+
class ModelDashboard < Administrate::BaseDashboard
|
32
|
+
ATTRIBUTE_TYPES = {
|
33
|
+
attachment: Field::ActiveStorage,
|
34
|
+
}
|
35
|
+
# ...
|
36
|
+
```
|
37
|
+
Then add `:attachment` to `FORM_ATTRIBUTES` and `SHOW_PAGE_ATTRIBUTES`.
|
38
|
+
Adding `:attachment` `COLLECTION_ATTRIBUTES` will work but will probably look too big.
|
39
|
+
|
40
|
+
### `has_many_attached`:
|
41
|
+
Assuming your model name is `Model` and field name is `attachments` the process is identical the only issue is that the form field isn't being permitted, in order to permit it we apply the following method to the dashboard:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
class ModelDashboard < Administrate::BaseDashboard
|
45
|
+
ATTRIBUTE_TYPES = {
|
46
|
+
attachments: Field::ActiveStorage,
|
47
|
+
}
|
48
|
+
|
49
|
+
# ...
|
50
|
+
FORM_ATTRIBUTES = {
|
51
|
+
#...
|
52
|
+
:attachments
|
53
|
+
}
|
54
|
+
|
55
|
+
# permitted for has_many_attached
|
56
|
+
def permitted_attributes
|
57
|
+
super + [:attachments => []]
|
58
|
+
end
|
59
|
+
```
|
60
|
+
I know it is not ideal, if you have a workaround please submit a PR.
|
61
|
+
|
62
|
+
### Prevent N+1 queries
|
63
|
+
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
|
+
```ruby
|
65
|
+
module Admin
|
66
|
+
class UsersController < Admin::ApplicationController
|
67
|
+
def scoped_resource
|
68
|
+
resource_class.with_attached_avatars
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
### Removing/Deleting an Attachment
|
76
|
+
In order to allow the user to delete an attachment using the admin dashboard you need to do the following:
|
77
|
+
1. create a controller action with a `delete` route
|
78
|
+
2. point the `Field::ActiveStorage` field to that route
|
79
|
+
|
80
|
+
here is an example (send the route name as a symbol):
|
81
|
+
```ruby
|
82
|
+
class ModelDashboard < Administrate::BaseDashboard
|
83
|
+
ATTRIBUTE_TYPES = {
|
84
|
+
attachment: Field::ActiveStorage.with_options({destroy_path: :custom_active_storage_destroy_path}),
|
85
|
+
}
|
86
|
+
# ...
|
87
|
+
```
|
88
|
+
Your `routes.rb` file must point to a controller action with method `delete` which should contain the following piece of code (you can modify to your own liking).
|
89
|
+
**FOR SECURITY REASONS** please check if the current user is allowed to remove such file
|
90
|
+
```ruby
|
91
|
+
def remove_attachment
|
92
|
+
attachment = ActiveStorage::Attachment.find(params[:attachment_id])
|
93
|
+
attachment.purge
|
94
|
+
redirect_back(fallback_location: "/")
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
### url_only
|
99
|
+
Only the following needs to change in order for the field to be url_only
|
100
|
+
```ruby
|
101
|
+
class ModelDashboard < Administrate::BaseDashboard
|
102
|
+
ATTRIBUTE_TYPES = {
|
103
|
+
attachments: Field::ActiveStorage.with_options({url_only: true}),
|
104
|
+
# ...
|
105
|
+
}
|
106
|
+
# ...
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
### show_in_index
|
111
|
+
This will preview thumbnails in the index page and if you're using `has_many` it will show the first one as a thumbnail and a count of the total attached files
|
112
|
+
```ruby
|
113
|
+
class ModelDashboard < Administrate::BaseDashboard
|
114
|
+
ATTRIBUTE_TYPES = {
|
115
|
+
attachments: Field::ActiveStorage.with_options({show_in_index: true}),
|
116
|
+
# ...
|
117
|
+
}
|
118
|
+
# ...
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
### show_preview_size
|
123
|
+
Supply the size of the image preview inside the show page. Check out the [mini_magic#resize_to_limit](https://github.com/janko/image_processing/blob/master/doc/minimagick.md#methods) documentation
|
124
|
+
```ruby
|
125
|
+
class ModelDashboard < Administrate::BaseDashboard
|
126
|
+
ATTRIBUTE_TYPES = {
|
127
|
+
attachments: Field::ActiveStorage.with_options({show_preview_size: [150, 200]}),
|
128
|
+
# ...
|
129
|
+
}
|
130
|
+
# ...
|
131
|
+
end
|
132
|
+
```
|
133
|
+
|
134
|
+
### direct_upload
|
135
|
+
If you want to upload directly from the browser to the cloud you can use direct_upload
|
136
|
+
```ruby
|
137
|
+
class ModelDashboard < Administrate::BaseDashboard
|
138
|
+
ATTRIBUTE_TYPES = {
|
139
|
+
attachments: Field::ActiveStorage.with_options({direct_upload: true}),
|
140
|
+
# ...
|
141
|
+
}
|
142
|
+
# ...
|
143
|
+
end
|
144
|
+
```
|
145
|
+
|
146
|
+
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.
|
147
|
+
|
148
|
+
## Things To Do:
|
149
|
+
- [x] upload single file
|
150
|
+
- [x] adding image support through url_for to support 3rd party cloud storage
|
151
|
+
- [x] use html 5 video element for video files
|
152
|
+
- [x] use html audio element for audio files
|
153
|
+
- [x] download link to other files
|
154
|
+
- [x] preview videos
|
155
|
+
- [x] preview pdfs
|
156
|
+
- [x] upload multiple files
|
157
|
+
- [x] find a way to delete attachments
|
158
|
+
- [x] preview office files as pictures
|
159
|
+
|
160
|
+
## Contribution Guide:
|
161
|
+
1. contributers are welcome (code, suggestions, and bugs).
|
162
|
+
2. please document your code.
|
163
|
+
3. add your name to the `contribute.md`.
|
164
|
+
|
165
|
+
---
|
166
|
+
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).
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "bundler/setup"
|
5
|
+
rescue LoadError
|
6
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
7
|
+
end
|
8
|
+
|
9
|
+
require "bundler/gem_tasks"
|
10
|
+
|
11
|
+
##
|
12
|
+
# Configure the test suite.
|
13
|
+
##
|
14
|
+
require "rspec/core"
|
15
|
+
require "rspec/core/rake_task"
|
16
|
+
|
17
|
+
RSpec::Core::RakeTask.new
|
18
|
+
|
19
|
+
##
|
20
|
+
# By default, just run the tests.
|
21
|
+
##
|
22
|
+
task default: :spec
|
data/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
theme: jekyll-theme-minimal
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<%#
|
2
|
+
# Image Form Partial
|
3
|
+
|
4
|
+
This partial renders an input element for image attributes.
|
5
|
+
By default, the input is a text field for the image's URL.
|
6
|
+
|
7
|
+
## Local variables:
|
8
|
+
|
9
|
+
- `f`:
|
10
|
+
A Rails form generator, used to help create the appropriate input fields.
|
11
|
+
- `field`:
|
12
|
+
An instance of [Administrate::Field::Image][1].
|
13
|
+
A wrapper around the image url pulled from the database.
|
14
|
+
|
15
|
+
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Image
|
16
|
+
%>
|
17
|
+
|
18
|
+
<div class="field-unit__label">
|
19
|
+
<%= f.label field.attribute %>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<div class="field-unit__field">
|
23
|
+
<% if field.data.present? && field.attached? %>
|
24
|
+
<%= render partial: 'fields/active_storage/items', locals: { field: field, removable: field.destroyable? } %>
|
25
|
+
<br />
|
26
|
+
Add:
|
27
|
+
<% end %>
|
28
|
+
|
29
|
+
<%= f.file_field field.attribute, multiple: field.many?, direct_upload: field.direct? %>
|
30
|
+
</div>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<%#
|
2
|
+
# Image Index Partial
|
3
|
+
|
4
|
+
This partial renders an image attribute
|
5
|
+
to be displayed on a resource's index page.
|
6
|
+
|
7
|
+
By default, the attribute is rendered as an image tag.
|
8
|
+
|
9
|
+
## Local variables:
|
10
|
+
|
11
|
+
- `field`:
|
12
|
+
An instance of [Administrate::Field::Image][1].
|
13
|
+
A wrapper around the image url pulled from the database.
|
14
|
+
|
15
|
+
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Image
|
16
|
+
%>
|
17
|
+
<style> <%# figure out a way to remove this %>
|
18
|
+
td img {
|
19
|
+
max-height: unset !important;
|
20
|
+
}
|
21
|
+
</style>
|
22
|
+
<%
|
23
|
+
attachments = Array(field.many? ? field.attachments : field.data)
|
24
|
+
%>
|
25
|
+
<% if field.attached? %>
|
26
|
+
<% if field.show_in_index? %>
|
27
|
+
<%= render partial: 'fields/active_storage/item', locals: { field: field, attachment: attachments[0], image_size: [50, 50] } %>
|
28
|
+
<% end %>
|
29
|
+
<% pluralize(attachments.count, 'Attached file') %>
|
30
|
+
<% else %>
|
31
|
+
0 Attached files
|
32
|
+
<% end %>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
<%#
|
2
|
+
# Item Partial
|
3
|
+
|
4
|
+
This partial renders attached items.
|
5
|
+
|
6
|
+
Attachments of type image, video and audio are emedded. For all other types
|
7
|
+
we try use it's preview. If all else fails we simply link to the attached file.
|
8
|
+
|
9
|
+
This partial will optionally show a `remove` link next to each attachment which is
|
10
|
+
controlled via a boolean local variable.
|
11
|
+
|
12
|
+
## Local variables:
|
13
|
+
|
14
|
+
- `field`:
|
15
|
+
An instance of [Administrate::Field::Image].
|
16
|
+
A wrapper around the image url pulled from the database.
|
17
|
+
- `attachment`:
|
18
|
+
Reference to the file
|
19
|
+
- `removable`:
|
20
|
+
A boolean used to control the display of a `Remove` link which
|
21
|
+
is used to destroy a single attachment. Defaults to `false`
|
22
|
+
%>
|
23
|
+
|
24
|
+
<%
|
25
|
+
# By default we don't allow attachment removal
|
26
|
+
removable = local_assigns.fetch(:removable, false)
|
27
|
+
image_size = local_assigns.fetch(:image_size, [1920, 1080])
|
28
|
+
%>
|
29
|
+
|
30
|
+
<% if attachment.image? and attachment.variable? and !field.url_only? %>
|
31
|
+
<%= link_to(field.blob_url(attachment), title: attachment.filename) do %>
|
32
|
+
<%= image_tag(field.variant(attachment, resize_to_limit: image_size)) %>
|
33
|
+
<% end %>
|
34
|
+
<% elsif attachment.image? and !field.url_only? %>
|
35
|
+
<%= link_to(field.blob_url(attachment), title: attachment.filename) do %>
|
36
|
+
<%= image_tag(field.url(attachment)) %>
|
37
|
+
<% end %>
|
38
|
+
<% elsif attachment.video? and attachment.previewable? and !field.url_only? %> <%# if ffmpeg is installed %>
|
39
|
+
<%= video_tag(field.url(attachment), poster: field.preview(attachment, resize_to_limit: image_size), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
|
40
|
+
<% elsif attachment.video? and !field.url_only? %>
|
41
|
+
<%= video_tag(field.url(attachment), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
|
42
|
+
<% elsif attachment.audio? and !field.url_only? %>
|
43
|
+
<%= audio_tag(field.url(attachment), autoplay: false, controls: true) %>
|
44
|
+
<% else %>
|
45
|
+
<%= link_to(field.blob_url(attachment), title: attachment.filename) do %>
|
46
|
+
<% if attachment.previewable? and !field.url_only? %>
|
47
|
+
<%= image_tag(field.preview(attachment, resize_to_limit: [595, 842])) %>
|
48
|
+
<% else %>
|
49
|
+
<%= attachment.filename %>
|
50
|
+
<% end %>
|
51
|
+
<% end %>
|
52
|
+
<% end %>
|
53
|
+
|
54
|
+
<% if removable %>
|
55
|
+
<%= link_to 'Remove', field.destroy_path(field, attachment), method: :delete, class: 'remove-attachment-link' %>
|
56
|
+
<hr>
|
57
|
+
<% end %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<%#
|
2
|
+
# Items Partial
|
3
|
+
|
4
|
+
This partial renders one or more attachments
|
5
|
+
|
6
|
+
## Local variables:
|
7
|
+
|
8
|
+
- `field`:
|
9
|
+
An instance of [Administrate::Field::Image].
|
10
|
+
A wrapper around the image url pulled from the database.
|
11
|
+
- `removable`:
|
12
|
+
A boolean used to control the display of a `Remove` link which
|
13
|
+
is used to destroy a single attachment. Defaults to `false`
|
14
|
+
%>
|
15
|
+
|
16
|
+
<%
|
17
|
+
attachments = Array(field.many? ? field.attachments : field.data)
|
18
|
+
removable = local_assigns.fetch(:removable, false)
|
19
|
+
%>
|
20
|
+
|
21
|
+
<% attachments.each do |attachment| %>
|
22
|
+
<div class="attachments-listing">
|
23
|
+
<%= render partial: 'fields/active_storage/item', locals: { field: field, attachment: attachment, removable: removable, image_size: field.show_preview_size } %>
|
24
|
+
</div>
|
25
|
+
<% end %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<%#
|
2
|
+
# Image Show Partial
|
3
|
+
|
4
|
+
This partial renders an image attribute,
|
5
|
+
to be displayed on a resource's show page.
|
6
|
+
|
7
|
+
By default, the attribute is rendered as an image tag.
|
8
|
+
|
9
|
+
## Local variables:
|
10
|
+
|
11
|
+
- `field`:
|
12
|
+
An instance of [Administrate::Field::Image][1].
|
13
|
+
A wrapper around the image url pulled from the database.
|
14
|
+
|
15
|
+
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Image
|
16
|
+
%>
|
17
|
+
|
18
|
+
<% if field.attached? %>
|
19
|
+
<%= render partial: 'fields/active_storage/items', locals: { field: field } %>
|
20
|
+
<% end %>
|
data/contribute.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributors
|
2
|
+
|
3
|
+
- Patrick Gleeson [@patrick-gleeson](https://github.com/patrick-gleeson)
|
4
|
+
- Mario Zigliotto [@mariozig](https://github.com/mariozig)
|
5
|
+
- Leif Gensert [@leifg](https://github.com/leifg)
|
6
|
+
- Kadu Diógenes [@cerdiogenes](https://github.com/cerdiogenes)
|
7
|
+
- Peter Bhat Harkins [@pushcx](https://github.com/pushcx)
|
8
|
+
- Delta Purna Widyangga [@deltapurna](https://github.com/deltapurna)
|
9
|
+
- Joé Dupuis [@twistedjoe](https://github.com/twistedjoe)
|
10
|
+
- Eugeny Khlopin [@evgeniy-khlopin](https://github.com/evgeniy-khlopin)
|
11
|
+
- Daniel Tinoco [@0urobor0s](https://github.com/0urobor0s)
|
12
|
+
- Matthew Hui [@mhui](https://github.com/mhui)
|
13
|
+
- Sébastien Dubois [@sedubois](https://github.com/sedubois)
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'administrate/field/base'
|
2
|
+
require 'rails'
|
3
|
+
|
4
|
+
module Administrate
|
5
|
+
module Field
|
6
|
+
class ActiveStorage < Administrate::Field::Base
|
7
|
+
class Engine < ::Rails::Engine
|
8
|
+
end
|
9
|
+
|
10
|
+
def url_only?
|
11
|
+
options.fetch(:url_only, false)
|
12
|
+
end
|
13
|
+
|
14
|
+
def destroyable?
|
15
|
+
options.key?(:destroy_path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def show_in_index?
|
19
|
+
options.fetch(:show_in_index, false)
|
20
|
+
end
|
21
|
+
|
22
|
+
def show_preview_size
|
23
|
+
options.fetch(:show_preview_size, [1080, 1920])
|
24
|
+
end
|
25
|
+
|
26
|
+
def many?
|
27
|
+
# find a way to use instance_of
|
28
|
+
data.class.name == 'ActiveStorage::Attached::Many'
|
29
|
+
end
|
30
|
+
|
31
|
+
def direct?
|
32
|
+
options.fetch(:direct_upload, false)
|
33
|
+
end
|
34
|
+
|
35
|
+
# def destroy_path?
|
36
|
+
# options.fetch(:destroy_path, false).present?
|
37
|
+
# end
|
38
|
+
|
39
|
+
# currently we are using Rails.application.routes.url_helpers
|
40
|
+
# without including the namespace because it runs into an
|
41
|
+
# exception
|
42
|
+
|
43
|
+
# work around since calling data.preview(options)
|
44
|
+
# returns "/images/<ActiveStorage::Preview>" which isnt the url
|
45
|
+
def preview(attachment, options)
|
46
|
+
Rails.application.routes.url_helpers.rails_representation_path(attachment.preview(options), only_path: true)
|
47
|
+
end
|
48
|
+
|
49
|
+
def variant(attachment, options)
|
50
|
+
Rails.application.routes.url_helpers.rails_representation_path(attachment.variant(combine_options: options), only_path: true)
|
51
|
+
end
|
52
|
+
|
53
|
+
def url(attachment)
|
54
|
+
Rails.application.routes.url_helpers.rails_blob_path(attachment, only_path: true)
|
55
|
+
end
|
56
|
+
|
57
|
+
def blob_url(attachment)
|
58
|
+
Rails.application.routes.url_helpers.rails_blob_path(attachment, disposition: :attachment, only_path: true)
|
59
|
+
end
|
60
|
+
|
61
|
+
def destroy_path(field, attachment)
|
62
|
+
destroy_path_helper = options.fetch(:destroy_path)
|
63
|
+
record_id = field.data.record.id
|
64
|
+
attachment_id = attachment.id
|
65
|
+
Rails.application.routes.url_helpers.send(destroy_path_helper, {:record_id => record_id, :attachment_id => attachment_id})
|
66
|
+
end
|
67
|
+
|
68
|
+
delegate :attached?, to: :data
|
69
|
+
delegate :attachments, to: :data
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "administrate/field/active_storage"
|
2
|
+
|
3
|
+
describe Administrate::Field::ActiveStorage do
|
4
|
+
describe "#to_partial_path" do
|
5
|
+
it "returns a partial based on the page being rendered" do
|
6
|
+
page = :show
|
7
|
+
field = Administrate::Field::ActiveStorage.new(:image, "/a.jpg", page)
|
8
|
+
|
9
|
+
path = field.to_partial_path
|
10
|
+
|
11
|
+
expect(path).to eq("/fields/active_storage/#{page}")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "viniBaxter-field-active_storage"
|
5
|
+
gem.version = "0.2.4"
|
6
|
+
gem.authors = ["viny baxter"]
|
7
|
+
gem.email = ["vincent.viricel@gmail.com"]
|
8
|
+
gem.homepage = "https://github.com/Dreamersoul/administrate-field-active_storage"
|
9
|
+
gem.summary = "Administrate fields for active storage"
|
10
|
+
gem.description = gem.summary
|
11
|
+
gem.license = "MIT"
|
12
|
+
|
13
|
+
gem.require_paths = ["lib"]
|
14
|
+
gem.files = `git ls-files`.split("\n")
|
15
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
|
17
|
+
gem.add_dependency "administrate", ">= 0.2.3"
|
18
|
+
gem.add_dependency "rails", ">= 6.0.2.2"
|
19
|
+
|
20
|
+
gem.add_development_dependency "rspec", "~> 3.4"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: viniBaxter-field-active_storage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- viny baxter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: administrate
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 6.0.2.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 6.0.2.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.4'
|
55
|
+
description: Administrate fields for active storage
|
56
|
+
email:
|
57
|
+
- vincent.viricel@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".ruby-version"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- _config.yml
|
69
|
+
- app/views/fields/active_storage/_form.html.erb
|
70
|
+
- app/views/fields/active_storage/_index.html.erb
|
71
|
+
- app/views/fields/active_storage/_item.html.erb
|
72
|
+
- app/views/fields/active_storage/_items.html.erb
|
73
|
+
- app/views/fields/active_storage/_show.html.erb
|
74
|
+
- contribute.md
|
75
|
+
- lib/viniBaxter/field/active_storage.rb
|
76
|
+
- spec/lib/administrate/field/active_storage_spec.rb
|
77
|
+
- viniBaxter-field-active_storage.gemspec
|
78
|
+
homepage: https://github.com/Dreamersoul/administrate-field-active_storage
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubygems_version: 3.0.3
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Administrate fields for active storage
|
101
|
+
test_files:
|
102
|
+
- spec/lib/administrate/field/active_storage_spec.rb
|