app/helpers/image_helper.rb
# Prevent images from thrashing your page's layout with the image_jump_fix helper.
#
# <%= image_jump_fix block.media_item do %>
#   <%= image_tag block.media_item.attachment_url(:medium) %>
# <% end %>
Prevent images from thrashing your page's layout with the image_jump_fix helper.
Prevent images from thrashing your page ' s layout with the image_jump_fix helper .
def image_jump_fix(media_item, options = {})
    width = media_item.try(:dimensions).try(:[], :width)
    height = media_item.try(:dimensions).try(:[], :height)
    tag_type = options.delete(:tag) || :div
    css_class = options[:class]
    if [width, height].all?
      ratio = height.to_f / width.to_f * 100
      padding_bottom = "padding-bottom: #{ratio}%;"
    end
    content_tag tag_type, class: "forest-image-jump-fix #{('forest-image-jump-fix--' + media_item.attachment_content_type.parameterize) if media_item.try(:attachment_content_type).present?} #{css_class}", style: padding_bottom do
      yield
    end
  end
def image_jump_fix ( media_item , options = { } ) width = media_item . try ( :dimensions ) . try ( :[] , :width ) height = media_item . try ( :dimensions ) . try ( :[] , :height ) tag_type = options . delete ( :tag ) || :div css_class = options [ :class ] if [ width , height ] . all? ratio = height . to_f / width . to_f * 100 padding_bottom = "padding-bottom: #{ratio}%;" end content_tag tag_type , class : "forest-image-jump-fix #{('forest-image-jump-fix--' + media_item.attachment_content_type.parameterize) if media_item.try(:attachment_content_type).present?} #{css_class}" , style : padding_bottom do yield end end
Prevent images from thrashing your page's layout with the image_jump_fix helper.
Prevent images from thrashing your page ' s layout with the image_jump_fix helper .
media_item
<not_specific>
options
<not_specific>