lespoupeesrusses/promethee

View on GitHub
app/views/promethee/components/slider_item/_show.html.erb

Summary

Maintainability
Test Coverage
<%
media_type = component[:attributes].dig(:media_type, :value)
caption = component[:attributes].dig(:caption, :value)&.to_s&.html_safe
case media_type
when 'image'
  image_blob = blob_from_data component[:attributes].dig(:image, :value)
when 'video'
  url = component[:attributes].dig(:video, :value)&.to_s
  if 'vimeo'.in? url
    video_id = url.gsub(/\A(?:https?:)?\/\/(?:(?:www|player)\.)?vimeo\.com\/(?:video\/)?(\d+).*?\z/, '\1')
    iframe_src = "https://player.vimeo.com/video/#{video_id}?color=ffffff&title=0&byline=0&portrait=0"
  elsif 'youtube'.in? url
    video_id = url.split('watch?v=').last
    iframe_src = "https://www.youtube.com/embed/#{video_id}"
  else
    iframe_src = url
  end
end
%>
<div class="<%= promethee_class_for component %> carousel-item__content"
     id="<%= promethee_id_for component %>">
  <% if iframe_src.present? %>
  <div class="embed-responsive embed-responsive-16by9">
    <iframe frameborder="0" webkitallowfullscreen="" mozallowfullscreen="" allowfullscreen="allowfullscreen" src="<%= iframe_src %>"></iframe>
  </div>
  <% elsif image_blob.present? %>
    <%= render 'promethee/show/image_srcset', blob: image_blob, alt: '', title: '', caption: caption, image_zoomable: false %>
  <% end %>
  <div class="carousel-item__content__caption">
    <%= caption %>
  </div>
</div>