lib/css_parser.rb in css_parser-1.1.4 vs lib/css_parser.rb in css_parser-1.1.5

- old
+ new

@@ -5,11 +5,11 @@ require 'zlib' require 'stringio' require 'iconv' module CssParser - VERSION = '1.1.4' + VERSION = '1.1.5' # Merge multiple CSS RuleSets by cascading according to the CSS 2.1 cascading rules # (http://www.w3.org/TR/REC-CSS2/cascade.html#cascading-order). # # Takes one or more RuleSet objects. @@ -73,23 +73,31 @@ end end rule_set.each_declaration do |property, value, is_important| # Add the property to the list to be folded per http://www.w3.org/TR/CSS21/cascade.html#cascading-order - if not properties.has_key?(property) or - is_important or # step 2 - properties[property][:specificity] < specificity or # step 3 - properties[property][:specificity] == specificity # step 4 - properties[property] = {:value => value, :specificity => specificity, :is_important => is_important} + if not properties.has_key?(property) + properties[property] = {:value => value, :specificity => specificity, :is_important => is_important} + elsif properties[property][:specificity] < specificity or properties[property][:specificity] == specificity + unless properties[property][:is_important] + properties[property] = {:value => value, :specificity => specificity, :is_important => is_important} + end end + + if is_important + properties[property] = {:value => value, :specificity => specificity, :is_important => is_important} + end end end merged = RuleSet.new(nil, nil) - # TODO: what about important properties.each do |property, details| - merged[property.strip] = details[:value].strip + if details[:is_important] + merged[property.strip] = details[:value].strip.gsub(/\;\Z/, '') + '!important' + else + merged[property.strip] = details[:value].strip + end end merged.create_shorthand! merged end