premailer/css_parser

Media query should reset to :all

Closed this issue · 2 comments

After a @media block, the next RuleSet’s :media_types is empty when it should be [:all].

$: << 'lib'
require 'css_parser'

css = <<CSS
body { background: red; }
@media screen {
  body { background: green; }
}
body { background: blue; }'
CSS

parser = CssParser::Parser.new
parser.load_string! css

p parser.instance_variable_get('@rules').map { |r| r[:media_types] }
# Expected: [[:all], [:screen], [:all]]
# Actual: [[:all], [:screen], []]

p parser.rules_by_media_query
# Expected: {:all=>[body { background: red; }, body { background: blue; }], :screen=>[body { background: green; }]}
# Actual: {:all=>[body { background: red; }], :screen=>[body { background: green; }]}

I've ran into this issue when parsing Twitter's Bootstrap; css_parser prints out the :all declaration, then the :print, then stops and ignores the rest of the css after that. Is this an easy thing to fix?

I've fixed this issue in #52.