Sha256: 62e88aa3651dc2eb4797dd85757c99ab4789ddee663c6ae0dca1e9e1d337b89d
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
module Artwork module View def activate_resolution_independence Thread.current[:artwork_script] ||= content_tag :script, compile_artwork_script end 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 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 private def extract_title_from(record) if record.respond_to? :title record.title elsif record.respond_to? :name record.name end end def compile_artwork_script artwork_script_path = Artwork.root_path + '/assets/javascripts/artwork.js' compiled_script = Uglifier.compile(File.read(artwork_script_path)) if compiled_script.respond_to?(:html_safe) compiled_script.html_safe else compiled_script end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
artwork-0.3.0 | lib/artwork/view.rb |