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 +++++++++++++++++++++++++---------- source/verein.html.erb | 4 ++-- 2 files changed, 27 insertions(+), 12 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: + #
+ # + # + # + #

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 diff --git a/source/verein.html.erb b/source/verein.html.erb index 62a30d0..4e3e45d 100644 --- a/source/verein.html.erb +++ b/source/verein.html.erb @@ -1,8 +1,8 @@
- <%= image_with_thumb("was_ist_das_sublab.pdf", thumbnail: "wasistdassublab.png", caption: "Was ist das sublab? (pdf)") %> - <%= image_with_thumb("sublab-presentation.pdf", thumbnail: "presi.png", caption: "Ubucon Präsentation (pdf)") %> + <%= asset_with_thumb("/inc/was_ist_das_sublab.pdf", thumbnail: "wasistdassublab.png", caption: "Was ist das sublab? (pdf)") %> + <%= asset_with_thumb("/inc/sublab-presentation.pdf", thumbnail: "presi.png", caption: "Ubucon Präsentation (pdf)") %>

-- cgit v1.2.1