Class: Plum::Asset
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ApplicationRecord
- Plum::Asset
- Includes:
- SiteScoped
- Defined in:
- app/models/plum/asset.rb
Instance Method Summary collapse
- #content_type ⇒ Object
- #filename ⇒ Object
- #image? ⇒ Boolean
- #to_liquid ⇒ Object
- #url ⇒ Object
- #variant_url(transformations) ⇒ Object
Instance Method Details
#content_type ⇒ Object
16 17 18 |
# File 'app/models/plum/asset.rb', line 16 def content_type file.content_type if file.attached? end |
#filename ⇒ Object
12 13 14 |
# File 'app/models/plum/asset.rb', line 12 def filename file.attached? ? file.filename.to_s : "" end |
#image? ⇒ Boolean
20 21 22 |
# File 'app/models/plum/asset.rb', line 20 def image? content_type.to_s.start_with?("image/") end |
#to_liquid ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/models/plum/asset.rb', line 39 def to_liquid { "id" => id, "url" => url, "thumb" => variant_url(resize_to_fill: [ 300, 300 ]), "small" => variant_url(resize_to_limit: [ 640, 640 ]), "medium" => variant_url(resize_to_limit: [ 1200, 1200 ]), "large" => variant_url(resize_to_limit: [ 2000, 2000 ]), "alt_text" => alt_text.to_s, "caption" => caption.to_s, "filename" => filename, "content_type" => content_type.to_s, "byte_size" => file.attached? ? file.byte_size : nil, "folder" => folder.to_s } end |
#url ⇒ Object
24 25 26 27 28 |
# File 'app/models/plum/asset.rb', line 24 def url return "" unless file.attached? Rails.application.routes.url_helpers.rails_blob_path(file, only_path: true) end |
#variant_url(transformations) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'app/models/plum/asset.rb', line 30 def variant_url(transformations) return url unless file.attached? && file.variable? variant = file.variant(transformations) Rails.application.routes.url_helpers.rails_blob_path(variant.processed, only_path: true) rescue StandardError, LoadError url end |