summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Henrik Mai <lars.mai@kontinui.de>2014-04-08 13:34:58 +0200
committerLars Henrik Mai <lars.mai@kontinui.de>2014-04-08 13:34:58 +0200
commitbe5b03464cf021e39a7f2d973fde10b041246908 (patch)
treedce6f7df04afdd0b8306320da18fd907c812c896
parenta733ee6a12e7a4ff358457564cec77029cab59eb (diff)
refactor image_with_thumb helper
-rw-r--r--helpers/extra_image_helpers.rb35
-rw-r--r--source/verein.html.erb4
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:
+ # <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
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 @@
<div class="content">
<div id="moods">
- <%= 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)") %>
</div>
<h2>