Skip to content

Instantly share code, notes, and snippets.

@pguillory
Created May 12, 2011 00:16
Show Gist options
  • Save pguillory/967683 to your computer and use it in GitHub Desktop.
Save pguillory/967683 to your computer and use it in GitHub Desktop.
# 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