Sha256: 6a3a12eb4f8f588c479594b87264b45e01ad9d9cab0266118a83286fe9a4a92f

Contents?: true

Size: 567 Bytes

Versions: 2

Compression:

Stored size: 567 Bytes

Contents

# frozen_string_literal: true

require 'uri'
require 'rinku'
require 'rexml/document'

module AutoHtml
  # Link filter
  class Link
    def initialize(target: nil, rel: nil)
      @target = target
      @rel = rel
    end

    def call(text)
      Rinku.auto_link(text, :all, attributes)
    end

    private

    def attributes
      [target_attr, rel_attr].compact.join(' ') unless [target_attr, rel_attr].compact.empty?
    end

    def rel_attr
      %(rel="#{@rel}") if @rel
    end

    def target_attr
      %(target="#{@target}") if @target
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
auto_html-2.1.0 lib/auto_html/link.rb
auto_html-2.0.2 lib/auto_html/link.rb