trestle-active_storage 0.0.1.pre.12 → 0.0.1
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/README.md +7 -1
- data/lib/trestle/active_storage/builder.rb +1 -1
- data/lib/trestle/active_storage/controller_concern.rb +9 -27
- data/lib/trestle/active_storage/engine.rb +1 -1
- data/lib/trestle/active_storage/resource.rb +18 -6
- data/lib/trestle/active_storage/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50cc7a1ff90ab38d8f8abc8b2586447a41431f537d87686e1f21ca0f2bd7e44c
|
4
|
+
data.tar.gz: a44acd224be364941ea78a69ba53288ab24e5e0b2bd838f6c55becab2ff3592d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 170ed9f8a485d885cc1fa4c7682e7865e18cfc8ee4cfcf26b4a9417c8773436deb52012ad0079e54f68fa501eb304da8e148a3131fdde3777c3ac433d4b6d643
|
7
|
+
data.tar.gz: 7020a30b055329ed3ff6ee3cc963b3edb6d458defc49f6e538312332d2bb79be8a1872095064ce4fc3e9d1b0ae61c35bb7be0cca13ffbadfb6b663427e6ae815
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Trestle ActiveStorage Integration (trestle-active_storage)
|
2
2
|
|
3
|
-
> [ActiveStorage](https://github.com/rails/rails/tree/master/activestorage) integration plugin for the Trestle admin framework
|
3
|
+
> [ActiveStorage](https://github.com/rails/rails/tree/master/activestorage#active-storage) integration plugin for the [Trestle admin framework](https://trestle.io)
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
@@ -31,6 +31,12 @@ gem 'trestle-active_storage'
|
|
31
31
|
|
32
32
|
Run `bundle install`, and then restart your Rails server.
|
33
33
|
|
34
|
+
## Wishlist
|
35
|
+
|
36
|
+
- [ ] Support for `has_many_attached` attachments
|
37
|
+
- [ ] Support for [ActiveStorage previews](https://api.rubyonrails.org/v5.2/classes/ActiveStorage/Previewer.html)
|
38
|
+
- [ ] Integration tests
|
39
|
+
|
34
40
|
## License
|
35
41
|
|
36
42
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -5,41 +5,23 @@ module Trestle
|
|
5
5
|
|
6
6
|
included do
|
7
7
|
before_action :define_attachment_accessors, only: [:show, :edit, :update, :destroy]
|
8
|
-
before_action :delete_attachment_params, only: [:create, :update]
|
9
|
-
before_action :attach_attachments, only: [:create, :update]
|
10
8
|
after_action :purge_attachments, only: [:update]
|
11
9
|
end
|
12
10
|
|
13
|
-
|
11
|
+
private
|
12
|
+
def define_attachment_accessors
|
13
|
+
self.instance = admin.find_instance(params)
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
admin.active_storage_fields.each do |field|
|
19
|
-
instance.class.send(:attr_accessor, "delete_#{field}")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def delete_attachment_params
|
24
|
-
admin.active_storage_fields.each { |field| params.delete(field) }
|
25
|
-
end
|
26
|
-
|
27
|
-
def attach_attachments
|
28
|
-
instance = admin.build_instance(permitted_params, params)
|
29
|
-
instance_params = admin.permitted_params(params)
|
30
|
-
|
31
|
-
admin.active_storage_fields.each do |field|
|
32
|
-
if instance_params[field].present?
|
33
|
-
instance.send(field).attach instance_params[field]
|
15
|
+
admin.active_storage_fields.each do |field|
|
16
|
+
instance.class.send(:attr_accessor, "delete_#{field}")
|
34
17
|
end
|
35
18
|
end
|
36
|
-
end
|
37
19
|
|
38
|
-
|
39
|
-
|
40
|
-
|
20
|
+
def purge_attachments
|
21
|
+
admin.active_storage_fields.each do |field|
|
22
|
+
instance.send(field).purge if instance.try("delete_#{field}") == '1'
|
23
|
+
end
|
41
24
|
end
|
42
|
-
end
|
43
25
|
end
|
44
26
|
end
|
45
27
|
end
|
@@ -4,7 +4,7 @@ module Trestle
|
|
4
4
|
config.assets.precompile << 'activestorage.js' << 'trestle/active_storage_fields.js'
|
5
5
|
|
6
6
|
initializer :extensions do
|
7
|
-
Trestle::Resource.
|
7
|
+
Trestle::Resource.send(:include, Trestle::ActiveStorage::Resource)
|
8
8
|
Trestle::Resource::Builder.send(:include, Trestle::ActiveStorage::Builder)
|
9
9
|
Trestle::Resource::Controller.send(:include, Trestle::ActiveStorage::ControllerConcern)
|
10
10
|
end
|
@@ -1,13 +1,25 @@
|
|
1
1
|
module Trestle
|
2
2
|
module ActiveStorage
|
3
3
|
module Resource
|
4
|
-
|
4
|
+
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
included do
|
7
|
+
singleton_class.send(:prepend, Collection)
|
8
|
+
end
|
9
|
+
|
10
|
+
module Collection
|
11
|
+
def active_storage_fields
|
12
|
+
if active_storage_attachable?
|
13
|
+
adapter.active_storage_fields
|
14
|
+
else
|
15
|
+
[]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
def active_storage_attachable?
|
22
|
+
adapter.respond_to?(:active_storage_fields)
|
11
23
|
end
|
12
24
|
end
|
13
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trestle-active_storage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
4
|
+
version: 0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Venneman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -81,9 +81,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
81
|
version: '0'
|
82
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
|
-
- - "
|
84
|
+
- - ">="
|
85
85
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
86
|
+
version: '0'
|
87
87
|
requirements: []
|
88
88
|
rubyforge_project:
|
89
89
|
rubygems_version: 2.7.3
|