summaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'helpers')
-rw-r--r--helpers/extra_image_helpers.rb35
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