Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #3 from estenh/master

Add single line border-radius property to swap.
  • Loading branch information...
commit c30c32b19927b19b85f7a099fd9beee111d5e135 2 parents b91f87e + 6eb0212
@mzsanford authored
Showing with 38 additions and 0 deletions.
  1. +24 −0 lib/r2.rb
  2. +14 −0 spec/r2_spec.rb
View
24 lib/r2.rb
@@ -49,6 +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.border_radius_swap(val) },
+ '-moz-border-radius' => lambda {|obj,val| obj.border_radius_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) },
@@ -140,6 +143,27 @@ def quad_swap(val)
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. 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 && !val.to_s.include?('/')
+ case points.length
+ when 4
+ [points[1], points[0], points[3], points[2]].join(' ')
+ when 3
+ [points[1], points[0], points[1], points[2]].join(' ')
+ when 2
+ [points[1], points[0]].join(' ')
+ else val
+ end
+ else
+ val
+ end
+ end
end
end
View
14 spec/r2_spec.rb
@@ -97,4 +97,18 @@
@r2.quad_swap("1px 2px").should == "1px 2px"
end
end
+
+ context "border_radius_swap" do
+ it "should swap a valid quad value" do
+ @r2.border_radius_swap("1px 2px 3px 4px").should == "2px 1px 4px 3px"
+ end
+
+ it "should skip a triple value" do
+ @r2.border_radius_swap("1px 2px 3px").should == "2px 1px 2px 3px"
+ end
+
+ it "should skip a pair value" do
+ @r2.border_radius_swap("1px 2px").should == "2px 1px"
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.