Sha256: 00b1b25987c38b9891c3dae3e5169317a3af401726f2b80ad359d5d76b65299e

Contents?: true

Size: 1.32 KB

Versions: 25

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Maglev
  module Content
    class Link < Base
      def href
        link[:href]
      end

      def text
        link[:text]
      end

      def with_text?
        !!setting.options[:with_text]
      end

      def open_new_window?
        !!link[:open_new_window]
      end

      def target_blank
        open_new_window? ? '_blank' : nil
      end

      def to_s
        href
      end

      def tag(view_context, options = {}, &block)
        captured_content = view_context.capture(&block) if block_given?
        view_context.link_to(
          captured_content || text_tag(view_context),
          href,
          {
            data: (options.delete(:data) || {}).merge(tag_data),
            target: target_blank
          }.merge(options)
        )
      end

      private

      def link
        @link ||= if content.is_a?(String)
                    { href: content, link_type: 'url', open_new_window: false }
                  elsif content
                    content
                  else
                    {}
                  end.symbolize_keys
      end

      # rubocop:disable Rails/OutputSafety
      def text_tag(view_context)
        view_context.tag.span(text, **{ data: { maglev_id: "#{tag_id}.text" } }).html_safe
      end
      # rubocop:enable Rails/OutputSafety
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
maglevcms-1.8.0 app/components/maglev/content/link.rb
maglevcms-1.7.3 app/components/maglev/content/link.rb
maglevcms-1.7.2 app/components/maglev/content/link.rb
maglevcms-1.7.1 app/components/maglev/content/link.rb
maglevcms-1.7.0 app/components/maglev/content/link.rb
maglevcms-1.6.1 app/components/maglev/content/link.rb
maglevcms-1.6.0 app/components/maglev/content/link.rb
maglevcms-1.5.1 app/components/maglev/content/link.rb
maglevcms-1.4.0 app/components/maglev/content/link.rb
maglevcms-1.3.0 app/components/maglev/content/link.rb
maglevcms-1.2.2 app/components/maglev/content/link.rb
maglevcms-1.2.1 app/components/maglev/content/link.rb
maglevcms-1.2.0 app/components/maglev/content/link.rb
maglevcms-1.1.7 app/components/maglev/content/link.rb
maglevcms-1.1.6 app/components/maglev/content/link.rb
maglevcms-1.1.5 app/components/maglev/content/link.rb
maglevcms-1.1.4 app/components/maglev/content/link.rb
maglevcms-1.1.3 app/components/maglev/content/link.rb
maglevcms-1.1.2 app/components/maglev/content/link.rb
maglevcms-1.1.1 app/components/maglev/content/link.rb