Created
January 17, 2010 01:20
-
-
Save mamuso/279128 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# #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