Skip to content

Instantly share code, notes, and snippets.

@youpy
Created October 16, 2011 16:35
Show Gist options
  • Save youpy/1291119 to your computer and use it in GitHub Desktop.
Save youpy/1291119 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# OSX only
%w/ubygems grope open-uri term\/ansicolor/.each {|g| require g }
COLORS = {
'warning' => :yellow,
'error' => :red
}
def main
filename_or_url = ARGV.shift
env = Grope::Env.new
env.load 'http://csslint.net/'
lint = env.document.getElementById('lint')
input = env.document.getElementById('input')
lines = open(filename_or_url).readlines
input.value = lines.join('')
js = env.eval('return Grope')
js.click(lint)
loop do
if env.document.querySelectorAll('table#errorView td').size > 0
break
end
env.wait(1)
end
summary = env.document.querySelector('.resultsSummary .summary').textContent
puts summary
puts
env.document.querySelectorAll('table#errorView #errors tr').each do |tr|
nodes = tr.childNodes
type = nodes[0].firstChild.alt
line = nodes[1].textContent
desc = nodes[4].firstChild.textContent
puts Term::ANSIColor.send(COLORS[type], '%s:%s %s' % [type, line, desc])
if line =~ /^\d+$/
puts '> %s' % lines[line.to_i - 1]
end
puts
end
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment