Skip to content

Instantly share code, notes, and snippets.

@dmerrick
Last active August 29, 2015 14:13
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 dmerrick/8bec84cf05799507ebf6 to your computer and use it in GitHub Desktop.
Save dmerrick/8bec84cf05799507ebf6 to your computer and use it in GitHub Desktop.
#!/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