# File 'lib/css_parser.rb', line 54defself.merge(*rule_sets)@folded_declaration_cache={}# in case called like CssParser.merge([rule_set, rule_set])
rule_sets.flatten!ifrule_sets[0].kind_of?(Array)unlessrule_sets.all?{|rs|rs.kind_of?(CssParser::RuleSet)}raiseArgumentError,"all parameters must be CssParser::RuleSets."endreturnrule_sets[0]ifrule_sets.length==1# Internal storage of CSS properties that we will keep
properties={}rule_sets.eachdo|rule_set|rule_set.expand_shorthand!specificity=rule_set.specificityunlessspecificityifrule_set.selectors.length==0specificity=0elsespecificity=rule_set.selectors.map{|s|calculate_specificity(s)}.compact.max||0endendrule_set.each_declarationdo|property,value,is_important|# Add the property to the list to be folded per http://www.w3.org/TR/CSS21/cascade.html#cascading-order
ifnotproperties.has_key?(property)properties[property]={:value=>value,:specificity=>specificity,:is_important=>is_important}elsifis_importantifnotproperties[property][:is_important]orproperties[property][:specificity]<=specificityproperties[property]={:value=>value,:specificity=>specificity,:is_important=>is_important}endelsifproperties[property][:specificity]<specificityorproperties[property][:specificity]==specificityunlessproperties[property][:is_important]properties[property]={:value=>value,:specificity=>specificity,:is_important=>is_important}endendendendmerged=RuleSet.new(nil,nil)properties.eachdo|property,details|ifdetails[:is_important]merged[property.strip]=details[:value].strip.gsub(/\;\Z/,'')+'!important'elsemerged[property.strip]=details[:value].stripendendmerged.create_shorthand!mergedend