Skip to content

Commit

Permalink
Merge pull request #2810 from refinery/refactored-image-fu-to-prevent…
Browse files Browse the repository at this point in the history
…-bugs

Refactored image_fu helper to only use geometry when not nil.
  • Loading branch information
parndt committed Dec 23, 2014
2 parents 5441303 + c3a9521 commit f453944
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions core/app/helpers/refinery/image_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ def content_fu(content, thumbnail)
# and we wanted to display a thumbnail cropped to 200x200 then we can use image_fu like this:
# <%= image_fu @model.image, '200x200' %> or with no thumbnail: <%= image_fu @model.image %>
def image_fu(image, geometry = nil, options = {})
if image.present?
dimensions = (image.thumbnail_dimensions(geometry) rescue {})
return nil if image.blank?

image_tag(image.thumbnail(:geometry => geometry,
:strip => options[:strip]).url, {
:alt => image.respond_to?(:title) ? image.title : image.image_name,
}.merge(dimensions).merge(options))
end
thumbnail_args = options.slice(:strip)
thumbnail_args[:geometry] = geometry if geometry

image_tag_args = (image.thumbnail_dimensions(geometry) rescue {})
image_tag_args[:alt] = image.respond_to?(:title) ? image.title : image.image_name

image_tag(image.thumbnail(thumbnail_args).url, image_tag_args.merge(options))
end
end
end

0 comments on commit f453944

Please sign in to comment.