Class: Links
- Inherits:
-
HTML::Proofer::Checks::Check
- Object
- HTML::Proofer::Checks::Check
- Links
- Defined in:
- lib/html/proofer/checks/links.rb
Instance Attribute Summary
Attributes inherited from HTML::Proofer::Checks::Check
#additional_href_ignores, #hydra, #issues, #options, #path, #src
Instance Method Summary collapse
Methods inherited from HTML::Proofer::Checks::Check
#add_issue, #initialize, #output_filenames, #request_url, subclasses, #validate_url
Constructor Details
This class inherits a constructor from HTML::Proofer::Checks::Check
Instance Method Details
#hash_check(html, href_hash) ⇒ Object
54 55 56 |
# File 'lib/html/proofer/checks/links.rb', line 54 def hash_check(html, href_hash) html.xpath("//*[@id='#{href_hash}']", "//*[@name='#{href_hash}']").length > 0 end |
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/html/proofer/checks/links.rb', line 17 def run @html.css('a').each do |link| link = Link.new link, self return if link.ignore? # is there even a href? return self.add_issue("link has no href attribute") if link.missing_href? # is it even a valid URL? return self.add_issue "#{link.href} is an invalid URL" unless link.valid? # does the file even exist? if link.remote? validate_url link.href, "externally linking to #{link.href}, which does not exist" else self.add_issue "internally linking to #{link.href}, which does not exist" unless link.exists? end # verify the target hash if link.hash if link.remote? #not yet checked elsif link.internal? self.add_issue "linking to internal hash ##{link.hash} that does not exist" unless hash_check @html, link.hash elsif link.external? unless link.exists? self.add_issue "trying to find hash of #{link.href}, but #{link.absolute_path} does not exist" else target_html = HTML::Proofer.create_nokogiri link.absolute_path self.add_issue "linking to #{link.href}, but #{link.hash} does not exist" unless hash_check target_html, link.hash end end end end end |