Skip to content

Commit

Permalink
Merge pull request #1654 from resolve/issue_1628
Browse files Browse the repository at this point in the history
Fixes #1628
  • Loading branch information
ugisozols committed May 12, 2012
2 parents c5a88f8 + 20c0169 commit f4d7026
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions core/app/helpers/refinery/image_helper.rb
Expand Up @@ -6,18 +6,16 @@ module ImageHelper
# replace all system images with a thumbnail version of them (handy for all images inside a page part)
# for example, <%= content_fu(@page.content_for(:body), '96x96#c') %> converts all /system/images to a 96x96 cropped thumbnail
def content_fu(content, thumbnail)
content.gsub(%r{<img.+?src=['"](/system/images/.+?)/.+?/>}) do |image_match|
begin
uid = Dragonfly::Job.from_path(
"#{image_match.match(%r{(/system/images/.+?)/})[1]}", Dragonfly[:refinery_images]
).uid
content.gsub(%r{<img.+?src=['"](/system/images/.+?)/.+?/>}) do |img|
begin
sha = img.match(%r{/system/images/(.+?)/})[1]
job = Dragonfly::Job.deserialize sha, Dragonfly[:refinery_images]

image_fu Image.where(:image_uid => uid).first, thumbnail
rescue
# FAIL, don't care why but return what we found initially.
image_match
end
end
image_fu Image.where(:image_uid => job.uid).first, thumbnail
rescue Dragonfly::Serializer::BadString
img
end
end
end

# image_fu is a helper for inserting an image that has been uploaded into a template.
Expand Down

0 comments on commit f4d7026

Please sign in to comment.