trestle-active_storage 0.0.1.pre

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a5b3855fce2dd9e8a24d802e0cc24a5c5dbf6e3e03f264f9bf1b0f9f81a747d0
4
+ data.tar.gz: ab35d5f69c6bdee1173791cd2e830a5eb18eb9db60fa1f57f9c033244230c6bb
5
+ SHA512:
6
+ metadata.gz: 26b0b26dbb1d88b8e2282a62d7f36c3f768cd3b87e69fedc3a7d33621c5098a4f1898adefd6a0b6f457a8bf9d76759156fc9c31210c8db27552f9666997bd885
7
+ data.tar.gz: fcfca0545c41d0ae9c7d3627f4deb20e1bc47e887b1c9ae93d5ef3d6b29c3d03a2fb0a1ea3762a989ab7f4bba406e65d6ed5a4bffe3e766ef52508c8893facee
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Richard Venneman
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Trestle ActiveStorage Integration (trestle-active_storage)
2
+
3
+ > [ActiveStorage](https://github.com/rails/rails/tree/master/activestorage) integration plugin for the Trestle admin framework
4
+
5
+ ## Usage
6
+
7
+ Define the active storage fields in your Trestle resource and use the `active_storage_field` field type:
8
+
9
+ ```ruby
10
+ Trestle.resource(:users) do
11
+ active_storage_fields do
12
+ [:avatar, :profile_picture]
13
+ end
14
+
15
+ form do |user|
16
+ text_field :first_name
17
+ text_field :last_name
18
+ active_storage_field :avatar
19
+ active_storage_field :profile_picture
20
+ end
21
+ end
22
+ ```
23
+
24
+ ## Installation
25
+
26
+ These instructions assume you have a working Trestle application. To integrate trestle-active_storage, first add it to your application's Gemfile:
27
+
28
+ ```ruby
29
+ gem 'trestle-active_storage'
30
+ ```
31
+
32
+ Run `bundle install`, and then restart your Rails server.
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Trestle::ActiveStorage'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+
33
+ task default: :test
@@ -0,0 +1,26 @@
1
+ Trestle.ready(function() {
2
+ function init() {
3
+ var fields = document.querySelectorAll(".active-storage__field");
4
+
5
+ for (var i = 0; i < fields.length; i++) {
6
+ attachEvents(fields[i]);
7
+ }
8
+ }
9
+
10
+ function attachEvents(field) {
11
+ var progressEl = field.parentNode.querySelectorAll(".progress")[0];
12
+ var progressBarEl = field.parentNode.querySelectorAll(".progress-bar")[0];
13
+
14
+ field.addEventListener("direct-upload:start", function(event) {
15
+ var detail = event.detail;
16
+ progressEl.style = "display: block";
17
+ });
18
+
19
+ field.addEventListener("direct-upload:progress", function(event) {
20
+ var detail = event.detail;
21
+ progressBarEl.style = "width: " + detail.progress + "%";
22
+ });
23
+ }
24
+
25
+ init();
26
+ });
@@ -0,0 +1,20 @@
1
+ <div class="active-storage">
2
+ <% if attachment.attached? %>
3
+ <div class="active-storage__preview">
4
+ <% if attachment.blob.image? %>
5
+ <%= link_to image_tag(attachment.blob.service_url, class: 'active-storage__image'),
6
+ attachment.blob.service_url, target: 'blank' %>
7
+ <% else %>
8
+ <%= link_to(attachment.blob.service_url, class: 'active-storage__link') %>
9
+ <% end %>
10
+ </div>
11
+
12
+ <%= builder.check_box("delete_#{field_name}", label: "Delete #{field_name}") %>
13
+ <% end %>
14
+
15
+ <div class="progress" style="display: none">
16
+ <div class="progress-bar progress-bar-striped active"></div>
17
+ </div>
18
+
19
+ <%= builder.raw_file_field(field_name, class: 'active-storage__field', direct_upload: true) %>
20
+ </div>
@@ -0,0 +1,10 @@
1
+ require 'trestle/active_storage/field'
2
+
3
+ Trestle.configure do |config|
4
+ config.hook(:javascripts) do
5
+ javascript_include_tag('activestorage') +
6
+ javascript_include_tag('trestle/active_storage_fields.js')
7
+ end
8
+
9
+ config.form_field :active_storage_field, Trestle::ActiveStorage::Field
10
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Trestle::Engine.routes.draw do
2
+ post '/active_storage/direct_uploads' => 'active_storage/direct_uploads#create', as: :rails_direct_uploads
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :trestle_active_storage do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,9 @@
1
+ module Trestle
2
+ module ActiveStorage
3
+ module Builder
4
+ def active_storage_fields(&block)
5
+ admin.active_storage_fields = block
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,44 @@
1
+ module Trestle
2
+ module ActiveStorage
3
+ module ControllerConcern
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before_action :delete_attachment_params, only: [:create, :update]
8
+ before_action :define_attachment_accessors, only: [:edit, :update]
9
+ after_action :set_attachments, only: %i[create update]
10
+ after_action :delete_attachments, only: %i[update]
11
+ end
12
+
13
+ protected
14
+
15
+ def delete_attachment_params
16
+ admin.active_storage_fields.each { |field| params.delete(field) }
17
+ end
18
+
19
+ def define_attachment_accessors
20
+ self.instance = admin.find_instance(params)
21
+
22
+ admin.active_storage_fields.each do |field|
23
+ instance.class.send(:attr_accessor, "delete_#{field}")
24
+ end
25
+ end
26
+
27
+ def set_attachments
28
+ instance_params = admin.permitted_params(params)
29
+
30
+ admin.active_storage_fields.each do |field|
31
+ if instance_params[field].present?
32
+ instance.send(field).attach instance_params[field]
33
+ end
34
+ end
35
+ end
36
+
37
+ def delete_attachments
38
+ admin.active_storage_fields.each do |field|
39
+ instance.send(field).purge if instance.try("delete_#{field}") == '1'
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,13 @@
1
+ module Trestle
2
+ module ActiveStorage
3
+ class Engine < Rails::Engine
4
+ config.assets.precompile << 'activestorage.js' << 'trestle/active_storage_fields.js'
5
+
6
+ initializer :extensions do
7
+ Trestle::Resource.singleton_class.send(:prepend, Trestle::ActiveStorage::Resource)
8
+ Trestle::Resource::Builder.send(:include, Trestle::ActiveStorage::Builder)
9
+ Trestle::Resource::Controller.send(:include, Trestle::ActiveStorage::ControllerConcern)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module Trestle
2
+ module ActiveStorage
3
+ class Field < Trestle::Form::Field
4
+ def field
5
+ instance = builder.object
6
+ attachment = instance.send(name)
7
+
8
+ @template.render partial: 'trestle/active_storage/field',
9
+ locals: {
10
+ builder: builder,
11
+ field_name: name,
12
+ attachment: attachment
13
+ }
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module Trestle
2
+ module ActiveStorage
3
+ module Resource
4
+ attr_writer :active_storage_fields
5
+
6
+ def active_storage_fields
7
+ instance_exec(&@active_storage_fields)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Trestle
2
+ module ActiveStorage
3
+ VERSION = '0.0.1.pre'
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ require 'trestle/active_storage/version'
2
+ require 'trestle'
3
+
4
+ module Trestle
5
+ module ActiveStorage
6
+ extend ActiveSupport::Autoload
7
+
8
+ autoload :Builder
9
+ autoload :ControllerConcern
10
+ autoload :Resource
11
+ end
12
+ end
13
+
14
+ require 'trestle/active_storage/engine' if defined?(Rails)
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trestle-active_storage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ platform: ruby
6
+ authors:
7
+ - Richard Venneman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.0.beta2
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 5.2.0.beta2
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6'
33
+ - !ruby/object:Gem::Dependency
34
+ name: trestle
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.8'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.8'
47
+ description: ActiveStorage integration plugin for the Trestle admin framework.
48
+ email:
49
+ - richardvenneman@me.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - MIT-LICENSE
55
+ - README.md
56
+ - Rakefile
57
+ - app/assets/javascripts/trestle/active_storage_fields.js
58
+ - app/views/trestle/active_storage/_field.html.erb
59
+ - config/initializers/trestle.rb
60
+ - config/routes.rb
61
+ - lib/tasks/trestle/active_storage_tasks.rake
62
+ - lib/trestle/active_storage.rb
63
+ - lib/trestle/active_storage/builder.rb
64
+ - lib/trestle/active_storage/controller_concern.rb
65
+ - lib/trestle/active_storage/engine.rb
66
+ - lib/trestle/active_storage/field.rb
67
+ - lib/trestle/active_storage/resource.rb
68
+ - lib/trestle/active_storage/version.rb
69
+ homepage: https://github.com/richardvenneman/trestle-active_storage
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">"
85
+ - !ruby/object:Gem::Version
86
+ version: 1.3.1
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.7.3
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: ActiveStorage integration plugin for the Trestle admin framework
93
+ test_files: []