Sha256: 117c306cd5aaf316ebee91a733c387f29d675f43786650a41513ae7c6f81fbdb

Contents?: true

Size: 1.92 KB

Versions: 3

Compression:

Stored size: 1.92 KB

Contents

<%#
# Item Partial

This partial renders attached items.

Attachments of type image, video and audio are emedded.  For all other types
we try use it's preview.  If all else fails we simply link to the attached file.

This partial will optionally show a `remove` link next to each attachment which is
controlled via a boolean local variable.

## Local variables:

- `field`:
  An instance of [Administrate::Field::Image].
  A wrapper around the image url pulled from the database.
- `attachment`:
  Reference to the file
- `removable`:
  A boolean used to control the display of a `Remove` link which
  is used to destroy a single attachment.  Defaults to `false`
%>

<%
  # By default we don't allow attachment removal
  removable = local_assigns.fetch(:removable, false)
  image_size = local_assigns.fetch(:image_size, "1920x1080>")
%>

<% if attachment.image? and !field.url_only? %>
  <%= image_tag(field.variant(attachment, resize: image_size)) %>
<% elsif attachment.video? and attachment.previewable? and !field.url_only? %> <%# if ffmpeg is installed %>
  <%= video_tag(field.url(attachment), poster: field.preview(attachment, resize: image_size), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
<% elsif attachment.video? and !field.url_only? %>
  <%= video_tag(field.url(attachment), controls: true, autobuffer: true, style: "width: 100%; height: auto;") %>
<% elsif attachment.audio? and !field.url_only? %>
  <%= audio_tag(field.url(attachment), autoplay: false, controls: true) %>
<% elsif attachment.previewable? and !field.url_only? %>
  <%= image_tag(field.preview(attachment, resize: "595x842>")) %>
  <br/>
  Download: <%= link_to(attachment.filename, field.blob_url(attachment)) %>
<% else %>
  <%= link_to(attachment.filename, field.blob_url(attachment)) %>
<% end %>

<% if removable %>
  <%= link_to 'Remove', field.destroy_path(field, attachment), method: :delete, class: 'remove-attachment-link' %>
  <hr>
<% end %>

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
administrate-field-active_storage-0.2.0 app/views/fields/active_storage/_item.html.erb
administrate-field-active_storage-0.1.8 app/views/fields/active_storage/_item.html.erb
administrate-field-active_storage-0.1.7 app/views/fields/active_storage/_item.html.erb