Module: Artwork::Model
- Defined in:
- lib/artwork/model.rb
Instance Method Summary collapse
- #artwork_thumb_for(attachment_name, size) ⇒ Object
- #artwork_thumbs_for(attachment_name) ⇒ Object
- #artwork_url(attachment_name, size, options = {}) ⇒ Object
- #attachment_style_for(attachment_name, size, alternative_sizes = nil) ⇒ Object
- #attachment_styles_for(attachment_name) ⇒ Object
- #normal_artwork_thumb_for(attachment_name, thumbs, desired_thumb) ⇒ Object
- #plain_thumb_for(attachment_name, label) ⇒ Object
- #retina_artwork_thumb_for(attachment_name, thumbs, desired_thumb) ⇒ Object
Instance Method Details
#artwork_thumb_for(attachment_name, size) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/artwork/model.rb', line 38 def artwork_thumb_for(, size) desired_thumb = DesiredThumbnail.from_style(size) thumbs = artwork_thumbs_for() thumbs = thumbs.select(&:compatible?).select { |thumb| desired_thumb.is_like?(thumb) }.sort if Artwork.load_2x_images? retina_artwork_thumb_for(, thumbs, desired_thumb) else normal_artwork_thumb_for(, thumbs, desired_thumb) end end |
#artwork_thumbs_for(attachment_name) ⇒ Object
34 35 36 |
# File 'lib/artwork/model.rb', line 34 def artwork_thumbs_for() ().map { |style| Thumbnail.from_style(style) } end |
#artwork_url(attachment_name, size, options = {}) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/artwork/model.rb', line 3 def artwork_url(, size, = {}) thumb_name = (, size, ) return nil unless thumb_name send().url(thumb_name, ) end |
#attachment_style_for(attachment_name, size, alternative_sizes = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/artwork/model.rb', line 15 def (, size, alternative_sizes = nil) size = determine_alternative_size_for(alternative_sizes) || size thumb = if DesiredThumbnail.compatible?(size) artwork_thumb_for(, size) else plain_thumb_for(, size) end return nil unless thumb if thumb.respond_to?(:name) thumb.name.to_sym else thumb.to_sym end end |
#attachment_styles_for(attachment_name) ⇒ Object
11 12 13 |
# File 'lib/artwork/model.rb', line 11 def () self.class.[.to_sym][:styles].keys end |
#normal_artwork_thumb_for(attachment_name, thumbs, desired_thumb) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/artwork/model.rb', line 65 def normal_artwork_thumb_for(, thumbs, desired_thumb) usable_thumbs = thumbs.reject(&:retina?) thumb = usable_thumbs.find { |current| desired_thumb.expected_width <= current.width } thumb || usable_thumbs.max_by(&:width) end |
#plain_thumb_for(attachment_name, label) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/artwork/model.rb', line 52 def plain_thumb_for(, label) all_styles = () normal_thumb = label.to_sym retina_thumb = :"#{label}_2x" if Artwork.load_2x_images? and all_styles.include?(retina_thumb) retina_thumb elsif all_styles.include?(normal_thumb) normal_thumb end end |
#retina_artwork_thumb_for(attachment_name, thumbs, desired_thumb) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/artwork/model.rb', line 73 def retina_artwork_thumb_for(, thumbs, desired_thumb) retina_thumbs = thumbs.select(&:retina?) thumb = retina_thumbs.find { |current| desired_thumb.expected_width <= current.width } thumb || normal_artwork_thumb_for(, thumbs, desired_thumb) || retina_thumbs.max_by(&:width) end |