Sha256: 9aeb13f491f4bd51c9c6abe61af82f7fe32aeb6c26cbcbce685d6c8bfd2fd88a

Contents?: true

Size: 723 Bytes

Versions: 1

Compression:

Stored size: 723 Bytes

Contents

module Para
  module AttributeField
    class ImageField < AttributeField::Base
      include ActionView::Helpers::AssetTagHelper

      def value_for(instance)
        style = attachment_thumb_style_for(instance)

        if instance.send(:"#{ name }?")
          image_tag(instance.send(name).url(style))
        end
      end

      private

      def attachment_thumb_style_for(instance)
        styles = instance.send(name).styles.map(&:first)
        # Check if there's a :thumb or :thumbnail style in attachment definition
        thumb = styles.find { |s| %w(thumb thumbnail).include?(s.to_s) }
        # Return the potentially smallest size !
        thumb || styles.first || :original
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
para-0.4.0 lib/para/attribute_field/image.rb