Sha256: 7a8678381ffbb8b26f67acfa6ec3f8bbcce19f23e1bd02ebc0e01e15a86237ab

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

# encoding: utf-8
require 'net/http'
require 'net/https'
require 'timeout'
require 'uri'
require 'typhoeus'

class HTML::Proofer::Checks

  class Check

    attr_reader :issues, :src, :path, :options, :external_urls, :additional_href_ignores, :additional_alt_ignores

    def initialize(src, path, html, opts={})
      @src    = src
      @path   = path
      @html   = remove_ignored(html)
      @options = opts
      @issues = []
      @additional_href_ignores = @options[:href_ignore]
      @additional_alt_ignores = @options[:alt_ignore]
      @external_urls = {}
    end

    def run
      raise NotImplementedError.new("HTML::Proofer::Check subclasses must implement #run")
    end

    def add_issue(desc, status = -1)
      @issues << Issue.new(@path, desc, status)
    end

    def output_filenames
      Dir[@site.config[:output_dir] + '/**/*'].select{ |f| File.file?(f) }
    end

    def add_to_external_urls(href)
      if @external_urls[href]
        @external_urls[href] << @path
      else
        @external_urls[href] = [@path]
      end
    end

    def self.subclasses
      classes = []

      ObjectSpace.each_object(Class) do |c|
        next unless c.superclass == self
        classes << c
      end

      classes
    end

  private

    def remove_ignored(html)
      html.css("code, pre").each { |node| node.unlink }
      html
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
html-proofer-1.6.0 lib/html/proofer/check.rb
html-proofer-1.5.4 lib/html/proofer/check.rb
html-proofer-1.5.3 lib/html/proofer/check.rb
html-proofer-1.5.2 lib/html/proofer/check.rb
html-proofer-1.5.1 lib/html/proofer/check.rb
html-proofer-1.5.0 lib/html/proofer/check.rb