-
-
Save flashingpumpkin/9074483 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 | |
require "rubygems" | |
require "spidr" | |
require "open-uri" | |
=begin | |
= CSS snowball | |
Rolls through your site, picking up style attributes and making you | |
a new stylesheet. Once you've got your stylesheet, run it through | |
something like http://www.cleancss.com/ to clean it up. | |
Outputs a CSS file and an instruction sheet. | |
=end | |
if ARGV.empty? | |
puts "CSS-Snowball - rolls through your site picking up styles" | |
puts "Usage: #{__FILE__} http://www.example > output.css" | |
exit | |
end | |
count = 1 | |
styles = [] | |
Spidr.site(ARGV[0]) do |spider| | |
spider.every_page do |page| | |
#url = page.url | |
body = page.search('body').first | |
if body.nil? | |
# probably not an HTML file, or a malformed one | |
next | |
else | |
style_attributes = body.search('[style]') | |
style_attributes.each do |s| | |
styles << s['style'].chomp(' ') | |
end | |
end | |
end | |
end | |
styles.uniq.each do |s| | |
puts ".snowball#{count} {" | |
s.split(';').each do |att| | |
puts " #{att};" | |
end | |
puts "}\n" | |
count = count + 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment