Created
October 15, 2013 10:05
-
-
Save madr/6989389 to your computer and use it in GitHub Desktop.
Validate HTML using ruby
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
require "rubygems" | |
require 'living-validator' | |
require 'uri' | |
url = ARGV.first | |
files = ARGV.slice(1, 9999) | |
stop_at = files.length | |
i = 1 | |
def colorize(text, color_code) | |
"\e[#{color_code}m#{text}\e[0m" | |
end | |
def red(text); colorize(text, 31); end | |
def green(text); colorize(text, 32); end | |
valid = true | |
files.each do |file| | |
puts '[%d/%d] %s%s:' % [i, stop_at, url, file] | |
i += 1 | |
result = LivingValidator::Validator.check '%s%s' % [url, file] | |
unless result == false | |
if result.errorCount > 0 | |
result.errors.each do |error| | |
puts red("%d:%d %s" % [error["lastLine"], error["lastColumn"], error["message"]]) | |
end | |
valid = false | |
else | |
puts green "valid" | |
end | |
else | |
puts red("FAILED") | |
end | |
end | |
exit 1 unless valid == true | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment