r2 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4f4e266f69646ea465956984aae4e9f23714888
4
- data.tar.gz: 4bc745ee1417f388979ffd6b090b3b0ce7cf012b
3
+ metadata.gz: d5ab6e294013e8786fc50aae34d70baa7a62f10b
4
+ data.tar.gz: a8b49f9b4b9407050145114607f23c7d391c3a6a
5
5
  SHA512:
6
- metadata.gz: 4b504c3c059252910fb1ab6dbcfbf41cf2c8383d181d28b861c133b99459ed7d2bff733fa51bddacc58b8583f0c27116fb5ebcdf3d6e62a9b06d25fc8509a61a
7
- data.tar.gz: e2f4ecebe8b886e6478ad1e3b99cfecee536df7f587d676f26757e5264a5d822504c5e7153a6fda23352bfb7d7f7b2300fd5725d3784606027ac8175567811ee
6
+ metadata.gz: f3950af1429c22b800a0c94a297ee427b95c125dbc806f516c946f3f3c1855d3ff8a08f6adc01c7515f02e66f32e793243efe48ed558fb718ffaf65140efe086
7
+ data.tar.gz: b36f3c6a247163831b299922ba4114067b5052eaef920cd03f51c008fa9c94f6f76e7c60d3c9217573f1134a12c68463e1ba2d45390fb1b8b985c1dcf720585c
data/README.md CHANGED
@@ -23,6 +23,7 @@ Report bugs in the github project at http://github.com/mzsanford/r2rb
23
23
 
24
24
  ## Change Log
25
25
 
26
+ * v0.2.5 - Handle `background:` shorthand
26
27
  * v0.2.4 - Handle `url()` properties better
27
28
  * [BUG] - Handle `url()` without embedded semi-colons and with trailing parameters
28
29
  * v0.2.3 - Handle `url()` properties better
data/lib/r2.rb CHANGED
@@ -62,7 +62,8 @@ module R2
62
62
  '-moz-box-shadow' => lambda {|obj,val| obj.shadow_swap(val) },
63
63
  'direction' => lambda {|obj,val| obj.direction_swap(val) },
64
64
  'clear' => lambda {|obj,val| obj.side_swap(val) },
65
- 'background-position' => lambda {|obj,val| obj.background_position_swap(val) }
65
+ 'background-position' => lambda {|obj,val| obj.background_position_swap(val) },
66
+ 'background' => lambda {|obj,val| obj.background_swap(val) },
66
67
  }
67
68
 
68
69
  # Given a String of CSS perform the full directionality change
@@ -173,6 +174,32 @@ module R2
173
174
  ShadowFlipper::flip(val)
174
175
  end
175
176
 
177
+ # Given the short-hand background: definition attempt to convert the direction.
178
+ def background_swap(val)
179
+ parts = val.split(/ /)
180
+
181
+ checked = []
182
+ skip = false
183
+ parts.each_index do |i|
184
+ p = parts[i]
185
+ n = parts[i+1]
186
+
187
+ if skip
188
+ skip = false
189
+ next
190
+ end
191
+
192
+ if p.match(/left|right|\d+%/)
193
+ checked << background_position_swap("#{p} #{n}")
194
+ skip = true
195
+ else
196
+ checked << side_swap(p)
197
+ end
198
+ end
199
+
200
+ checked.flatten.join(' ')
201
+ end
202
+
176
203
 
177
204
  # Border radius uses top-left, top-right, bottom-left, bottom-right, so all values need to be swapped. Additionally,
178
205
  # two and three value border-radius declarations need to be swapped as well. Vertical radius, specified with a /,
@@ -1,3 +1,3 @@
1
1
  module R2
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
@@ -55,6 +55,27 @@ describe R2::Swapper do
55
55
  flipped_css.should == expected_result
56
56
  end
57
57
 
58
+ # background: #000 url("spree/frontend/cart.png") no-repeat left center;
59
+ it "handles background with position declarations" do
60
+ css = <<-EOS
61
+ .bg1 {
62
+ background: #000 url("spree/frontend/cart.png") no-repeat left center;
63
+ }
64
+ .bg2 {
65
+ background: #000 url("spree/frontend/cart.png") no-repeat 1% 50%;
66
+ }
67
+ EOS
68
+
69
+ expected_result = '.bg1{background:#000 url("spree/frontend/cart.png") no-repeat right center;}'
70
+ expected_result += '.bg2{background:#000 url("spree/frontend/cart.png") no-repeat 99% 50%;}';
71
+
72
+ flipped_css = r2.r2(css)
73
+
74
+ flipped_css.should == expected_result
75
+ end
76
+
77
+
78
+
58
79
  it "handles SVG background-image declarations" do
59
80
  escaped_xml = "%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22iso-8859-1%22%3F%3E%3C!DOCTYPE%20svg%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20SVG%201.1%2F%2FEN%22%20%22http%3A%2F%2Fwww.w3.org%2FGraphics%2FSVG%2F1.1%2FDTD%2Fsvg11.dtd%22%3E%3Csvg%20version%3D%221.1%22%20id%3D%22Layer_1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20x%3D%220px%22%20y%3D%220px%22%20%20width%3D%2214px%22%20height%3D%2214px%22%20viewBox%3D%220%200%2014%2014%22%20style%3D%22enable-background%3Anew%200%200%2014%2014%3B%22%20xml%3Aspace%3D%22preserve%22%3E%3Cpath%20style%3D%22fill%3A%23FFFFFF%3B%22%20d%3D%22M9%2C5v3l5-4L9%2C0v3c0%2C0-5%2C0-5%2C7C6%2C5%2C9%2C5%2C9%2C5z%20M11%2C12H2V5h1l2-2H0v11h13V7l-2%2C2V12z%22%2F%3E%3C%2Fsvg%3E"
60
81
  css = <<-EOS
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Sanford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-13 00:00:00.000000000 Z
11
+ date: 2014-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake