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



74
75
76
# File 'lib/html_proofer/check.rb', line 74

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

.subchecks(runner_options) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/html_proofer/check.rb', line 60

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, line: nil, status: nil, content: nil) ⇒ Object



27
28
29
30
# File 'lib/html_proofer/check.rb', line 27

def add_failure(description, line: nil, status: nil, content: nil)
  @failures << Failure.new(@runner.current_filename, short_name, description, line: line, status: status,
    content: content)
end

#add_to_external_urls(url, line) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/html_proofer/check.rb', line 51

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: @runner.current_filename, line: line }
end

#add_to_internal_urls(url, line) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/html_proofer/check.rb', line 36

def add_to_internal_urls(url, line)
  url_string = url.raw_attribute

  @internal_urls[url_string] = [] if @internal_urls[url_string].nil?

   = {
    source: @runner.current_source,
    filename: @runner.current_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



32
33
34
# File 'lib/html_proofer/check.rb', line 32

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