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
17 18 19 |
# File 'app/models/plum/asset.rb', line 17 def content_type file.content_type if file.attached? end |
#filename ⇒ Object
13 14 15 |
# File 'app/models/plum/asset.rb', line 13 def filename file.attached? ? file.filename.to_s : "" end |
#image? ⇒ Boolean
21 22 23 |
# File 'app/models/plum/asset.rb', line 21 def image? content_type.to_s.start_with?("image/") end |
#to_liquid ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/plum/asset.rb', line 40 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, "focal_x" => focal_x, "focal_y" => focal_y, "object_position" => "#{focal_x}% #{focal_y}%" } end |
#url ⇒ Object
25 26 27 28 29 |
# File 'app/models/plum/asset.rb', line 25 def url return "" unless file.attached? Rails.application.routes.url_helpers.rails_blob_path(file, only_path: true) end |
#variant_url(transformations) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'app/models/plum/asset.rb', line 31 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 |