administrate-field-active_storage 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 36e2931ef3866e05ff79f6580d2e82d9255bf32a
4
+ data.tar.gz: e756ee6745311cfc2fda588a222ec4f4ce5656a1
5
+ SHA512:
6
+ metadata.gz: ec287997ada87ecba73e4aba1f812be8005fe2340c6b37a2edf7b7177cb15a0dccdfc91a46b0b530548e83258754d88837ec18ec873b19fda999fd8f82c14b9f
7
+ data.tar.gz: 9b43814703a5281d9de9a0f2a7a16878e5b75c995c9f33cd93816ea70414ffb3b68757d55ef191ea5aa819f6c2f374921ac06460223cb3ff428b0fdec4d990ff
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # CHANGELOG
2
+
3
+ ## 1.1.0 (2017-03-24)
4
+
5
+ * Don't crash if image is nil/blank ([#9][])
6
+ * Remove Explicit Dependency on Rails ([#11][])
7
+ * Adds this CHANGELOG ([#12][])
8
+
9
+ [#9]: https://github.com/thoughtbot/administrate-field-image/pull/9
10
+ [#11]: https://github.com/thoughtbot/administrate-field-image/pull/11
11
+ [#12]: https://github.com/thoughtbot/administrate-field-image/pull/12
12
+
13
+ ## 1.0.0 (2017-01-16)
14
+
15
+ * Extraction from [administrate][].
16
+ * Rails 5 support.
17
+
18
+ [administrate]: https://github.com/thoughtbot/administrate
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
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,53 @@
1
+ # Administrate::Field::ActiveStorage
2
+ ![rails](https://img.shields.io/badge/rails-%3E%3D5.2.0-red.svg)
3
+ ## Things To Know:
4
+ - currently the gem only works for `has_one_attached` support for `has_many_attached` will be added in a future release.
5
+ - to preview pdf files you need to install `mupdf` or `Poppler`.
6
+ - to preview video files you need to install `ffmpeg`.
7
+
8
+ ## How To Use:
9
+ Add `administrate-field-active_storage` to your Gemfile:
10
+
11
+ ```ruby
12
+ gem 'administrate-field-active_storage'
13
+ ```
14
+
15
+ Install:
16
+
17
+ ```
18
+ $ bundle install
19
+ ```
20
+
21
+ Use:
22
+ assuming your modelname is `Model` and field name is `attachment`
23
+ ```ruby
24
+ class ModelDashboard < Administrate::BaseDashboard
25
+ ATTRIBUTE_TYPES = {
26
+ attachment: Field::ActiveStorage,
27
+ }
28
+ # ...
29
+ ```
30
+ Then add `:attachment` to `FORM_ATTRIBUTES` and `SHOW_PAGE_ATTRIBUTES`.
31
+ currently adding `:attachment` `COLLECTION_ATTRIBUTES` will work but will probably look too big.
32
+
33
+ ## Things To Do:
34
+
35
+ - [x] upload single file
36
+ - [x] adding image support through url_for to support 3rd party cloud storage
37
+ - [x] use html 5 video element for video files
38
+ - [x] use html audio element for audio files
39
+ - [x] download link to other files
40
+ - [x] preview videos
41
+ - [x] preview pdfs
42
+ - [ ] preview office files as pictures
43
+ - [ ] upload multiple files
44
+
45
+ ## Contribution guide:
46
+ 1. contributers are welcome (code, suggestions, and bugs).
47
+ 2. please document your code.
48
+ 3. add your name to the `contribute.md`.
49
+
50
+ please note that this is my first gem :) i might have gotten some stuff wrong PR's are always welcome
51
+ ---
52
+ 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).
53
+
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
@@ -0,0 +1,21 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "administrate-field-active_storage"
5
+ gem.version = "0.0.2"
6
+ gem.authors = ["Hamad AlGhanim"]
7
+ gem.email = ["hamadyalghanim@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.0.rc1"
18
+ gem.add_dependency "rails", ">= 5.2"
19
+
20
+ gem.add_development_dependency "rspec", "~> 3.4"
21
+ end
@@ -0,0 +1,23 @@
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
+ <div class="field-unit__field">
22
+ <%= f.file_field field.attribute %>
23
+ </div>
@@ -0,0 +1,31 @@
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
+ <% if field.image? %>
18
+ <%= image_tag(field.url) %>
19
+ <% elsif field.video? and field.previewable?%> <%# if ffmpeg is installed %>
20
+ <%= video_tag(field.url, poster: field.preview(resize: "1920x1080>"), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
21
+ <% elsif field.video? %>
22
+ <%= video_tag(field.url, controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
23
+ <% elsif field.audio? %>
24
+ <%= audio_tag(field.url, autoplay: true, controls: true) %>
25
+ <% elsif field.previewable? %>
26
+ <%= image_tag(field.preview(resize: "595x842>")) %>
27
+ <br/>
28
+ Download: <%= link_to(field.filename, field.blob_url) %>
29
+ <% else %>
30
+ <%= link_to(field.filename, field.blob_url) %>
31
+ <% end %>
@@ -0,0 +1,30 @@
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.image? %>
19
+ <%= image_tag(field.url) %>
20
+ <% elsif field.video? %>
21
+ <%= video_tag(field.url, poster: field.preview(resize: "1920x1080>"), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
22
+ <% elsif field.audio? %>
23
+ <%= audio_tag(field.url, autoplay: true, controls: true) %>
24
+ <% elsif field.previewable? %>
25
+ <%= image_tag(field.preview(resize: "595x842>")) %>
26
+ <br/>
27
+ Download: <%= link_to(field.filename, field.blob_url) %>
28
+ <% else %>
29
+ <%= link_to(field.filename, field.blob_url) %>
30
+ <% end %>
data/contribute.md ADDED
File without changes
@@ -0,0 +1,37 @@
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
+ # currently we are using Rails.application.routes.url_helpers
10
+ # without including the namespace because it runs into an
11
+ # exception
12
+
13
+ def url
14
+ Rails.application.routes.url_helpers.rails_blob_path(data, only_path: true)
15
+ end
16
+
17
+ def blob_url
18
+ Rails.application.routes.url_helpers.rails_blob_path(data, disposition: :attachment, only_path: true)
19
+ end
20
+
21
+ # work around since calling data.preview(options)
22
+ # returns "/images/<ActiveStorage::Preview>" which isnt the url
23
+
24
+ def preview(options)
25
+ Rails.application.routes.url_helpers.rails_representation_path(data.preview(options), only_path: true)
26
+ end
27
+
28
+ delegate :filename, to: :data
29
+ delegate :previewable?, to: :data
30
+ delegate :image?, to: :data
31
+ delegate :video?, to: :data
32
+ delegate :audio?, to: :data
33
+ delegate :audio?, to: :data
34
+
35
+ end
36
+ end
37
+ 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
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: administrate-field-active_storage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Hamad AlGhanim
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-06 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: Administrate fields for active storage
56
+ email:
57
+ - hamadyalghanim@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CHANGELOG.md
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - administrate-field-active_storage.gemspec
69
+ - app/views/fields/active_storage/_form.html.erb
70
+ - app/views/fields/active_storage/_index.html.erb
71
+ - app/views/fields/active_storage/_show.html.erb
72
+ - contribute.md
73
+ - lib/administrate/field/active_storage.rb
74
+ - spec/lib/administrate/field/active_storage_spec.rb
75
+ homepage: https://github.com/Dreamersoul/administrate-field-active_storage
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.6.11
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Administrate fields for active storage
99
+ test_files:
100
+ - spec/lib/administrate/field/active_storage_spec.rb