From 4852a7c95b13901bc8e88f7785dde4bab8de20c7 Mon Sep 17 00:00:00 2001 From: Lars Henrik Mai Date: Sun, 6 Apr 2014 20:58:02 +0200 Subject: added helper for images with thumbnails and captions --- helpers/extra_image_helpers.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 helpers/extra_image_helpers.rb (limited to 'helpers') diff --git a/helpers/extra_image_helpers.rb b/helpers/extra_image_helpers.rb new file mode 100644 index 0000000..9c92d3c --- /dev/null +++ b/helpers/extra_image_helpers.rb @@ -0,0 +1,27 @@ +module ExtraImageHelpers + + # creates a div with image link, thumbnail and caption + # TODO make this work for non-image assets (pdf on 'verein' page) + def image_with_thumb(name, options={}) + caption = options.delete(:caption) + full_path = "/img/#{name}" + + thumb_name = options.delete(:thumbnail) || default_thumbnail_for(name) + 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) + + content_tag :div, [image_link, caption_tag].join("\n") + end + + private + + def default_thumbnail_for(image_name_with_ext) + name, ext = image_name_with_ext.split(".") + "#{name}_klein.#{ext}" + end + +end -- cgit v1.2.1