lib/css_parser.rb in css_parser-1.2.6 vs lib/css_parser.rb in css_parser-1.3.0
- old
+ new
@@ -22,13 +22,14 @@
# used in the cascade calculations.
#
# If no specificity is explicitly set and the RuleSet has *one* selector,
# the specificity is calculated using that selector.
#
- # If no selectors or multiple selectors are present, the specificity is
- # treated as 0.
+ # If no selectors the specificity is treated as 0.
#
+ # If multiple selectors are present then the greatest specificity is used.
+ #
# ==== Example #1
# rs1 = RuleSet.new(nil, 'color: black;')
# rs2 = RuleSet.new(nil, 'margin: 0px;')
#
# merged = CssParser.merge(rs1, rs2)
@@ -65,13 +66,13 @@
rule_sets.each do |rule_set|
rule_set.expand_shorthand!
specificity = rule_set.specificity
unless specificity
- if rule_set.selectors.length == 1
- specificity = calculate_specificity(rule_set.selectors[0])
- else
+ if rule_set.selectors.length == 0
specificity = 0
+ else
+ specificity = rule_set.selectors.map { |s| calculate_specificity(s) }.compact.max || 0
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