Module: Artwork::View

Defined in:
lib/artwork/view.rb

Instance Method Summary collapse

Instance Method Details

#activate_resolution_independenceObject



5
6
7
# File 'lib/artwork/view.rb', line 5

def activate_resolution_independence
  Thread.current[:artwork_script] ||=  :script, compile_artwork_script
end

#artwork_tag(record, attachment_name, size, options = {}) ⇒ Object



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] ||= extract_title_from(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

   :div, :class => attachment_name do
     :div, img_holder_options.merge(:class => 'img-holder') do
      image_tag image_url, image_tag_options
    end
  end
end