Sha256: bf790d46d881a60d87c37c3057a22da2a01aa3b340b7b776b92b64ab24fb8fc9

Contents?: true

Size: 1.69 KB

Versions: 35

Compression:

Stored size: 1.69 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
      ]

      # 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

35 entries across 35 versions & 1 rubygems

Version Path
alchemy_cms-7.1.12 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.0.15 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.1.11 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.1.10 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.1.9 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.0.14 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.0.13 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.1.8 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.1.7 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.0.12 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.0.11 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.1.6 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.1.5 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.0.10 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.1.4 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.0.9 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.1.3 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.1.2 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.1.1 app/models/alchemy/ingredients/picture.rb
alchemy_cms-7.1.0 app/models/alchemy/ingredients/picture.rb