Sha256: 6ad2990f7aa9e07de9a3d1a6800a99c1b8caafb277570e8791182f84362cfa7f

Contents?: true

Size: 947 Bytes

Versions: 21

Compression:

Stored size: 947 Bytes

Contents

module Nexmo
  module OAS
    module Renderer
      module Filters
        class ExternalLink < Banzai::Filter
          def call(input)
            @input = input

            document.css('a').each_with_index do |link, _index|
              if link['href']&.start_with?('http') && link['class'] && !link['class'].include?('no-external-marker')
                link['target'] = '_blank'
                if link.css('svg').empty?
                  link.add_child <<~HEREDOC
                    &nbsp;<svg class="Vlt-icon Vlt-icon--smaller Vlt-icon--text-bottom Vlt-blue-dark"><use xlink:href="/assets/symbol/volta-icons.svg#Vlt-icon-open"></use></svg>
                  HEREDOC
                end
              end
            end

            @document.to_html
          end

          private

          def document
            @document ||= Nokogiri::HTML::DocumentFragment.parse(@input)
          end
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
nexmo-oas-renderer-0.7.1 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.7.0 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.6.6 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.6.5 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.6.4 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.6.3 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.6.2 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.6.1 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.5.6 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.5.5 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.5.4 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.5.2 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.5.1 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.5.0 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.4.1 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.4.0 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.2.1 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.2.0 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.1.2 lib/nexmo/oas/renderer/filters/external_link.rb
nexmo-oas-renderer-0.1.1 lib/nexmo/oas/renderer/filters/external_link.rb