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
|
# File 'lib/artwork/view.rb', line 9
def artwork_tag(record, attachment_name, size, options = {})
image_tag_options = options[:image] || {}
img_holder_options = options[:img_holder] || {}
image_tag_options[:alt] ||= (record)
image_url = record.artwork_url attachment_name, size, options
if options[:auto_height]
if options[:auto_height].respond_to?(:first)
image_width = options[:auto_height].first
image_height = options[:auto_height].last
else
image = record.send(attachment_name)
image_width = image.width
image_height = image.height
end
if image_width.present? and image_height.present?
padding = ((image_height.to_f / image_width) * 100).round(4)
img_holder_options[:style] = "padding-bottom:#{padding}%;"
end
end
content_tag :div, :class => attachment_name do
content_tag :div, img_holder_options.merge(:class => 'img-holder') do
image_tag image_url, image_tag_options
end
end
end
|