Created
May 12, 2011 00:16
-
-
Save pguillory/967683 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Returns parsed CSS | |
def extract_css | |
css = @dom.css('style, link[rel=stylesheet]').collect do |node| | |
next unless /^$|screen|all/ === node['media'].to_s | |
node.remove | |
if node.name == 'style' | |
node.content | |
else | |
uri = %r{^https?://} === node['href'] ? node['href'] : File.join(@stylesheets_path, node['href'].sub(/\?.+$/,'')) | |
open(uri).read | |
end | |
end.join("\n") | |
css.gsub!(/\}[^{}]*\:[^{}]*\{[^{}]*\}/, "}\n /* HOVER */\n") | |
css.gsub!(/\}[^{}]*\:[^{}]*\{[^{}]*\}/, "}\n /* HOVER */\n") | |
css | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment