Sha256: ea90fe96492ab463871bf5103a85bc7a74f5735a84cd2c532c70e9388bfeae33
Contents?: true
Size: 752 Bytes
Versions: 6
Compression:
Stored size: 752 Bytes
Contents
module Para module AttributeField class ImageField < AttributeField::Base include ActionView::Helpers::AssetTagHelper register :image, self 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
6 entries across 6 versions & 1 rubygems