Skip to content

Instantly share code, notes, and snippets.

@juanghurtado
Forked from mamuso/wcag.rake
Created January 24, 2010 21:35
Show Gist options
  • Save juanghurtado/285465 to your computer and use it in GitHub Desktop.
Save juanghurtado/285465 to your computer and use it in GitHub Desktop.
# #WCAG Basic wadus
#
# Using http://achecker.ca/checker/index.php
require 'raakt'
desc "WCAG basic wadus"
task :wcag_validate do
# perform a setup of all our variables
setup
wcag_validate '.html'
end
private
# Colorize the output :)
def colorize(text, color_code); "#{color_code}#{text}\e[0m"; end
def red(text); colorize(text, "\e[31m"); end
def green(text); colorize(text, "\e[32m"); end
# Reads the yaml with the configuration of the project to get always the correct
# output_dir and initializes the validator
def setup
@url_validator = "http://www.achecker.ca/checker/index.php"
@config = YAML.load_file("config.yaml")
end
# Method to validate calling to the w3c_validators methods
def wcag_validate ext
files(@config['output_dir'], true, ext).each do |file|
f = File.new(file)
raakttest = Raakt::Test.new(f.read)
result = raakttest.all
if result.length > 0
puts "\t #{red(file)} => #{result}"
else
puts "\t #{green(file)}"
end
end
end
# From nanoc
# # Returns a list of all files in +dir+, ignoring any unwanted files (files
# that end with '~', '.orig', '.rej' or '.bak').
#
# +recursively+:: When +true+, finds files in +dir+ as well as its
# subdirectories; when +false+, only searches +dir+
# itself.
def files(dir, recursively, ext = '')
glob = File.join([dir] + (recursively ? [ "**", "*#{ext}" ] : [ "*#{ext}" ]))
Dir[glob].reject { |f| File.directory?(f) or f =~ /(~|\.orig|\.rej|\.bak)$/ }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment