blob: 6a36415bf53bff80179f3b2c1ae935e80dea62d4 (
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
|
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}"
image_link = content_tag(:a, href: path) do
image_tag(thumb_path, options)
end
caption_tag = content_tag :p, caption
content_tag(:div) 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
|