class RailsGuides::Validator - rails-4.2.4 Documentation

# class RailsGuides::Validator

### Public Instance Methods

validate() click to toggle source

    # File guides/w3c_validator.rb, line 35
    def validate
      validator = MarkupValidator.new
      STDOUT.sync = true
      errors_on_guides = {}

      guides_to_validate.each do |f|
        begin
          results = validator.validate_file(f)
        rescue Exception => e
          puts "\nCould not validate #{f} because of #{e}"
          next
        end

        if results.validity
          print "."
        else
          print "E"
          errors_on_guides[f] = results.errors
        end
      end

      show_results(errors_on_guides)
    end

### Private Instance Methods

guides_to_validate() click to toggle source

    # File guides/w3c_validator.rb, line 60
    def guides_to_validate
      guides = Dir["./output/*.html"]
      guides.delete("./output/layout.html")
      guides.delete("./output/_license.html")
      guides.delete("./output/_welcome.html")
      ENV.key?('ONLY') ? select_only(guides) : guides
    end

select_only(guides) click to toggle source

    # File guides/w3c_validator.rb, line 68
    def select_only(guides)
      prefixes = ENV['ONLY'].split(",").map(&:strip)
      guides.select do |guide|
        prefixes.any? {|p| guide.start_with?("./output/#{p}")}
      end
    end

show_results(error_list) click to toggle source

    # File guides/w3c_validator.rb, line 75
    def show_results(error_list)
      if error_list.size == 0
        puts "\n\nAll checked guides validate OK!"
      else
        error_summary = error_detail = ""

        error_list.each_pair do |name, errors|
          error_summary += "\n  #{name}"
          error_detail += "\n\n  #{name} has #{errors.size} validation error(s):\n"
          errors.each do |error|
            error_detail += "\n    "+error.to_s.delete("\n")
          end
        end

        puts "\n\nThere are #{error_list.size} guides with validation errors:\n" + error_summary
        puts "\nHere are the detailed errors for each guide:" + error_detail
      end
    end