r2 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +5 -1
- data/bin/r2 +0 -0
- data/lib/r2/version.rb +1 -1
- data/lib/r2.rb +54 -3
- data/r2.gemspec +2 -0
- data/spec/r2_spec.rb +85 -7
- metadata +40 -44
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -19,6 +19,10 @@ Report bugs in the github project at http://github.com/mzsanford/r2rb
|
|
19
19
|
|
20
20
|
## Change Log
|
21
21
|
|
22
|
+
* v0.1.0 – @fractious[https://github.com/fractious] updates
|
23
|
+
* [CLEANUP] Added rspec dev dependency
|
24
|
+
* [CLEANUP] Fixed typo in internal method name
|
25
|
+
* [FEATURE] Added support for background-position
|
22
26
|
* v0.0.3 - Feature release
|
23
27
|
* [FEATURE] Added -moz and -webkit border support
|
24
28
|
* [FEATURE] Added box-shadow (+moz and webkit) support
|
@@ -40,4 +44,4 @@ Report bugs in the github project at http://github.com/mzsanford/r2rb
|
|
40
44
|
distributed under the License is distributed on an "AS IS" BASIS,
|
41
45
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
42
46
|
See the License for the specific language governing permissions and
|
43
|
-
limitations under the License.
|
47
|
+
limitations under the License.
|
data/bin/r2
CHANGED
File without changes
|
data/lib/r2/version.rb
CHANGED
data/lib/r2.rb
CHANGED
@@ -49,12 +49,17 @@ module R2
|
|
49
49
|
VALUE_PROCS = {
|
50
50
|
'padding' => lambda {|obj,val| obj.quad_swap(val) },
|
51
51
|
'margin' => lambda {|obj,val| obj.quad_swap(val) },
|
52
|
+
'border-radius' => lambda {|obj,val| obj.border_radius_swap(val) },
|
53
|
+
'-moz-border-radius' => lambda {|obj,val| obj.border_radius_swap(val) },
|
54
|
+
'-webkit-border-radius' => lambda {|obj,val| obj.border_radius_swap(val) },
|
52
55
|
'text-align' => lambda {|obj,val| obj.side_swap(val) },
|
53
56
|
'float' => lambda {|obj,val| obj.side_swap(val) },
|
54
57
|
'box-shadow' => lambda {|obj,val| obj.quad_swap(val) },
|
55
58
|
'-webkit-box-shadow' => lambda {|obj,val| obj.quad_swap(val) },
|
56
59
|
'-moz-box-shadow' => lambda {|obj,val| obj.quad_swap(val) },
|
57
|
-
'direction' => lambda {|obj,val| obj.direction_swap(val) }
|
60
|
+
'direction' => lambda {|obj,val| obj.direction_swap(val) },
|
61
|
+
'clear' => lambda {|obj,val| obj.side_swap(val) },
|
62
|
+
'background-position' => lambda {|obj,val| obj.background_position_swap(val) }
|
58
63
|
}
|
59
64
|
|
60
65
|
# Given a String of CSS perform the full directionality change
|
@@ -69,7 +74,7 @@ module R2
|
|
69
74
|
|
70
75
|
rule_str = selector + '{'
|
71
76
|
declarations.split(/;(?!base64)/).each do |decl|
|
72
|
-
rule_str <<
|
77
|
+
rule_str << declaration_swap(decl)
|
73
78
|
end
|
74
79
|
rule_str << "}"
|
75
80
|
rule_str
|
@@ -89,7 +94,7 @@ module R2
|
|
89
94
|
end
|
90
95
|
|
91
96
|
# Given a single CSS declaration rule (e.g. <tt>padding-left: 4px</tt>) return the opposing rule (so, <tt>padding-right:4px;</tt> in this example)
|
92
|
-
def
|
97
|
+
def declaration_swap(decl)
|
93
98
|
return '' unless decl
|
94
99
|
|
95
100
|
matched = decl.match(/([^:]+):(.+)$/)
|
@@ -139,6 +144,52 @@ module R2
|
|
139
144
|
val
|
140
145
|
end
|
141
146
|
end
|
147
|
+
# Border radius uses top-left, top-right, bottom-left, bottom-right, so all values need to be swapped. Additionally,
|
148
|
+
# two and three value border-radius declarations need to be swapped as well. Vertical radius, specified with a /,
|
149
|
+
# should be left alone.
|
150
|
+
def border_radius_swap(val)
|
151
|
+
# 1px 2px 3px 4px => 1px 4px 3px 2px
|
152
|
+
points = val.to_s.split(/\s+/)
|
153
|
+
|
154
|
+
if points && points.length > 1 && !val.to_s.include?('/')
|
155
|
+
case points.length
|
156
|
+
when 4
|
157
|
+
[points[1], points[0], points[3], points[2]].join(' ')
|
158
|
+
when 3
|
159
|
+
[points[1], points[0], points[1], points[2]].join(' ')
|
160
|
+
when 2
|
161
|
+
[points[1], points[0]].join(' ')
|
162
|
+
else val
|
163
|
+
end
|
164
|
+
else
|
165
|
+
val
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
# Given a background-position such as <tt>left center</tt> or <tt>0% 50%</tt> return the opposing value e.g <tt>right center</tt> or <tt>100% 50%</tt>
|
170
|
+
def background_position_swap(val)
|
171
|
+
|
172
|
+
if val =~ /left/
|
173
|
+
val.gsub!('left', 'right')
|
174
|
+
elsif val =~ /right/
|
175
|
+
val.gsub!('right', 'left')
|
176
|
+
end
|
177
|
+
|
178
|
+
points = val.strip.split(/\s+/)
|
179
|
+
|
180
|
+
# If first point is a percentage-value
|
181
|
+
if match = points[0].match(/(\d+)%/)
|
182
|
+
inv = 100 - match[1].to_i # 30% => 70% (100 - x)
|
183
|
+
val = ["#{inv}%", points[1]].compact.join(' ')
|
184
|
+
end
|
185
|
+
|
186
|
+
# If first point is a unit-value
|
187
|
+
if match = points[0].match(/^(\d+[a-z]{2,3})/)
|
188
|
+
val = ["right", match[1], points[1] || "center"].compact.join(' ')
|
189
|
+
end
|
190
|
+
|
191
|
+
val
|
192
|
+
end
|
142
193
|
end
|
143
194
|
|
144
195
|
end
|
data/r2.gemspec
CHANGED
@@ -14,6 +14,8 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.rubyforge_project = "r2"
|
16
16
|
|
17
|
+
s.add_development_dependency 'rspec', '~> 1.3.0'
|
18
|
+
|
17
19
|
s.files = `git ls-files`.split("\n")
|
18
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
21
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
data/spec/r2_spec.rb
CHANGED
@@ -12,25 +12,25 @@ describe R2 do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
context "
|
15
|
+
context "declaration_swap" do
|
16
16
|
it "should handle nil" do
|
17
|
-
@r2.
|
17
|
+
@r2.declaration_swap(nil).should == ''
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should handle invalid declarations" do
|
21
|
-
@r2.
|
21
|
+
@r2.declaration_swap("not a decl").should == ''
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should swap a swappable parameter" do
|
25
|
-
@r2.
|
25
|
+
@r2.declaration_swap("padding-right:4px").should == 'padding-left:4px;'
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should swap a swappable quad parameter" do
|
29
|
-
@r2.
|
29
|
+
@r2.declaration_swap("padding:1px 2px 3px 4px").should == 'padding:1px 4px 3px 2px;'
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should ignore other parameters" do
|
33
|
-
@r2.
|
33
|
+
@r2.declaration_swap("foo:bar").should == 'foo:bar;'
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -97,4 +97,82 @@ describe R2 do
|
|
97
97
|
@r2.quad_swap("1px 2px").should == "1px 2px"
|
98
98
|
end
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
|
+
context "border_radius_swap" do
|
102
|
+
it "should swap a valid quad value" do
|
103
|
+
@r2.border_radius_swap("1px 2px 3px 4px").should == "2px 1px 4px 3px"
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should skip a triple value" do
|
107
|
+
@r2.border_radius_swap("1px 2px 3px").should == "2px 1px 2px 3px"
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should skip a pair value" do
|
111
|
+
@r2.border_radius_swap("1px 2px").should == "2px 1px"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "background_position_swap" do
|
116
|
+
|
117
|
+
context "with a single value" do
|
118
|
+
it "should ignore a named-vertical" do
|
119
|
+
@r2.background_position_swap('top').should == 'top'
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should swap a named-horizontal 'left'" do
|
123
|
+
@r2.background_position_swap('left').should == 'right'
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should swap a named-horizontal 'right'" do
|
127
|
+
@r2.background_position_swap('right').should == 'left'
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should invert a percentage" do
|
131
|
+
@r2.background_position_swap('25%').should == '75%'
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should convert a unit value" do
|
135
|
+
@r2.background_position_swap('25px').should == 'right 25px center'
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "with a pair of values" do
|
140
|
+
# Note that a pair of keywords can be reordered while a combination of
|
141
|
+
# keyword and length or percentage cannot. So ‘center left’ is valid
|
142
|
+
# while ‘50% left’ is not.
|
143
|
+
# See: http://dev.w3.org/csswg/css3-background/#background-position
|
144
|
+
|
145
|
+
it "should swap named-horizontal and ignore named-vertical" do
|
146
|
+
@r2.background_position_swap('right bottom').should == 'left bottom'
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should swap named-horizontal and ignore unit-vertical" do
|
150
|
+
@r2.background_position_swap('left 100px').should == 'right 100px'
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should convert unit-horizontal" do
|
154
|
+
@r2.background_position_swap('100px center').should == 'right 100px center'
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should swap named-horizontal and ignore percentage-vertical" do
|
158
|
+
@r2.background_position_swap('left 0%').should == 'right 0%'
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should invert first percentage-horizontal value in a pair" do
|
162
|
+
@r2.background_position_swap('25% 100%').should == '75% 100%'
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "with a triplet of values" do
|
167
|
+
it "should swap named-horizontal" do
|
168
|
+
@r2.background_position_swap('left 20px center').should == 'right 20px center'
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context "with a quad of values" do
|
173
|
+
it "should swap named-horizontal value" do
|
174
|
+
@r2.background_position_swap('bottom 10px left 20px').should == 'bottom 10px right 20px'
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
metadata
CHANGED
@@ -1,34 +1,40 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: r2
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 3
|
10
|
-
version: 0.0.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Matt Sanford
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
date: 2013-03-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.3.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.3.0
|
22
30
|
description: CSS flipper for right-to-left processing. A Ruby port of https://github.com/ded/r2
|
23
|
-
email:
|
31
|
+
email:
|
24
32
|
- matt@twitter.com
|
25
|
-
executables:
|
33
|
+
executables:
|
26
34
|
- r2
|
27
35
|
extensions: []
|
28
|
-
|
29
36
|
extra_rdoc_files: []
|
30
|
-
|
31
|
-
files:
|
37
|
+
files:
|
32
38
|
- .gitignore
|
33
39
|
- Gemfile
|
34
40
|
- LICENSE
|
@@ -39,39 +45,29 @@ files:
|
|
39
45
|
- lib/r2/version.rb
|
40
46
|
- r2.gemspec
|
41
47
|
- spec/r2_spec.rb
|
42
|
-
|
43
|
-
homepage: ""
|
48
|
+
homepage: ''
|
44
49
|
licenses: []
|
45
|
-
|
46
50
|
post_install_message:
|
47
51
|
rdoc_options: []
|
48
|
-
|
49
|
-
require_paths:
|
52
|
+
require_paths:
|
50
53
|
- lib
|
51
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
55
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
|
58
|
-
- 0
|
59
|
-
version: "0"
|
60
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
|
-
requirements:
|
63
|
-
- -
|
64
|
-
- !ruby/object:Gem::Version
|
65
|
-
|
66
|
-
segments:
|
67
|
-
- 0
|
68
|
-
version: "0"
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
69
66
|
requirements: []
|
70
|
-
|
71
67
|
rubyforge_project: r2
|
72
|
-
rubygems_version: 1.
|
68
|
+
rubygems_version: 1.8.23
|
73
69
|
signing_key:
|
74
70
|
specification_version: 3
|
75
71
|
summary: CSS flipper for right-to-left processing
|
76
|
-
test_files:
|
72
|
+
test_files:
|
77
73
|
- spec/r2_spec.rb
|