blob: 47cda2def6320dd71e79da36bca861b42c9e6685 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
module ExtraImageHelpers
# 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={})
path = "/img/#{name}"
options[: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}"
container_opts = options.delete(:container_opts) || {}
image_link = content_tag(:a, href: path, class: "th") do
image_tag(thumb_path, options)
end
caption_tag = content_tag :p, caption
content_tag(:div, container_opts) do
image_link << caption_tag
end
end
private
def default_thumbnail_for(image_name_with_ext)
name, ext = image_name_with_ext.split(".")
"#{name}_klein.#{ext}"
end
end
|