Class: Loofah::Scrubbers::NoFollow

Inherits:
Loofah::Scrubber show all
Defined in:
lib/loofah/scrubbers.rb

Overview

scrub!(:nofollow)

+:nofollow+ adds a rel="nofollow" attribute to all links

   link_farmers_markup = "ohai! <a href='http://www.myswarmysite.com/'>I like your blog post</a>"
   Loofah.fragment(link_farmers_markup).scrub!(:nofollow)
   => "ohai! <a href='http://www.myswarmysite.com/' rel="nofollow">I like your blog post</a>"

Constant Summary

Constants inherited from Loofah::Scrubber

Loofah::Scrubber::CONTINUE, Loofah::Scrubber::STOP

Instance Attribute Summary

Attributes inherited from Loofah::Scrubber

#block, #direction

Instance Method Summary collapse

Methods inherited from Loofah::Scrubber

#append_attribute, #traverse

Constructor Details

#initializeNoFollow

Returns a new instance of NoFollow


203
204
205
# File 'lib/loofah/scrubbers.rb', line 203

def initialize
  @direction = :top_down
end

Instance Method Details

#scrub(node) ⇒ Object


207
208
209
210
211
# File 'lib/loofah/scrubbers.rb', line 207

def scrub(node)
  return CONTINUE unless (node.type == Nokogiri::XML::Node::ELEMENT_NODE) && (node.name == 'a')
  append_attribute(node, 'rel', 'nofollow')
  return STOP
end