Class: Ra11y::Site
- Inherits:
-
Object
- Object
- Ra11y::Site
- Defined in:
- lib/ra11y/site.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #errors ⇒ Object
- #html_files ⇒ Object
-
#initialize(path) ⇒ Site
constructor
A new instance of Site.
- #inspect ⇒ Object
- #notices ⇒ Object
- #paths ⇒ Object
- #perfect? ⇒ Boolean
- #run ⇒ Object
- #warnings ⇒ Object
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.(path, Dir.pwd) end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/ra11y/site.rb', line 4 def path @path end |
Instance Method Details
#errors ⇒ Object
50 51 52 |
# File 'lib/ra11y/site.rb', line 50 def errors @errors ||= results_by_type("errors") end |
#html_files ⇒ Object
42 43 44 |
# File 'lib/ra11y/site.rb', line 42 def html_files @files ||= Parallel.map(paths) { |p| Ra11y::HtmlFile.new(p) } end |
#inspect ⇒ Object
62 63 64 |
# File 'lib/ra11y/site.rb', line 62 def inspect "#<Ra11y::HtmlFile errors=#{errors.count} warnings=#{warnings.count} notices=#{notices.count}>" end |
#notices ⇒ Object
58 59 60 |
# File 'lib/ra11y/site.rb', line 58 def notices @notices ||= results_by_type("notices") end |
#paths ⇒ Object
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
46 47 48 |
# File 'lib/ra11y/site.rb', line 46 def perfect? errors.empty? && warnings.empty? end |
#run ⇒ Object
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 |
#warnings ⇒ Object
54 55 56 |
# File 'lib/ra11y/site.rb', line 54 def warnings @warnings ||= results_by_type("warnings") end |