premailer / css_parser

Ruby CSS Parser
Other
279 stars 110 forks source link

Media query should reset to :all #43

Closed twe4ked closed 7 years ago

twe4ked commented 11 years ago

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; }]}
ben-eb commented 11 years ago

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?

jievans commented 10 years ago

I've fixed this issue in https://github.com/premailer/css_parser/pull/52.