r2 0.2.1 → 0.2.2

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: 0a5183daf3e28928082401b7e9ab748e41080b7a
4
- data.tar.gz: 7e223471bffd64f83bab5c4b6f9454d067759e8d
3
+ metadata.gz: 5001cd455fb9de572960b0f6ab968888198a5e88
4
+ data.tar.gz: 3508a64c9e2df1edf3a5656094860f3afd66242c
5
5
  SHA512:
6
- metadata.gz: f4fbd3b2586d61ca723267911424da717054b69e072456da424c51a5bbf9070a430d926c404b53d464b07cc1511d5745bf821d7db5b3ef86243fd3498fcc2ed3
7
- data.tar.gz: 7e3eff1221044f7b7e695044bf8c89b4d0ec8e587c7bc13a33811c7f5f8390085e19ee77737b6203da921b8a1222386e5be57d6c6eddd27f00b834854e47085f
6
+ metadata.gz: eaf0fa605bd6b6f03a9181997949618a2567a18bc170e0db71d250b2a7a658ea2e6b613a3d9c050d5da1248bce08f8bd520d36c9e04424e512f30ead4b818c0b
7
+ data.tar.gz: 2db705161e9d78c836c7e19ce1c9942ecb0e388b19821edc40bce355eee226c5ee4f2f9d8d006277de6f2e9688a21ac7e75875c94aea5c3a8132f51fa261b985
data/README.md CHANGED
@@ -23,6 +23,9 @@ Report bugs in the github project at http://github.com/mzsanford/r2rb
23
23
 
24
24
  ## Change Log
25
25
 
26
+ * v0.2.2 – CSS3 `box-shadow` fix continues
27
+ * [BUG] Correctly handle `box-shadow` declarations that define multiple shadows (fix from [@wazeHQ](https://github.com/wazeHQ))
28
+ * [FEATURE] Make the `r2` command line tool convert CSS provided via `stdin` or a file (previously it was a no-op)
26
29
  * v0.2.1 – CSS3 `box-shadow` fix
27
30
  * [BUG] Correctly handle `box-shadow` declarations starting with `inset` (fix from [@wazeHQ](https://github.com/wazeHQ))
28
31
  * v0.2.0 – CSS3 additions
data/bin/r2 CHANGED
@@ -1,3 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "r2"
4
+
5
+ if ARGV[0]
6
+ css = File.read(ARGV[0])
7
+ else
8
+ css = $stdin.read
9
+ end
10
+
11
+ puts R2.r2(css)
data/lib/r2.rb CHANGED
@@ -5,6 +5,9 @@
5
5
  # Author:: Matt Sanford (mailto:matt@twitter.com)
6
6
  # Copyright:: Copyright (c) 2011 Twitter, Inc.
7
7
  # License:: Licensed under the Apache License, Version 2.0
8
+
9
+ require 'r2/shadow_flipper'
10
+
8
11
  module R2
9
12
 
10
13
  # Short cut method for providing a one-time CSS change
@@ -148,19 +151,10 @@ module R2
148
151
  # Given the 2-6 variable declaration for box-shadow convert the direction. Conversion requires inverting the
149
152
  # horizontal measure only.
150
153
  def shadow_swap(val)
151
- args = val.to_s.split(/\s+/)
152
-
153
- #move 'inset' to the end
154
- args.push(args.shift) if args && args[0] == "inset"
155
-
156
- matched = args && args[0].match(/^([-+]?\d+)(\w*)$/)
157
- if matched
158
- return (["#{(-1 * matched[1].to_i)}#{matched[2]}"] + args[1..5]).compact.join(' ')
159
- else
160
- return val
161
- end
154
+ ShadowFlipper::flip(val)
162
155
  end
163
156
 
157
+
164
158
  # Border radius uses top-left, top-right, bottom-left, bottom-right, so all values need to be swapped. Additionally,
165
159
  # two and three value border-radius declarations need to be swapped as well. Vertical radius, specified with a /,
166
160
  # should be left alone.
@@ -0,0 +1,33 @@
1
+ module R2
2
+ module ShadowFlipper
3
+ def self.flip(val)
4
+ val = replace_commas_in_parentheses(val)
5
+ val = val.split(/\s*,\s*/).map { |shadow| single_shadow_swap(shadow) }.join(', ')
6
+ restore_commas(val)
7
+ end
8
+
9
+ private
10
+
11
+ def self.replace_commas_in_parentheses(string)
12
+ string.gsub(/\([^)]*\)/) { |parens| parens.gsub(',', '|||') }
13
+ end
14
+
15
+ def self.restore_commas(string)
16
+ string.gsub('|||', ',')
17
+ end
18
+
19
+ def self.single_shadow_swap(val)
20
+ args = val.to_s.split(/\s+/)
21
+
22
+ #move 'inset' to the end
23
+ args.push(args.shift) if args && args[0] == "inset"
24
+
25
+ matched = args && args[0].match(/^([-+]?\d+)(\w*)$/)
26
+ if matched
27
+ return (["#{(-1 * matched[1].to_i)}#{matched[2]}"] + args[1..5]).compact.join(' ')
28
+ else
29
+ return val
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module R2
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -156,6 +156,14 @@ describe R2::Swapper do
156
156
  r2.shadow_swap("inset 1px 2px").should == "-1px 2px inset"
157
157
  end
158
158
 
159
+ it "should swap multiple values" do
160
+ r2.shadow_swap("inset 1px 2px, 1px 2px #000").should == "-1px 2px inset, -1px 2px #000"
161
+ end
162
+
163
+ it "should swap multiple values (with rgba)" do
164
+ r2.shadow_swap("inset 1px 2px rgba(0,0,0,0.2), 1px 2px #000").should == "-1px 2px rgba(0,0,0,0.2) inset, -1px 2px #000"
165
+ end
166
+
159
167
  end
160
168
 
161
169
  describe "#border_radius_swap" do
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.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Sanford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-26 00:00:00.000000000 Z
11
+ date: 2013-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -55,6 +55,7 @@ files:
55
55
  - Rakefile
56
56
  - bin/r2
57
57
  - lib/r2.rb
58
+ - lib/r2/shadow_flipper.rb
58
59
  - lib/r2/version.rb
59
60
  - r2.gemspec
60
61
  - spec/r2_spec.rb