Class: Rack::Relations::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/relations/processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(safelist_domains:) ⇒ Processor

Returns a new instance of Processor.



9
10
11
# File 'lib/rack/relations/processor.rb', line 9

def initialize(safelist_domains:)
  @safelist_domains = safelist_domains
end

Instance Attribute Details

#safelist_domainsObject

TODO rename safelist_domains, might have other safelists?



7
8
9
# File 'lib/rack/relations/processor.rb', line 7

def safelist_domains
  @safelist_domains
end

Instance Method Details

#perform(body) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# 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