Sha256: d4ff05c95391bb61c6078609ed26bce6687be4d1de4ec71ad986d3e90fe05c44

Contents?: true

Size: 1.17 KB

Versions: 25

Compression:

Stored size: 1.17 KB

Contents

module Alchemy
  module Ingredients
    class TextView < BaseView
      attr_reader :disable_link

      delegate :dom_id, :link, :link_title, :link_target,
        to: :ingredient

      # @param ingredient [Alchemy::Ingredient]
      # @param disable_link [Boolean] (false) Whether to disable the link even if the picture has a link.
      # @param html_options [Hash] Options that will be passed to the a tag.
      def initialize(ingredient, disable_link: nil, html_options: {})
        super(ingredient, html_options: html_options)
        @disable_link = settings_value(:disable_link, value: disable_link, default: false)
      end

      def call
        if disable_link?
          dom_id.present? ? anchor : value
        else
          link_to(value, url_for(link), {
            id: dom_id.presence,
            title: link_title,
            target: ((link_target == "blank") ? "_blank" : nil),
            data: {link_target: link_target}
          }.merge(html_options))
        end
      end

      private

      def anchor
        content_tag(:a, value, {id: dom_id}.merge(html_options))
      end

      def disable_link?
        link.blank? || disable_link
      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/text_view.rb
alchemy_cms-7.1.6 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.1.5 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.0.10 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.1.4 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.0.9 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.1.3 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.1.2 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.1.1 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.1.0 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.1.0.pre.rc1 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.1.0.pre.b2 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.1.0.pre.b1 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.0.8 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.0.7 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.0.6 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.0.5 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.0.4 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.0.3 app/components/alchemy/ingredients/text_view.rb
alchemy_cms-7.0.2 app/components/alchemy/ingredients/text_view.rb