Sha256: 5a850ef171a1227fbed01324aba0b082c976813b1d0c5df9b61a9b5cb3cb4ce7

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'roger/test'
require File.dirname(__FILE__) + "/w3c_validator"

module RogerW3cvalidator
  class Test

    def initialize(options={})
      @options = {
        :match => ["html/**/*.html"],
        :skip => []
      }
      @options.update(options) if options            
    end

    def call(test, options={})
      options = {}.update(@options).update(options)

      test.log(self, "Validating all files matching #{options[:match].inspect}")

      success = true
      test.get_files(options[:match], options[:skip]).each do |file_path|
        validator = W3CValidator.new(File.read(file_path))
        validator.validate!
        if !validator.valid
          test.log(self, "#{file_path} is invalid (errors: #{validator.errors}, warnings: #{validator.warnings})") do
            validator.response["messages"].each do |message|
              test.debug(self, message["message"])
            end
          end
          success = false
        else
          test.debug(self, "#{file_path} is valid")
        end
      end

      success
    end

  end
end

Roger::Test.register :w3cvalidator, RogerW3cvalidator::Test

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roger_w3cvalidator-0.1.0 lib/roger_w3cvalidator/test.rb