Class: Images

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

Instance Attribute Summary

Attributes inherited from HTML::Proofer::Checks::Check

#hydra, #issues

Instance Method Summary collapse

Methods inherited from HTML::Proofer::Checks::Check

#add_issue, #external_href?, #ignore_href?, #initialize, #output_filenames, #request_url, subclasses, #validate_url

Constructor Details

This class inherits a constructor from HTML::Proofer::Checks::Check

Instance Method Details

#runObject


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/html/proofer/checks/images.rb', line 5

def run
  @html.css('img').each do |img|
    src = img['src']

    # check image sources
    if src && src.length > 0
      if !external_href?(src)
        self.add_issue("#{@path}".blue + ": internal image #{src} does not exist") unless src[0] != "/" and File.exist?(File.join(File.dirname(@path), src))
      else
        validate_url(src, "#{@path}".blue + ": external image #{src} does not exist")
      end
    else
      self.add_issue("#{@path}".blue + ": image has no src attribute")
    end

    # check alt tag
    self.add_issue("#{@path}".blue + ": image #{src} does not have an alt attribute") unless img['alt'] and !img['alt'].empty?
    
    screenShotRegExp = /Screen(?: |%20)Shot(?: |%20)\d+-\d+-\d+(?: |%20)at(?: |%20)\d+.\d+.\d+/

    if src =~ screenShotRegExp
      self.add_issue("#{@path}".blue + ": image has a terrible filename (#{src})")
    end
  end
end