worker-field-active_storage 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 93a96697730a7bffc56e57c997050e7b98d1a66abb505bdd3645ade27e19deb1
4
+ data.tar.gz: 228c506aa65694c5ab1e541d052780ef3eed886e0eeb9e5de334ce0951f1ca25
5
+ SHA512:
6
+ metadata.gz: 578f4b8eb1c7460789eb6126f468cd6d5a1ccd2a7666989c6336baed6e78251fbbf857cc3ff2b74e24083ca80ab893e12c8aa4520241c79c88aea4f2efead8ae
7
+ data.tar.gz: 7ed138e07a448aa97e0bedf2a0424f81ced3d7ef014a800898c796d9aef67e2a78b7dddbe7b0fe050008d04ee4d911374fe78586d678fc272d688d6bce03759c
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
11
+ .DS_Store
@@ -0,0 +1 @@
1
+ ruby-2.5.3
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -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.
@@ -0,0 +1,51 @@
1
+ # Gem from original
2
+ Huge thanks @Dreamersoul
3
+ source from administrate-field-active_storage,
4
+ [administrate-field-active_storage](https://github.com/Dreamersoul/administrate-field-active_storage)
5
+
6
+ build by Hamad AlGhanim,
7
+ [Dreamersoul](https://github.com/Dreamersoul)
8
+
9
+ I did that version cause i'm working on front with that Gem.
10
+ Once all fixed, il will propose a PR to the original version.
11
+
12
+
13
+ # Worker::Field::ActiveStorage
14
+
15
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/worker/field/active_storage`. To experiment with that code, run `bin/console` for an interactive prompt.
16
+
17
+ TODO: Delete this and the text above, and describe your gem
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'worker-field-active_storage'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install worker-field-active_storage
34
+
35
+ ## Usage
36
+
37
+ TODO: Write usage instructions here
38
+
39
+ ## Development
40
+
41
+ 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.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/worker-field-active_storage.
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,62 @@
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="active__storage__admin">
23
+ <div class="field-unit__field">
24
+ <div class="field-unit__field__picture">
25
+ <% if field.attached? %>
26
+ <%= render partial: 'fields/active_storage/items', locals: { field: field, removable: field.destroyable? } %>
27
+ <% end %>
28
+ </div>
29
+ <div class="fileinput fileinput-new text-center" data-provides="fileinput">
30
+
31
+ <div class="fileinput-preview fileinput-exists thumbnail"></div>
32
+ <div>
33
+ <!-- <span class=" btn-simple btn btn-rework btn-round btn-file">
34
+ <span for="file-input" class="fileinput-new">Select image</span>
35
+ <span class="fileinput-exists">Change</span>
36
+ <input type="file" name="..." />
37
+ </span> -->
38
+
39
+
40
+
41
+ <div class="fileinput fileinput-new text-center" data-provides="fileinput">
42
+ <div class="fileinput-preview fileinput-exists thumbnail"></div>
43
+ <div>
44
+ <span class="btn-whithe btn-file" style="width:200px;">
45
+ <div class="fileinput-new thumbnail">
46
+ <%= image_tag "image_placeholder.jpg" %>
47
+ <!-- <img src="../../assets/img/image_placeholder.jpg" alt="..."> -->
48
+ </div>
49
+ <!-- <span class="fileinput-new">Select image</span> -->
50
+ <!-- <span for="file-input" class="fileinput-new">Select image</span>
51
+ <span class="fileinput-exists">Change</span>
52
+ <input type="file" name="..."> -->
53
+ <%= f.file_field field.attribute, multiple: field.many?, direct_upload: field.direct? %>
54
+ </span>
55
+ <!-- <a href="#pablo" class="btn btn-danger btn-round fileinput-exists" data-dismiss="fileinput"><i class="fa fa-times"></i> Remove</a> -->
56
+ </div>
57
+ </div>
58
+ </div>
59
+ </div>
60
+
61
+ </div>
62
+ </div>
@@ -0,0 +1,33 @@
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
+ <%
18
+ attachments = Array(field.many? ? field.attachments : field.data)
19
+ %>
20
+
21
+ <% if field.attached? %>
22
+
23
+ <% if attachments.count > 1 %>
24
+ <%= pluralize(attachments.count, 'Attached file') %>
25
+ <% else %>
26
+ <% field.attachments.each do |attachment| %>
27
+ <%= render :partial => 'fields/active_storage/item_index', locals: { field: field, attachment: attachment } %>
28
+ <br/>
29
+ <% end %>
30
+ <% end %>
31
+ <% else %>
32
+ 0 Attached files
33
+ <% end %>
@@ -0,0 +1,48 @@
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
+ %>
28
+
29
+ <% if attachment.image? and !field.url_only? %>
30
+ <%= image_tag(field.url(attachment)) %>
31
+ <% elsif attachment.video? and attachment.previewable? and !field.url_only? %> <%# if ffmpeg is installed %>
32
+ <%= video_tag(field.url(attachment), poster: field.preview(attachment, resize: "1920x1080>"), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
33
+ <% elsif attachment.video? and !field.url_only? %>
34
+ <%= video_tag(field.url(attachment), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
35
+ <% elsif attachment.audio? and !field.url_only? %>
36
+ <%= audio_tag(field.url(attachment), autoplay: false, controls: true) %>
37
+ <% elsif attachment.previewable? and !field.url_only? %>
38
+ <%= image_tag(field.preview(attachment, resize: "595x842>")) %>
39
+ <br/>
40
+ Download: <%= link_to(attachment.filename, field.blob_url(attachment)) %>
41
+ <% else %>
42
+ <%= link_to(attachment.filename, field.blob_url(attachment)) %>
43
+ <% end %>
44
+
45
+ <% if removable %>
46
+ <%= link_to 'Remove', field.destroy_path(field, attachment), method: :delete, class: 'remove-attachment-link' %>
47
+ <hr>
48
+ <% end %>
@@ -0,0 +1,48 @@
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
+ %>
28
+
29
+ <% if attachment.image? and !field.url_only? %>
30
+ <%= image_tag(field.url(attachment)) %>
31
+ <% elsif attachment.video? and attachment.previewable? and !field.url_only? %> <%# if ffmpeg is installed %>
32
+ <%= video_tag(field.url(attachment), poster: field.preview(attachment, resize: "1920x1080>"), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
33
+ <% elsif attachment.video? and !field.url_only? %>
34
+ <%= video_tag(field.url(attachment), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
35
+ <% elsif attachment.audio? and !field.url_only? %>
36
+ <%= audio_tag(field.url(attachment), autoplay: false, controls: true) %>
37
+ <% elsif attachment.previewable? and !field.url_only? %>
38
+ <%= image_tag(field.preview(attachment, resize: "595x842>")) %>
39
+ <br/>
40
+ Download: <%= link_to(attachment.filename, field.blob_url(attachment)) %>
41
+ <% else %>
42
+ <%= link_to(attachment.filename, field.blob_url(attachment)) %>
43
+ <% end %>
44
+
45
+ <% if removable %>
46
+ <%= link_to 'Remove', field.destroy_path(field, attachment), method: :delete, class: 'remove-attachment-link' %>
47
+ <hr>
48
+ <% 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 } %>
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 %>
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "worker/field/nested_has_many"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,60 @@
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 many?
19
+ # find a way to use instance_of
20
+ data.class.name == "ActiveStorage::Attached::Many"
21
+ end
22
+
23
+ def direct?
24
+ options.fetch(:direct_upload, false)
25
+ end
26
+
27
+ # def destroy_path?
28
+ # options.fetch(:destroy_path, false).present?
29
+ # end
30
+
31
+ # currently we are using Rails.application.routes.url_helpers
32
+ # without including the namespace because it runs into an
33
+ # exception
34
+
35
+ # work around since calling data.preview(options)
36
+ # returns "/images/<ActiveStorage::Preview>" which isnt the url
37
+ def preview(attachment, options)
38
+ Rails.application.routes.url_helpers.rails_representation_path(attachment.preview(options), only_path: true)
39
+ end
40
+
41
+ def url(attachment)
42
+ Rails.application.routes.url_helpers.rails_blob_path(attachment, only_path: true)
43
+ end
44
+
45
+ def blob_url(attachment)
46
+ Rails.application.routes.url_helpers.rails_blob_path(attachment, disposition: :attachment, only_path: true)
47
+ end
48
+
49
+ def destroy_path(field, attachment)
50
+ destroy_path_helper = options.fetch(:destroy_path)
51
+ record_id = field.data.record.id
52
+ attachment_id = attachment.id
53
+ Rails.application.routes.url_helpers.send(destroy_path_helper, {:record_id => record_id, :attachment_id => attachment_id})
54
+ end
55
+
56
+ delegate :attached?, to: :data
57
+ delegate :attachments, to: :data
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,14 @@
1
+ require "administrate/field/active_storage"
2
+
3
+ describe Worker::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,20 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "worker-field-active_storage"
5
+ gem.version = "0.1.0"
6
+ gem.authors = ["V baxt"]
7
+ gem.email = ["vincent.viricel@gmail.com"]
8
+ gem.summary = "Front version for Admin active storage - "
9
+ gem.description = gem.summary
10
+ gem.license = "MIT"
11
+
12
+ gem.require_paths = ["lib"]
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+
16
+ gem.add_dependency "administrate", ">= 0.2.0.rc1"
17
+ gem.add_dependency "rails", ">= 5.2"
18
+
19
+ gem.add_development_dependency "rspec", "~> 3.4"
20
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: worker-field-active_storage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - V baxt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-12 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.0.rc1
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.0.rc1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '5.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '5.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: Front version for Admin 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.txt
66
+ - README.md
67
+ - Rakefile
68
+ - app/views/fields/active_storage/_form.html.erb
69
+ - app/views/fields/active_storage/_index.html.erb
70
+ - app/views/fields/active_storage/_item.html.erb
71
+ - app/views/fields/active_storage/_item_index.html.erb
72
+ - app/views/fields/active_storage/_items.html.erb
73
+ - app/views/fields/active_storage/_show.html.erb
74
+ - bin/console
75
+ - bin/setup
76
+ - lib/worker/field/active_storage.rb
77
+ - spec/lib/worker/field/active_storage_spec.rb
78
+ - worker-field-active_storage.gemspec
79
+ homepage:
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.7.6
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Front version for Admin active storage -
103
+ test_files:
104
+ - spec/lib/worker/field/active_storage_spec.rb