Class: Writeup::Filters::AbsoluteLinks

Inherits:
HTML::Pipeline::Filter
  • Object
show all
Defined in:
lib/writeup/filters/absolute_links.rb

Instance Method Summary collapse

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/writeup/filters/absolute_links.rb', line 5

def call
  doc.search("a").each do |element|
    href = (element['href'] || '').strip
    next if href.nil? || href.blank?
    unless href.start_with?('http') || href.start_with?('//') || href.start_with?('#')
      element['href'] = URI.join(link_subpage_url, href).to_s
    end
  end
  doc
end

Private: the relative url you want to use



17
18
19
# File 'lib/writeup/filters/absolute_links.rb', line 17

def link_subpage_url
  context[:link_subpage_url] or raise "Missing context :link_subpage_url for #{self.class.name}"
end