Module: RailsRinku

Included in:
ActionView::Helpers::TextHelper
Defined in:
lib/rails_rinku.rb

Instance Method Summary collapse

Instance Method Details


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rails_rinku.rb', line 4

def rinku_auto_link(text, *args, &block)
  return '' if text.blank?

  options = args.size == 2 ? {} : args.extract_options!
  unless args.empty?
    options[:link] = args[0] || :all
    options[:html] = args[1] || {}
    options[:skip] = args[2]
  end
  options.reverse_merge!(:link => :all, :html => {})
  text = h(text) unless text.html_safe?

  tag_options_method = if Gem::Version.new(Rails.version) >= Gem::Version.new("5.1")
    # Rails >= 5.1
    tag_builder.method(:tag_options)
  else
    # Rails <= 5.0
    method(:tag_options)
  end

  Rinku.auto_link(
    text,
    options[:link],
    tag_options_method.call(options[:html]),
    options[:skip],
    &block
  ).html_safe
end