Class: Decidim::MetaImageUrlResolver
- Inherits:
-
Object
- Object
- Decidim::MetaImageUrlResolver
- Includes:
- TranslatableAttributes
- Defined in:
- app/resolvers/decidim/meta_image_url_resolver.rb
Overview
Resolves the most appropriate image URL for meta tags from a given resource within an organization. Searches in the following order: attachment images, images in resource description, participatory space images, and default content block images. Ensures the selected image is resized to 1200x630 pixels.
Constant Summary collapse
- IMAGE_FIELDS =
[:hero_image, :banner_image, :avatar].freeze
- DESCRIPTION_FIELDS =
[:body, :description, :short_description, :content, :additional_info].freeze
- CONTENT_BLOCK_TYPES =
{ { manifest_name: :hero, scope_name: :homepage } => [:background_image] }.freeze
Instance Attribute Summary collapse
-
#organization ⇒ Object
readonly
Returns the value of attribute organization.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
-
#blob ⇒ ActiveStorage::Blob?
Determines the image blob to be used for meta tags by following a hierarchy.
-
#initialize(resource, organization) ⇒ MetaImageUrlResolver
constructor
A new instance of MetaImageUrlResolver.
-
#resolve ⇒ String?
Resolves the image blob to be used for meta tags.
Methods included from TranslatableAttributes
#attachment?, #default_locale?
Constructor Details
#initialize(resource, organization) ⇒ MetaImageUrlResolver
Returns a new instance of MetaImageUrlResolver.
16 17 18 19 |
# File 'app/resolvers/decidim/meta_image_url_resolver.rb', line 16 def initialize(resource, organization) @resource = resource @organization = organization end |
Instance Attribute Details
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
21 22 23 |
# File 'app/resolvers/decidim/meta_image_url_resolver.rb', line 21 def organization @organization end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
21 22 23 |
# File 'app/resolvers/decidim/meta_image_url_resolver.rb', line 21 def resource @resource end |
Instance Method Details
#blob ⇒ ActiveStorage::Blob?
Determines the image blob to be used for meta tags by following a hierarchy.
37 38 39 |
# File 'app/resolvers/decidim/meta_image_url_resolver.rb', line 37 def blob @blob ||= blob_from_image_fields || || blob_from_description || blob_from_participatory_space || blob_from_content_blocks end |
#resolve ⇒ String?
Resolves the image blob to be used for meta tags.
26 27 28 29 30 31 32 |
# File 'app/resolvers/decidim/meta_image_url_resolver.rb', line 26 def resolve return unless blob return unless blob.service.exist?(blob.key) resized_variant = blob.variant(resize_to_limit: [1200, 630]).processed Rails.application.routes.url_helpers.rails_representation_url(resized_variant, only_path: true) end |