diff options
author | Lars Henrik Mai <lars.mai@kontinui.de> | 2014-04-08 13:34:58 +0200 |
---|---|---|
committer | Lars Henrik Mai <lars.mai@kontinui.de> | 2014-04-08 13:34:58 +0200 |
commit | be5b03464cf021e39a7f2d973fde10b041246908 (patch) | |
tree | dce6f7df04afdd0b8306320da18fd907c812c896 /helpers | |
parent | a733ee6a12e7a4ff358457564cec77029cab59eb (diff) |
refactor image_with_thumb helper
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/extra_image_helpers.rb | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/helpers/extra_image_helpers.rb b/helpers/extra_image_helpers.rb index 9c92d3c..6a36415 100644 --- a/helpers/extra_image_helpers.rb +++ b/helpers/extra_image_helpers.rb @@ -1,20 +1,35 @@ module ExtraImageHelpers - # creates a div with image link, thumbnail and caption - # TODO make this work for non-image assets (pdf on 'verein' page) + # creates an image link with thumbnail and caption: + # <div> + # <a href="/img/image.jpg"> + # <img src="/img/image_klein.jpg"> + # </a> + # <p>Caption</p> + # </div> + # def image_with_thumb(name, options={}) - caption = options.delete(:caption) - full_path = "/img/#{name}" + path = "/img/#{name}" + options[:thumbnail] ||= default_thumbnail_for(name) - thumb_name = options.delete(: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}" - # oh boy, padrino-helpers has problems with nested content_for... FIXME - thumb_tag = image_tag(thumb_path, options) - image_link = content_tag(:a, thumb_tag, href: full_path) - caption_tag = content_tag(:p, caption) + image_link = content_tag(:a, href: path) do + image_tag(thumb_path, options) + end + + caption_tag = content_tag :p, caption - content_tag :div, [image_link, caption_tag].join("\n") + content_tag(:div) do + image_link << caption_tag + end end private |