Sha256: 300e980485254577fbbe59c540956d1f1ffe261ee73cf3c954dd91834d47d123

Contents?: true

Size: 988 Bytes

Versions: 5

Compression:

Stored size: 988 Bytes

Contents

# encoding: utf-8

class Images < ::HTML::Proofer::Checks::Check

  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
          self.add_issue("#{@path}".blue + ": external image #{src} does not exist") unless validate_url(src)
        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\ Shot\ \d+-\d+-\d+ at \d+.\d+.\d+/

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
html-proofer-0.0.8 lib/html/proofer/checks/images.rb
html-proofer-0.0.7 lib/html/proofer/checks/images.rb
html-proofer-0.0.6 lib/html/proofer/checks/images.rb
html-proofer-0.0.5 lib/html/proofer/checks/images.rb
html-proofer-0.0.4 lib/html/proofer/checks/images.rb