Class: ScriptCheck

Inherits:
HTML::Proofer::CheckRunner show all
Defined in:
lib/html/proofer/checks/scripts.rb

Instance Attribute Summary

Attributes inherited from HTML::Proofer::CheckRunner

#alt_ignores, #empty_alt_ignore, #external_urls, #href_ignores, #hydra_opts, #issues, #options, #parallel_opts, #path, #src, #typhoeus_opts, #url_ignores, #validation_opts

Instance Method Summary collapse

Methods inherited from HTML::Proofer::CheckRunner

#add_issue, #add_path_for_url, #add_to_external_urls, checks, #extract_domain_path, #initialize, #new_url_query_values?

Constructor Details

This class inherits a constructor from HTML::Proofer::CheckRunner

Instance Method Details

#runObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/html/proofer/checks/scripts.rb', line 20

def run
  @html.css('script').each do |node|
    script = ScriptCheckable.new(node, self)
    line = node.line

    next if script.ignore?
    next unless script.blank?

    # does the script exist?
    if script.missing_src?
      add_issue('script is empty and has no src attribute', line)
    elsif script.remote?
      add_to_external_urls(script.src, line)
    else
      add_issue("internal script #{script.src} does not exist", line) unless script.exists?
    end
  end

  external_urls
end