Skip to content

Commit

Permalink
This closes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamersoul committed Jul 7, 2018
1 parent b4f3943 commit 8b352c8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion administrate-field-active_storage.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)

Gem::Specification.new do |gem|
gem.name = "administrate-field-active_storage"
gem.version = "0.1.0"
gem.version = "0.1.1"
gem.authors = ["Hamad AlGhanim"]
gem.email = ["[email protected]"]
gem.homepage = "https://github.com/Dreamersoul/administrate-field-active_storage"
Expand Down
1 change: 1 addition & 0 deletions app/views/fields/active_storage/_index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ By default, the attribute is rendered as an image tag.
<% if field.many? %>
<% field.attachments.each do |attachment| %>
<%= render :partial => 'item', :field => field, :attachment => attachment %>
<br/>
<% end %>
<% else %>
<%= render :partial => 'item', :field => field, :attachment => field.data %>
Expand Down
10 changes: 5 additions & 5 deletions app/views/fields/active_storage/_item.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<% if attachment.image? %>
<% if attachment.image? and !field.url_only? %>
<%= image_tag(field.url(attachment)) %>
<% elsif attachment.video? and attachment.previewable? %> <%# if ffmpeg is installed %>
<% elsif attachment.video? and attachment.previewable? and !field.url_only? %> <%# if ffmpeg is installed %>
<%= video_tag(field.url(attachment), poster: field.preview(attachment, resize: "1920x1080>"), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
<% elsif attachment.video? %>
<% elsif attachment.video? and !field.url_only? %>
<%= video_tag(field.url(attachment), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
<% elsif attachment.audio? %>
<% elsif attachment.audio? and !field.url_only? %>
<%= audio_tag(field.url(attachment), autoplay: true, controls: true) %>
<% elsif attachment.previewable? %>
<% elsif attachment.previewable? and !field.url_only? %>
<%= image_tag(field.preview(attachment, resize: "595x842>")) %>
<br/>
Download: <%= link_to(attachment.filename, field.blob_url(attachment)) %>
Expand Down
1 change: 1 addition & 0 deletions app/views/fields/active_storage/_show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ By default, the attribute is rendered as an image tag.
<% if field.many? %>
<% field.attachments.each do |attachment| %>
<%= render :partial => 'fields/active_storage/item', locals: { field: field, attachment: attachment } %>
<br/>
<% end %>
<% else %>
<%= render :partial => 'fields/active_storage/item', locals: { field: field, attachment: field.data } %>
Expand Down
14 changes: 10 additions & 4 deletions lib/administrate/field/active_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ module Field
class ActiveStorage < Administrate::Field::Base
class Engine < ::Rails::Engine
end
# currently we are using Rails.application.routes.url_helpers
# without including the namespace because it runs into an
# exception

def url_only?
options.fetch(:url_only, false)
end

def many?
# find a way to use instance_of
data.class.name == "ActiveStorage::Attached::Many"
end

# currently we are using Rails.application.routes.url_helpers
# without including the namespace because it runs into an
# exception

# work around since calling data.preview(options)
# returns "/images/<ActiveStorage::Preview>" which isnt the url

def preview(attachment, options)
Rails.application.routes.url_helpers.rails_representation_path(attachment.preview(options), only_path: true)
end
Expand Down

0 comments on commit 8b352c8

Please sign in to comment.