Class: Ra11y::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/ra11y/site.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Site

Returns a new instance of Site.



6
7
8
# File 'lib/ra11y/site.rb', line 6

def initialize(path)
  @path = File.expand_path(path, Dir.pwd)
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/ra11y/site.rb', line 4

def path
  @path
end

Instance Method Details

#errorsObject



50
51
52
# File 'lib/ra11y/site.rb', line 50

def errors
  @errors ||= results_by_type("errors")
end

#html_filesObject



42
43
44
# File 'lib/ra11y/site.rb', line 42

def html_files
  @files ||= Parallel.map(paths) { |p| Ra11y::HtmlFile.new(p) }
end

#inspectObject



62
63
64
# File 'lib/ra11y/site.rb', line 62

def inspect
  "#<Ra11y::HtmlFile errors=#{errors.count} warnings=#{warnings.count} notices=#{notices.count}>"
end

#noticesObject



58
59
60
# File 'lib/ra11y/site.rb', line 58

def notices
  @notices ||= results_by_type("notices")
end

#pathsObject



37
38
39
40
# File 'lib/ra11y/site.rb', line 37

def paths
  pattern = File.join(path, '**', "*html")
  Dir.glob(pattern).select { |fn| File.file? fn }
end

#perfect?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/ra11y/site.rb', line 46

def perfect?
  errors.empty? && warnings.empty?
end

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ra11y/site.rb', line 10

def run
  puts "Site: #{path}"
  puts "Running Ra11y on #{paths.count} files..."
  puts "Errors: #{errors.count}, Warnings: #{warnings.count}, Notices: #{notices.count}"

  html_files.each do |file|

    puts "#{file.path} (Errors: #{file.errors.count}, Warnings: #{file.warnings.count}, Notices: #{file.notices.count}):".blue

    file.results.each do |result|
      output = "#{result.type.capitalize}: #{result}"

      if result.error?
        output = output.red
      elsif result.warning?
        output = output.yellow
      else
        output = output.white
      end

      puts "  * #{output}"
    end
  end

  exit 1 unless perfect?
end

#warningsObject



54
55
56
# File 'lib/ra11y/site.rb', line 54

def warnings
  @warnings ||= results_by_type("warnings")
end