@@ -11,8 +11,10 @@ class RuleSet
1111 BACKGROUND_PROPERTIES = [ 'background-color' , 'background-image' , 'background-repeat' , 'background-position' , 'background-size' , 'background-attachment' ] . freeze
1212 LIST_STYLE_PROPERTIES = [ 'list-style-type' , 'list-style-position' , 'list-style-image' ] . freeze
1313 FONT_STYLE_PROPERTIES = [ 'font-style' , 'font-variant' , 'font-weight' , 'font-size' , 'line-height' , 'font-family' ] . freeze
14+ FONT_WEIGHT_PROPERTIES = [ 'font-style' , 'font-weight' , 'font-variant' ] . freeze
1415 BORDER_STYLE_PROPERTIES = [ 'border-width' , 'border-style' , 'border-color' ] . freeze
1516 BORDER_PROPERTIES = [ 'border' , 'border-left' , 'border-right' , 'border-top' , 'border-bottom' ] . freeze
17+ DIMENSION_DIRECTIONS = [ :top , :right , :bottom , :left ] . freeze
1618
1719 NUMBER_OF_DIMENSIONS = 4
1820
@@ -196,7 +198,7 @@ def replace_declaration!(property, replacements, preserve_importance: false)
196198 end
197199
198200 def to_s ( options = { } )
199- str = declarations . reduce ( String . new ) do |memo , ( prop , value ) |
201+ str = declarations . reduce ( + '' ) do |memo , ( prop , value ) |
200202 importance = options [ :force_important ] || value . important ? ' !important' : ''
201203 memo << "#{ prop } : #{ value . value } #{ importance } ; "
202204 end
@@ -456,7 +458,7 @@ def expand_font_shorthand! # :nodoc:
456458 font_props [ 'font-family' ] = m
457459 end
458460 elsif /normal|inherit/i . match? ( m )
459- [ 'font-style' , 'font-weight' , 'font-variant' ] . each do |font_prop |
461+ FONT_WEIGHT_PROPERTIES . each do |font_prop |
460462 font_props [ font_prop ] ||= m
461463 end
462464 elsif /italic|oblique/i . match? ( m )
@@ -554,15 +556,15 @@ def create_background_shorthand! # :nodoc:
554556 #
555557 # TODO: this is extremely similar to create_background_shorthand! and should be combined
556558 def create_border_shorthand! # :nodoc:
557- values = BORDER_STYLE_PROPERTIES . map do |property |
559+ values = BORDER_STYLE_PROPERTIES . filter_map do |property |
558560 next unless ( declaration = declarations [ property ] )
559561 next if declaration . important
560562 # can't merge if any value contains a space (i.e. has multiple values)
561563 # we temporarily remove any spaces after commas for the check (inside rgba, etc...)
562564 next if /\s / . match? ( declaration . value . gsub ( /,\s / , ',' ) . strip )
563565
564566 declaration . value
565- end . compact
567+ end
566568
567569 return if values . size != BORDER_STYLE_PROPERTIES . size
568570
@@ -579,7 +581,7 @@ def create_dimensions_shorthand! # :nodoc:
579581 return if declarations . size < NUMBER_OF_DIMENSIONS
580582
581583 DIMENSIONS . each do |property , dimensions |
582- values = [ :top , :right , :bottom , :left ] . each_with_index . with_object ( { } ) do |( side , index ) , result |
584+ values = DIMENSION_DIRECTIONS . each_with_index . with_object ( { } ) do |( side , index ) , result |
583585 next unless ( declaration = declarations [ dimensions [ index ] ] )
584586
585587 result [ side ] = declaration . value
@@ -602,7 +604,7 @@ def create_dimensions_shorthand! # :nodoc:
602604 def create_font_shorthand! # :nodoc:
603605 return unless FONT_STYLE_PROPERTIES . all? { |prop | declarations . key? ( prop ) }
604606
605- new_value = String . new
607+ new_value = + ''
606608 [ 'font-style' , 'font-variant' , 'font-weight' ] . each do |property |
607609 unless declarations [ property ] . value == 'normal'
608610 new_value << declarations [ property ] . value << ' '
@@ -639,7 +641,7 @@ def compute_dimensions_shorthand(values)
639641 return [ :top ] if values . values . uniq . count == 1
640642
641643 # `/* top | right | bottom | left */`
642- return [ :top , :right , :bottom , :left ] if values [ :left ] != values [ :right ]
644+ return DIMENSION_DIRECTIONS if values [ :left ] != values [ :right ]
643645
644646 # Vertical are the same & horizontal are the same, `/* vertical | horizontal */`
645647 return [ :top , :left ] if values [ :top ] == values [ :bottom ]
0 commit comments