Class: RogerW3cvalidator::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/roger_w3cvalidator/test.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Test

Returns a new instance of Test.



7
8
9
10
11
12
13
# File 'lib/roger_w3cvalidator/test.rb', line 7

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

Instance Method Details

#call(test, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/roger_w3cvalidator/test.rb', line 15

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