Sha256: d85ce2498d1ede22fa1dca1f006228c13f0989f8b60a31695bc04a7792769e9f

Contents?: true

Size: 1.86 KB

Versions: 12

Compression:

Stored size: 1.86 KB

Contents

# frozen_string_literal: true

module Alchemy
  module Ingredients
    # A picture assignment
    #
    # Assign Alchemy::Picture to this ingredient
    #
    # Optionally you can add a link
    # As well as set the alt tag, a caption and title
    #
    class Picture < Alchemy::Ingredient
      include Alchemy::PictureThumbnails

      store_accessor :data,
        :alt_tag,
        :caption,
        :crop_from,
        :crop_size,
        :css_class,
        :link_class_name,
        :link_target,
        :link_title,
        :link,
        :render_size,
        :title

      related_object_alias :picture, class_name: "Alchemy::Picture"

      allow_settings %i[
        crop
        css_classes
        fixed_ratio
        linkable
        size
        sizes
        srcset
        upsample
      ]

      def alt_text(language: Alchemy::Current.language)
        alt_tag.presence ||
          picture&.description_for(language) ||
          picture&.name&.humanize
      end

      # The first 30 characters of the pictures name
      #
      # Used by the Element#preview_text method.
      #
      # @param [Integer] max_length (30)
      #
      def preview_text(max_length = 30)
        picture&.name.to_s[0..max_length - 1]
      end

      # The picture view component with mapped options.
      #
      # @param options [Hash] - Passed to the view component
      # @param html_options [Hash] - Passed to the view component
      #
      # @return Alchemy::Ingredients::PictureView
      def as_view_component(options: {}, html_options: {})
        PictureView.new(
          self,
          show_caption: options.delete(:show_caption),
          disable_link: options.delete(:disable_link),
          srcset: options.delete(:srcset),
          sizes: options.delete(:sizes),
          picture_options: options,
          html_options: html_options
        )
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
alchemy_cms-7.3.4 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.3.3 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.3.2 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.2.7 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.3.1 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.3.0 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.2.6 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.2.5 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.2.4 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.2.3 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.2.2 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.2.1 app/models/alchemy/ingredients/picture.rb