Sha256: afe00dc25ae5c03bd88add720f71e5f31c452a46d55b3a620d2ce6e807134a63

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

module Artwork
  module View
    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
artwork-0.1.1 lib/artwork/view.rb
artwork-0.1.0 lib/artwork/view.rb
artwork-0.0.1 lib/artwork/view.rb