Class: HTMLProofer::Check

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/html_proofer/check.rb,
lib/html_proofer/check/links.rb,
lib/html_proofer/check/images.rb,
lib/html_proofer/check/favicon.rb,
lib/html_proofer/check/scripts.rb,
lib/html_proofer/check/open_graph.rb

Overview

Mostly handles issue management and collecting of external URLs.

Direct Known Subclasses

Favicon, Images, Links, OpenGraph, Scripts

Defined Under Namespace

Classes: Favicon, Images, Links, OpenGraph, Scripts

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

#blank?, #create_nokogiri, #pluralize

Constructor Details

#initialize(runner, html) ⇒ Check

Returns a new instance of Check.



10
11
12
13
14
15
16
17
# File 'lib/html_proofer/check.rb', line 10

def initialize(runner, html)
  @runner = runner
  @html   = remove_ignored(html)

  @external_urls = {}
  @internal_urls = {}
  @failures = []
end

Instance Attribute Details

#external_urlsObject (readonly)

Returns the value of attribute external_urls.



8
9
10
# File 'lib/html_proofer/check.rb', line 8

def external_urls
  @external_urls
end

#failuresObject (readonly)

Returns the value of attribute failures.



8
9
10
# File 'lib/html_proofer/check.rb', line 8

def failures
  @failures
end

#internal_urlsObject (readonly)

Returns the value of attribute internal_urls.



8
9
10
# File 'lib/html_proofer/check.rb', line 8

def internal_urls
  @internal_urls
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/html_proofer/check.rb', line 8

def options
  @options
end

Class Method Details

.short_nameObject



80
81
82
# File 'lib/html_proofer/check.rb', line 80

def short_name
  name.split("::").last
end

.subchecks(runner_options) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
# 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

Instance Method Details

#add_failure(description, element: nil, line: nil, status: nil, content: nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# 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

#add_to_external_urls(url, line) ⇒ Object



57
58
59
60
61
62
63
# 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

#add_to_internal_urls(url, line) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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?

   = {
    source: url.source,
    filename: url.filename,
    line: line,
    base_url: base_url,
    found: false,
  }
  @internal_urls[url_string] << 
end

#create_element(node) ⇒ Object



19
20
21
# File 'lib/html_proofer/check.rb', line 19

def create_element(node)
  Element.new(@runner, node, base_url: base_url)
end

#runObject

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/html_proofer/check.rb', line 23

def run
  raise NotImplementedError, "HTMLProofer::Check subclasses must implement #run"
end

#short_nameObject



38
39
40
# File 'lib/html_proofer/check.rb', line 38

def short_name
  self.class.name.split("::").last
end