Module: Refinery::ImageHelper
- Defined in:
- app/helpers/refinery/image_helper.rb
Instance Method Summary collapse
-
#content_fu(content, thumbnail) ⇒ Object
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.
-
#image_fu(image, geometry = nil, options = {}) ⇒ Object
image_fu is a helper for inserting an image that has been uploaded into a template.
Instance Method Details
#content_fu(content, thumbnail) ⇒ Object
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
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/helpers/refinery/image_helper.rb', line 6 def content_fu(content, thumbnail) 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 => job.uid).first, thumbnail rescue Dragonfly::Serializer::BadString img end end end |
#image_fu(image, geometry = nil, options = {}) ⇒ Object
image_fu is a helper for inserting an image that has been uploaded into a template. Say for example that we had a @model.image (@model having a belongs_to :image relationship) 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 %>
23 24 25 26 27 28 29 30 31 32 |
# File 'app/helpers/refinery/image_helper.rb', line 23 def image_fu(image, geometry = nil, ={}) if image.present? dimensions = (image.thumbnail_dimensions(geometry) rescue {}) image_tag(image.thumbnail(:geometry => geometry, :strip => [:strip]).url, { :alt => image.respond_to?(:title) ? image.title : image.image_name, }.merge(dimensions).merge()) end end |