Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleaned up code, fixed bug where > 4 args would return nil, avoid dea…

…ling with any vertical radius issues
  • Loading branch information...
commit 4dcf64dd14364e41df1f9468b976c6848e0db50c 1 parent 6127bb4
@esten esten authored
Showing with 6 additions and 4 deletions.
  1. +6 −4 lib/r2.rb
View
10 lib/r2.rb
@@ -49,9 +49,9 @@ class Swapper
VALUE_PROCS = {
'padding' => lambda {|obj,val| obj.quad_swap(val) },
'margin' => lambda {|obj,val| obj.quad_swap(val) },
- 'border-radius' => lambda {|obj,val| obj.quad_swap(val) },
+ 'border-radius' => lambda {|obj,val| obj.border_radius_swap(val) },
'-moz-border-radius' => lambda {|obj,val| obj.border_radius_swap(val) },
- '-webkit-border-radius' => lambda {|obj,val| obj.quad_swap(val) },
+ '-webkit-border-radius' => lambda {|obj,val| obj.border_radius_swap(val) },
'text-align' => lambda {|obj,val| obj.side_swap(val) },
'float' => lambda {|obj,val| obj.side_swap(val) },
'box-shadow' => lambda {|obj,val| obj.quad_swap(val) },
@@ -144,12 +144,13 @@ def quad_swap(val)
end
end
# Border radius uses top-left, top-right, bottom-left, bottom-right, so all values need to be swapped. Additionally,
- # two and three value border-radius declarations need to be swapped as well.
+ # two and three value border-radius declarations need to be swapped as well. Vertical radius, specified with a /,
+ # should be left alone.
def border_radius_swap(val)
# 1px 2px 3px 4px => 1px 4px 3px 2px
points = val.to_s.split(/\s+/)
- if points && points.length > 1
+ if points && points.length > 1 && !val.to_s.include?('/')
case points.length
when 4
[points[1], points[0], points[3], points[2]].join(' ')
@@ -157,6 +158,7 @@ def border_radius_swap(val)
[points[1], points[0], points[1], points[2]].join(' ')
when 2
[points[1], points[0]].join(' ')
+ else val
end
else
val
Please sign in to comment.
Something went wrong with that request. Please try again.