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
# 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]
    image = record.send(attachment_name)

    if image.height.present? and image.width.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