Class: HTMLProofer::Check
- Inherits:
-
Object
- Object
- HTMLProofer::Check
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.
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
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_urls ⇒ Object
Returns the value of attribute external_urls.
8
9
10
|
# File 'lib/html_proofer/check.rb', line 8
def external_urls
@external_urls
end
|
#failures ⇒ Object
Returns the value of attribute failures.
8
9
10
|
# File 'lib/html_proofer/check.rb', line 8
def failures
@failures
end
|
#internal_urls ⇒ Object
Returns the value of attribute internal_urls.
8
9
10
|
# File 'lib/html_proofer/check.rb', line 8
def internal_urls
@internal_urls
end
|
#options ⇒ Object
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_name ⇒ Object
82
83
84
|
# File 'lib/html_proofer/check.rb', line 82
def short_name
name.split("::").last
end
|
.subchecks(runner_options) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/html_proofer/check.rb', line 68
def subchecks(runner_options)
checks = ObjectSpace.each_object(Class).select do |klass|
klass < self
end
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
37
|
# 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,
element: element,
)
end
|
#add_to_external_urls(url, element) ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/html_proofer/check.rb', line 59
def add_to_external_urls(url, element)
url_string = url.to_s
@external_urls[url_string] = [] if @external_urls[url_string].nil?
@external_urls[url_string] << { filename: url.filename, line: element.line, element: element }
end
|
#add_to_internal_urls(url, element) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/html_proofer/check.rb', line 43
def add_to_internal_urls(url, element)
url_string = url.raw_attribute
@internal_urls[url_string] = [] if @internal_urls[url_string].nil?
metadata = {
source: url.source,
filename: url.filename,
line: element.line,
base_url: base_url,
found: false,
element: element,
}
@internal_urls[url_string] << metadata
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
|
#run ⇒ Object
23
24
25
|
# File 'lib/html_proofer/check.rb', line 23
def run
raise NotImplementedError, "HTMLProofer::Check subclasses must implement #run"
end
|
#short_name ⇒ Object
39
40
41
|
# File 'lib/html_proofer/check.rb', line 39
def short_name
self.class.name.split("::").last
end
|