Class: Nanoc3::Extra::Validators::W3C

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoc3/extra/validators/w3c.rb

Overview

A validator that uses the W3C web service to validate HTML and CSS files.

Instance Method Summary collapse

Constructor Details

#initialize(dir, types) ⇒ W3C

Returns a new instance of W3C.

Parameters:

  • dir (String)

    The directory that will be searched for HTML and/or CSS files to validate

  • types (Array<Symbol>)

    A list of types to check. Allowed types are ‘:html` and `:css`.



13
14
15
16
# File 'lib/nanoc3/extra/validators/w3c.rb', line 13

def initialize(dir, types)
  @dir   = dir
  @types = types
end

Instance Method Details

#runvoid

This method returns an undefined value.

Starts the validator. The results will be printed to stdout.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nanoc3/extra/validators/w3c.rb', line 21

def run
  # Load validator
  require 'w3c_validators'

  # Find all files
  filenames = []
  extensions = types_to_extensions(@types)
  extensions.each { |extension| filenames.concat(Dir[@dir + '/**/*.' + extension]) }

  # Validate each file
  filenames.each do |filename|
    validation_started(filename)

    extension = File.extname(filename)[1..-1]
    results = validator_for(extension).validate_file(filename)

    validation_ended(filename, results.errors)
  end
end