diff --git a/lib/inline-style.rb b/lib/inline-style.rb index 89a2d65..802e38f 100644 --- a/lib/inline-style.rb +++ b/lib/inline-style.rb @@ -28,8 +28,10 @@ def self.process html, opts = {} def initialize html, opts = {} @stylesheets_path = opts[:stylesheets_path] || ENV['DOCUMENT_ROOT'] || '.' - @html = html - @dom = String === html ? Nokogiri.HTML(html) : html + @ignore = opts[:ignore] || false + @only = opts[:only] || false + @html = html + @dom = String === html ? Nokogiri.HTML(html) : html end def process @@ -79,8 +81,12 @@ def pre_parsed? # Returns parsed CSS def extract_css - @dom.css('style, link[rel=stylesheet]').collect do |node| + css_search = @only ? @only : 'style, link[rel=stylesheet]' + @dom.css(css_search).collect do |node| + + next if @ignore and node.parent.css(@ignore).include? node next unless /^$|screen|all/ === node['media'].to_s + node.remove if node.name == 'style' @@ -89,6 +95,7 @@ def extract_css uri = %r{^https?://} === node['href'] ? node['href'] : File.join(@stylesheets_path, node['href'].sub(/\?.+$/,'')) open(uri).read end + end.join("\n") end