class HTMLProofer::Check
Mostly handles issue management and collecting of external URLs.
Attributes
Public Class Methods
Source
# File lib/html_proofer/check.rb, line 10 def initialize(runner, html) @runner = runner @html = remove_ignored(html) @external_urls = {} @internal_urls = {} @failures = [] end
Source
# File lib/html_proofer/check.rb, line 80 def short_name name.split("::").last end
Source
# File lib/html_proofer/check.rb, line 66 def subchecks(runner_options) # grab all known checks checks = ObjectSpace.each_object(Class).select do |klass| klass < self end # remove any checks not explicitly included checks.each_with_object([]) do |check, arr| next unless runner_options[:checks].include?(check.short_name) arr << check end end
Public Instance Methods
Source
# File lib/html_proofer/check.rb, line 27 def add_failure(description, element: nil, line: nil, status: nil, content: nil) @failures << Failure.new( @runner.current_filename, short_name, description, line: element.nil? ? line : element.line, status: status, content: element.nil? ? content : element.content, ) end
Source
# File lib/html_proofer/check.rb, line 57 def add_to_external_urls(url, line) url_string = url.to_s @external_urls[url_string] = [] if @external_urls[url_string].nil? @external_urls[url_string] << { filename: url.filename, line: line } end
Source
# File lib/html_proofer/check.rb, line 42 def add_to_internal_urls(url, line) url_string = url.raw_attribute @internal_urls[url_string] = [] if @internal_urls[url_string].nil? metadata = { source: url.source, filename: url.filename, line: line, base_url: base_url, found: false, } @internal_urls[url_string] << metadata end
Source
# File lib/html_proofer/check.rb, line 19 def create_element(node) Element.new(@runner, node, base_url: base_url) end
Source
# File lib/html_proofer/check.rb, line 23 def run raise NotImplementedError, "HTMLProofer::Check subclasses must implement #run" end
Source
# File lib/html_proofer/check.rb, line 38 def short_name self.class.name.split("::").last end
Private Instance Methods
Source
# File lib/html_proofer/check.rb, line 85 def base_url return @base_url if defined?(@base_url) return (@base_url = "") if (base = @html.at_css("base")).nil? @base_url = base["href"] end
Source
# File lib/html_proofer/check.rb, line 93 def remove_ignored(html) return if html.nil? html.css("code, pre, tt").each(&:unlink) html end