From be5b03464cf021e39a7f2d973fde10b041246908 Mon Sep 17 00:00:00 2001 From: Lars Henrik Mai Date: Tue, 8 Apr 2014 13:34:58 +0200 Subject: refactor image_with_thumb helper --- helpers/extra_image_helpers.rb | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'helpers') 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: + #
+ # + # + # + #

Caption

+ #
+ # 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 -- cgit v1.2.1