Skip to content

Instantly share code, notes, and snippets.

@madr
Created October 15, 2013 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madr/6989389 to your computer and use it in GitHub Desktop.
Save madr/6989389 to your computer and use it in GitHub Desktop.
Validate HTML using ruby
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