Last active
August 29, 2015 14:13
-
-
Save dmerrick/8bec84cf05799507ebf6 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
#!/usr/bin/env ruby | |
# this script takes a URL and verifies that | |
# every css file included loads correctly | |
require 'open-uri' | |
require 'nokogiri' | |
require 'pry' if $DEBUG | |
url = ARGV.shift || 'https://ifttt.com' | |
doc = Nokogiri::HTML(open(url).read) | |
# iterate over every link tag in the doc | |
css_urls = doc.xpath('//link').map do |link_tags| | |
link_tags.attributes['href'].value | |
end.select do |link| | |
# select only the css files | |
link =~ /css$/ | |
end | |
binding.pry if $DEBUG | |
# attempt to open every css file | |
css_urls.each do |css_url| | |
begin | |
open css_url | |
rescue Exception => e | |
# print an error and exit if we have issues | |
puts "Error loading #{css_url}: #{e.message}" | |
puts e.backtrace if $DEBUG | |
exit 2 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment