Class: ImageCheck

Inherits:
HTML::Proofer::CheckRunner show all
Defined in:
lib/html/proofer/checks/images.rb

Instance Attribute Summary

Attributes inherited from HTML::Proofer::CheckRunner

#alt_ignores, #external_urls, #href_ignores, #hydra_opts, #issues, #options, #parallel_opts, #path, #src, #typhoeus_opts

Instance Method Summary collapse

Methods inherited from HTML::Proofer::CheckRunner

#add_issue, #add_to_external_urls, checks, #initialize

Constructor Details

This class inherits a constructor from HTML::Proofer::CheckRunner

Instance Method Details

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/html/proofer/checks/images.rb', line 26

def run
  @html.css('img').each do |i|
    img = ImageCheckable.new i, self

    next if img.ignore?

    # screenshot filenames should return because of terrible names
    next add_issue("image has a terrible filename (#{img.src})", i.line) if img.terrible_filename?

    # does the image exist?
    if img.missing_src?
      add_issue('image has no src or srcset attribute', i.line)
    else
      if img.remote?
        add_to_external_urls img.src
      else
        add_issue("internal image #{img.src} does not exist", i.line) unless img.exists?
      end
    end

    # check alt tag
    add_issue("image #{img.src} does not have an alt attribute", i.line) unless img.valid_alt_tag?
  end

  external_urls
end