class HTMLProofer::Check

Mostly handles issue management and collecting of external URLs.

Attributes

element[R]
external_urls[R]
html[R]
issues[R]
node[R]
options[R]
path[R]
src[R]

Public Class Methods

new(src, path, html, logger, options) click to toggle source
# File lib/html-proofer/check.rb, line 7
def initialize(src, path, html, logger, options)
  @src    = src
  @path   = path
  @html   = remove_ignored(html)
  @logger = logger
  @options = options
  @issues = []
  @external_urls = {}
end
subchecks() click to toggle source
# File lib/html-proofer/check.rb, line 44
def self.subchecks
  classes = []

  ObjectSpace.each_object(Class) do |c|
    next unless c.superclass == self

    classes << c
  end

  classes
end

Public Instance Methods

add_issue(desc, line: nil, status: -1, content: nil) click to toggle source
# File lib/html-proofer/check.rb, line 26
def add_issue(desc, line: nil, status: -1, content: nil)
  @issues << Issue.new(@path, desc, line: line, status: status, content: content)
end
add_path_for_url(url) click to toggle source
# File lib/html-proofer/check.rb, line 36
def add_path_for_url(url)
  if @external_urls[url]
    @external_urls[url] << @path
  else
    @external_urls[url] = [@path]
  end
end
add_to_external_urls(url) click to toggle source
# File lib/html-proofer/check.rb, line 30
def add_to_external_urls(url)
  return if @external_urls[url]

  add_path_for_url(url)
end
blank?(attr) click to toggle source
# File lib/html-proofer/check.rb, line 56
def blank?(attr)
  attr.nil? || attr.empty?
end
create_element(node) click to toggle source
# File lib/html-proofer/check.rb, line 17
def create_element(node)
  @node = node
  Element.new(node, self, @logger)
end
run() click to toggle source
# File lib/html-proofer/check.rb, line 22
def run
  raise NotImplementedError, 'HTMLProofer::Check subclasses must implement #run'
end

Private Instance Methods

remove_ignored(html) click to toggle source
# File lib/html-proofer/check.rb, line 62
def remove_ignored(html)
  html.css('code, pre, tt').each(&:unlink)
  html
end