Sha256: 353cddc296145b8edf45d9471dabfdecded6f51f05abc183056078e461f66c55

Contents?: true

Size: 1.1 KB

Versions: 31

Compression:

Stored size: 1.1 KB

Contents

module Alchemy
  module Ingredients
    class FileView < BaseView
      delegate :attachment, to: :ingredient

      # @param ingredient [Alchemy::Ingredient]
      # @param link_text [String] The link text. If not given, the ingredients link_text setting or the attachments name will be used.
      # @param html_options [Hash] Options that will be passed to the a tag.
      def initialize(ingredient, link_text: nil, html_options: {})
        super(ingredient, html_options: html_options)
        @link_text = settings_value(:link_text, value: link_text, default: attachment&.name)
      end

      def call
        link_to(
          link_text,
          attachment.url(
            download: true,
            name: attachment.slug,
            format: attachment.suffix
          ),
          {
            class: ingredient.css_class.presence,
            title: ingredient.title.presence
          }.merge(html_options)
        ).html_safe
      end

      def render?
        !attachment.nil?
      end

      private

      def link_text
        ingredient.link_text.presence || @link_text
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
alchemy_cms-7.4.2 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.3.6 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.2.9 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.4.1 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.4.0 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.3.5 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.2.8 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.1.13 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.0.16 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.3.4 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.3.3 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.3.2 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.2.7 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.3.1 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.3.0 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.2.6 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.2.5 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.1.12 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.0.15 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.2.4 app/components/alchemy/ingredients/file_view.rb