Sha256: 3c88e7ea5da1b651f75f1a3d3f030487c4efce887fd53af36b0bc521c564b7a0
Contents?: true
Size: 1.13 KB
Versions: 16
Compression:
Stored size: 1.13 KB
Contents
# encoding: utf-8 class Image < ::HTML::Proofer::Checkable SCREEN_SHOT_REGEX = /Screen(?: |%20)Shot(?: |%20)\d+-\d+-\d+(?: |%20)at(?: |%20)\d+.\d+.\d+/ def valid_alt_tag? @alt and !@alt.empty? end def terrible_filename? @src =~ SCREEN_SHOT_REGEX end def src @src unless @src.nil? || @src.empty? end def missing_src? !src end end class Images < ::HTML::Proofer::Checks::Check def run @html.css("img").each do |i| img = Image.new i, "image", self next if img.ignore? # screenshot filenames should return because of terrible names next self.add_issue "image has a terrible filename (#{img.src})" if img.terrible_filename? # does the image exist? if img.missing_src? self.add_issue "image has no src attribute" else if img.remote? add_to_external_urls img.src else self.add_issue("internal image #{img.src} does not exist") unless img.exists? end end # check alt tag self.add_issue "image #{img.src} does not have an alt attribute" unless img.valid_alt_tag? end external_urls end end
Version data entries
16 entries across 16 versions & 1 rubygems