Sha256: f695ef8166c5dd32d1c4ca9f3940e1e5a3d11077d69439baf70a7e985ef88fd6

Contents?: true

Size: 1.09 KB

Versions: 25

Compression:

Stored size: 1.09 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)
        )
      end

      def render?
        !attachment.nil?
      end

      private

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

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
alchemy_cms-7.0.11 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.1.6 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.1.5 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.0.10 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.1.4 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.0.9 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.1.3 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.1.2 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.1.1 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.1.0 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.1.0.pre.rc1 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.1.0.pre.b2 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.1.0.pre.b1 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.0.8 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.0.7 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.0.6 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.0.5 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.0.4 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.0.3 app/components/alchemy/ingredients/file_view.rb
alchemy_cms-7.0.2 app/components/alchemy/ingredients/file_view.rb