module ExtraImageHelpers # creates an image link with thumbnail and caption: #
# # # #

Caption

#
# def image_with_thumb(name, options={}) path = "/img/#{name}" options[:thumbnail] ||= default_thumbnail_for(name) asset_with_thumb(path, options) end # more general version of image_with_thumb, for pdfs and other assets (= not in the '/img' directory) def asset_with_thumb(path, options={}) caption = options.delete(:caption) thumb_name = options.delete(:thumbnail) thumb_path = "/img/#{thumb_name}" container_opts = options.delete(:container_opts) || {} image_link = content_tag(:a, href: path) do image_tag(thumb_path, options) end caption_tag = content_tag :p, caption content_tag(:div, container_opts) do image_link << caption_tag end end private def default_thumbnail_for(image_name_with_ext) name, ext = image_name_with_ext.split(".") "#{name}_klein.#{ext}" end end