class Rack::Relations::Processor
Attributes
safelist_domains[RW]
TODO rename safelist_domains
, might have other safelists?
Public Class Methods
new(safelist_domains:)
click to toggle source
# File lib/rack/relations/processor.rb, line 9 def initialize(safelist_domains:) @safelist_domains = safelist_domains end
Public Instance Methods
perform(body)
click to toggle source
# File lib/rack/relations/processor.rb, line 13 def perform(body) doc = parsed_body(body.join("\n")) doc.css("a[href]").each do |node| anchor = Anchor.new(node, safelist_domains: safelist_domains) next if anchor.safe? node.set_attribute("rel", anchor.modified_rel) end [doc.to_html] end
Private Instance Methods
parsed_body(text)
click to toggle source
# File lib/rack/relations/processor.rb, line 26 def parsed_body(text) if text =~ /<!DOCTYPE/i Nokogiri::HTML(text) else Nokogiri::HTML.fragment(text) end end