Class: ImageCheck
Constant Summary
collapse
- SCREEN_SHOT_REGEX =
/Screen(?: |%20)Shot(?: |%20)\d+-\d+-\d+(?: |%20)at(?: |%20)\d+.\d+.\d+/
Instance Attribute Summary
#element, #external_urls, #issues, #node, #options, #path, #src
Instance Method Summary
collapse
#add_issue, #add_path_for_url, #add_to_external_urls, #blank?, #create_element, #initialize, subchecks
Instance Method Details
#empty_alt_tag? ⇒ Boolean
4
5
6
|
# File 'lib/html-proofer/check/images.rb', line 4
def empty_alt_tag?
@img.alt.strip.empty?
end
|
#missing_src? ⇒ Boolean
12
13
14
|
# File 'lib/html-proofer/check/images.rb', line 12
def missing_src?
blank?(@img.url)
end
|
#run ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/html-proofer/check/images.rb', line 16
def run
@html.css('img').each do |node|
@img = create_element(node)
line = node.line
next if @img.ignore?
if terrible_filename?
add_issue("image has a terrible filename (#{@img.url})", line: line)
next
end
if missing_src?
add_issue('image has no src or srcset attribute', line: line)
else
if @img.remote?
add_to_external_urls(@img.url, line)
elsif !@img.exists?
add_issue("internal image #{@img.url} does not exist", line: line)
end
end
if @img.alt.nil? || (empty_alt_tag? && !@img.ignore_empty_alt?)
add_issue("image #{@img.url} does not have an alt attribute", line: line)
end
end
external_urls
end
|
#terrible_filename? ⇒ Boolean
8
9
10
|
# File 'lib/html-proofer/check/images.rb', line 8
def terrible_filename?
@img.url =~ SCREEN_SHOT_REGEX
end
|