noesya/osuny

View on GitHub
app/views/admin/active_storage/blobs/static.html.erb

Summary

Maintainability
Test Coverage
<%-
university = University.find_by(id: @about.university_id)
version = 2
cache [@about, university, version] do
-%>
<%
width, height = @about.metadata.values_at('width', 'height')
ratio = width.present? && height.present? ? (width.to_f / height.to_f) : nil
format = 'square'
if ratio.present?
  format = 'landscape' if ratio > 1
  format = 'portrait' if ratio < 1
end
base_url = university&.url || ""
%>
<%= raw({
  "name" => @about.filename.to_s,
  "size" => @about.byte_size,
  "width" => width,
  "height" => height,
  "ratio" => ratio,
  "format" => format,
  "url" => "#{base_url}#{medium_path(signed_id: @about.signed_id, filename_with_transformations: @about.filename)}",
  "direct_url" => @about.url,
  "download_url" => "#{base_url}#{download_medium_path(signed_id: @about.signed_id)}"
}.compact.to_yaml) %>
<%- end -%>