r2 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/r2.rb +1 -1
- data/lib/r2/version.rb +1 -1
- data/r2.gemspec +3 -2
- data/spec/r2_spec.rb +70 -51
- metadata +39 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8550ffae3d9358c1257e8163f6a5d03d945d09f
|
4
|
+
data.tar.gz: 3a0e2808776280f8c3a87de5d1cf7baa5a18af8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1de570c1fc501a5e278d2757bba45aacce956ef3d39660e9e3f661de8bbf7812391729407363882d9a98bb386bbff37ec8de588f85e9b49592679d3175aac1c
|
7
|
+
data.tar.gz: 6c80710ffed22c49310fec1766d478e4df07c10af0a9bed75ec3a1ea1c02c18f3da29d311517355fcff44c374fab99c183ca9fc39c034a18300c922938f83f96
|
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.6 - Handle multi-row selectors (fix from [@n0nick](https://github.com/n0nick))
|
26
27
|
* v0.2.5 - Handle `background:` shorthand
|
27
28
|
* v0.2.4 - Handle `url()` properties better
|
28
29
|
* [BUG] - Handle `url()` without embedded semi-colons and with trailing parameters
|
data/lib/r2.rb
CHANGED
@@ -110,7 +110,7 @@ module R2
|
|
110
110
|
return '' unless css
|
111
111
|
|
112
112
|
css.gsub(/\/\*[\s\S]+?\*\//, ''). # comments
|
113
|
-
gsub(/[\n\r]
|
113
|
+
gsub(/[\n\r]+/, ' '). # line breaks and carriage returns
|
114
114
|
gsub(/\s*([:;,\{\}])\s*/, '\1'). # space between selectors, declarations, properties and values
|
115
115
|
gsub(/\s+/, ' '). # replace multiple spaces with single spaces
|
116
116
|
gsub(/(\A\s+|\s+\z)/, '') # leading or trailing spaces
|
data/lib/r2/version.rb
CHANGED
data/r2.gemspec
CHANGED
@@ -14,8 +14,9 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.rubyforge_project = "r2"
|
16
16
|
|
17
|
-
s.add_development_dependency 'rake'
|
18
|
-
s.add_development_dependency 'rspec', '~>
|
17
|
+
s.add_development_dependency 'rake', '~> 0'
|
18
|
+
s.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
|
19
|
+
s.add_development_dependency 'rspec-mocks', '~> 3.4.0', '>= 3.4.0'
|
19
20
|
|
20
21
|
s.files = `git ls-files`.split("\n")
|
21
22
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/spec/r2_spec.rb
CHANGED
@@ -8,8 +8,8 @@ describe R2 do
|
|
8
8
|
let(:css) { "body { direction: rtl; }" }
|
9
9
|
|
10
10
|
it "provides a shortcut to .new#r2" do
|
11
|
-
R2::Swapper.
|
12
|
-
r2.
|
11
|
+
allow(R2::Swapper).to receive(:new).and_return(r2)
|
12
|
+
expect(r2).to receive(:r2).with(css)
|
13
13
|
R2.r2(css)
|
14
14
|
end
|
15
15
|
end
|
@@ -21,7 +21,7 @@ describe R2::Swapper do
|
|
21
21
|
|
22
22
|
describe "#r2" do
|
23
23
|
it "processes CSS" do
|
24
|
-
r2.r2("/* comment */\nbody { direction: rtl; }\nimg { padding: 4px;}").
|
24
|
+
expect(r2.r2("/* comment */\nbody { direction: rtl; }\nimg { padding: 4px;}")).to eq("body{direction:ltr;}img{padding:4px;}")
|
25
25
|
end
|
26
26
|
|
27
27
|
it "handles media queries" do
|
@@ -37,7 +37,7 @@ describe R2::Swapper do
|
|
37
37
|
|
38
38
|
flipped_css = r2.r2(css)
|
39
39
|
|
40
|
-
flipped_css.
|
40
|
+
expect(flipped_css).to eq(expected_result)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "handles background-image declarations" do
|
@@ -52,7 +52,7 @@ describe R2::Swapper do
|
|
52
52
|
|
53
53
|
flipped_css = r2.r2(css)
|
54
54
|
|
55
|
-
flipped_css.
|
55
|
+
expect(flipped_css).to eq(expected_result)
|
56
56
|
end
|
57
57
|
|
58
58
|
# background: #000 url("spree/frontend/cart.png") no-repeat left center;
|
@@ -71,7 +71,7 @@ describe R2::Swapper do
|
|
71
71
|
|
72
72
|
flipped_css = r2.r2(css)
|
73
73
|
|
74
|
-
flipped_css.
|
74
|
+
expect(flipped_css).to eq(expected_result)
|
75
75
|
end
|
76
76
|
|
77
77
|
|
@@ -90,146 +90,165 @@ describe R2::Swapper do
|
|
90
90
|
|
91
91
|
flipped_css = r2.r2(css)
|
92
92
|
|
93
|
-
flipped_css.
|
93
|
+
expect(flipped_css).to eq(expected_result)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "handles newline correctly" do
|
97
|
+
css =
|
98
|
+
"fieldset[disabled]\n" +
|
99
|
+
"input[type=\"checkbox\"], fieldset[disabled]\n" +
|
100
|
+
".radio {\n" +
|
101
|
+
" cursor: not-allowed; }"
|
102
|
+
|
103
|
+
expected =
|
104
|
+
'fieldset[disabled] input[type="checkbox"],' +
|
105
|
+
'fieldset[disabled] .radio' +
|
106
|
+
'{cursor:not-allowed;}'
|
107
|
+
|
108
|
+
expect(r2.r2(css)).to eq(expected)
|
94
109
|
end
|
95
110
|
end
|
96
111
|
|
97
112
|
describe "#declaration_swap" do
|
98
113
|
it "should handle nil" do
|
99
|
-
r2.declaration_swap(nil).
|
114
|
+
expect(r2.declaration_swap(nil)).to eq('')
|
100
115
|
end
|
101
116
|
|
102
117
|
it "should handle invalid declarations" do
|
103
|
-
r2.declaration_swap("not a decl").
|
118
|
+
expect(r2.declaration_swap("not a decl")).to eq('')
|
104
119
|
end
|
105
120
|
|
106
121
|
it "should swap a swappable parameter" do
|
107
|
-
r2.declaration_swap("padding-right:4px").
|
122
|
+
expect(r2.declaration_swap("padding-right:4px")).to eq('padding-left:4px;')
|
108
123
|
end
|
109
124
|
|
110
125
|
it "should swap a swappable quad parameter" do
|
111
|
-
r2.declaration_swap("padding:1px 2px 3px 4px").
|
126
|
+
expect(r2.declaration_swap("padding:1px 2px 3px 4px")).to eq('padding:1px 4px 3px 2px;')
|
112
127
|
end
|
113
128
|
|
114
129
|
it "should ignore other parameters" do
|
115
|
-
r2.declaration_swap("foo:bar").
|
130
|
+
expect(r2.declaration_swap("foo:bar")).to eq('foo:bar;')
|
116
131
|
end
|
117
132
|
end
|
118
133
|
|
119
134
|
describe "#minimize" do
|
120
135
|
it "should handle nil" do
|
121
|
-
r2.minimize(nil).
|
136
|
+
expect(r2.minimize(nil)).to eq("")
|
122
137
|
end
|
123
138
|
|
124
139
|
it "should strip comments" do
|
125
|
-
r2.minimize("/* comment */foo").
|
140
|
+
expect(r2.minimize("/* comment */foo")).to eq("foo")
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should convert newlines to spaces" do
|
144
|
+
expect(r2.minimize("foo\nbar")).to eq("foo bar")
|
126
145
|
end
|
127
146
|
|
128
|
-
it "should
|
129
|
-
r2.minimize("foo\nbar").
|
147
|
+
it "should convert multiple newlines to a space" do
|
148
|
+
expect(r2.minimize("foo\n\n\nbar")).to eq("foo bar")
|
130
149
|
end
|
131
150
|
|
132
|
-
it "should
|
133
|
-
r2.minimize("foo\rbar").
|
151
|
+
it "should convert carriage returns to spaces" do
|
152
|
+
expect(r2.minimize("foo\rbar")).to eq("foo bar")
|
134
153
|
end
|
135
154
|
|
136
155
|
it "should collapse multiple spaces into one" do
|
137
|
-
r2.minimize("foo bar").
|
156
|
+
expect(r2.minimize("foo bar")).to eq("foo bar")
|
138
157
|
end
|
139
158
|
end
|
140
159
|
|
141
160
|
describe "#direction_swap" do
|
142
161
|
it "should swap 'rtl' to 'ltr'" do
|
143
|
-
r2.direction_swap('rtl').
|
162
|
+
expect(r2.direction_swap('rtl')).to eq('ltr')
|
144
163
|
end
|
145
164
|
|
146
165
|
it "should swap 'ltr' to 'rtl'" do
|
147
|
-
r2.direction_swap('ltr').
|
166
|
+
expect(r2.direction_swap('ltr')).to eq('rtl')
|
148
167
|
end
|
149
168
|
|
150
169
|
it "should ignore values other than 'ltr' and 'rtl'" do
|
151
170
|
[nil, '', 'foo'].each do |val|
|
152
|
-
r2.direction_swap(val).
|
171
|
+
expect(r2.direction_swap(val)).to eq(val)
|
153
172
|
end
|
154
173
|
end
|
155
174
|
end
|
156
175
|
|
157
176
|
describe "#side_swap" do
|
158
177
|
it "should swap 'right' to 'left'" do
|
159
|
-
r2.side_swap('right').
|
178
|
+
expect(r2.side_swap('right')).to eq('left')
|
160
179
|
end
|
161
180
|
|
162
181
|
it "should swap 'left' to 'right'" do
|
163
|
-
r2.side_swap('left').
|
182
|
+
expect(r2.side_swap('left')).to eq('right')
|
164
183
|
end
|
165
184
|
|
166
185
|
it "should ignore values other than 'left' and 'right'" do
|
167
186
|
[nil, '', 'foo'].each do |val|
|
168
|
-
r2.side_swap(val).
|
187
|
+
expect(r2.side_swap(val)).to eq(val)
|
169
188
|
end
|
170
189
|
end
|
171
190
|
end
|
172
191
|
|
173
192
|
describe "#quad_swap" do
|
174
193
|
it "should swap a valid quad value" do
|
175
|
-
r2.quad_swap("1px 2px 3px 4px").
|
194
|
+
expect(r2.quad_swap("1px 2px 3px 4px")).to eq("1px 4px 3px 2px")
|
176
195
|
end
|
177
196
|
|
178
197
|
it "should skip a pair value" do
|
179
|
-
r2.quad_swap("1px 2px").
|
198
|
+
expect(r2.quad_swap("1px 2px")).to eq("1px 2px")
|
180
199
|
end
|
181
200
|
end
|
182
201
|
|
183
202
|
describe "#shadow_swap" do
|
184
203
|
it "should swap a 2 arg value" do
|
185
|
-
r2.shadow_swap("1px 2px").
|
204
|
+
expect(r2.shadow_swap("1px 2px")).to eq("-1px 2px")
|
186
205
|
end
|
187
206
|
|
188
207
|
it "should swap a 2 arg value from rtl to ltr" do
|
189
|
-
r2.shadow_swap("-1px 2px").
|
208
|
+
expect(r2.shadow_swap("-1px 2px")).to eq("1px 2px")
|
190
209
|
end
|
191
210
|
|
192
211
|
it "should swap a 3 arg value" do
|
193
|
-
r2.shadow_swap("1px 2px #000").
|
212
|
+
expect(r2.shadow_swap("1px 2px #000")).to eq("-1px 2px #000")
|
194
213
|
end
|
195
214
|
|
196
215
|
it "should swap a 4 arg value" do
|
197
|
-
r2.shadow_swap("1px 2px 3px 4px").
|
216
|
+
expect(r2.shadow_swap("1px 2px 3px 4px")).to eq("-1px 2px 3px 4px")
|
198
217
|
end
|
199
218
|
|
200
219
|
it "should swap a 5 arg value" do
|
201
|
-
r2.shadow_swap("1px 2px 3px 4px #000").
|
220
|
+
expect(r2.shadow_swap("1px 2px 3px 4px #000")).to eq("-1px 2px 3px 4px #000")
|
202
221
|
end
|
203
222
|
|
204
223
|
it "should swap a 6 arg value" do
|
205
|
-
r2.shadow_swap("1px 2px 3px 4px #000 inset").
|
224
|
+
expect(r2.shadow_swap("1px 2px 3px 4px #000 inset")).to eq("-1px 2px 3px 4px #000 inset")
|
206
225
|
end
|
207
226
|
|
208
227
|
it "should swap value starting with inset" do
|
209
|
-
r2.shadow_swap("inset 1px 2px").
|
228
|
+
expect(r2.shadow_swap("inset 1px 2px")).to eq("-1px 2px inset")
|
210
229
|
end
|
211
230
|
|
212
231
|
it "should swap multiple values" do
|
213
|
-
r2.shadow_swap("inset 1px 2px, 1px 2px #000").
|
232
|
+
expect(r2.shadow_swap("inset 1px 2px, 1px 2px #000")).to eq("-1px 2px inset, -1px 2px #000")
|
214
233
|
end
|
215
234
|
|
216
235
|
it "should swap multiple values (with rgba)" do
|
217
|
-
r2.shadow_swap("inset 1px 2px rgba(0,0,0,0.2), 1px 2px #000").
|
236
|
+
expect(r2.shadow_swap("inset 1px 2px rgba(0,0,0,0.2), 1px 2px #000")).to eq("-1px 2px rgba(0,0,0,0.2) inset, -1px 2px #000")
|
218
237
|
end
|
219
238
|
|
220
239
|
end
|
221
240
|
|
222
241
|
describe "#border_radius_swap" do
|
223
242
|
it "should swap a valid quad value" do
|
224
|
-
r2.border_radius_swap("1px 2px 3px 4px").
|
243
|
+
expect(r2.border_radius_swap("1px 2px 3px 4px")).to eq("2px 1px 4px 3px")
|
225
244
|
end
|
226
245
|
|
227
246
|
it "should skip a triple value" do
|
228
|
-
r2.border_radius_swap("1px 2px 3px").
|
247
|
+
expect(r2.border_radius_swap("1px 2px 3px")).to eq("2px 1px 2px 3px")
|
229
248
|
end
|
230
249
|
|
231
250
|
it "should skip a pair value" do
|
232
|
-
r2.border_radius_swap("1px 2px").
|
251
|
+
expect(r2.border_radius_swap("1px 2px")).to eq("2px 1px")
|
233
252
|
end
|
234
253
|
end
|
235
254
|
|
@@ -237,23 +256,23 @@ describe R2::Swapper do
|
|
237
256
|
|
238
257
|
context "with a single value" do
|
239
258
|
it "should ignore a named-vertical" do
|
240
|
-
r2.background_position_swap('top').
|
259
|
+
expect(r2.background_position_swap('top')).to eq('top')
|
241
260
|
end
|
242
261
|
|
243
262
|
it "should swap a named-horizontal 'left'" do
|
244
|
-
r2.background_position_swap('left').
|
263
|
+
expect(r2.background_position_swap('left')).to eq('right')
|
245
264
|
end
|
246
265
|
|
247
266
|
it "should swap a named-horizontal 'right'" do
|
248
|
-
r2.background_position_swap('right').
|
267
|
+
expect(r2.background_position_swap('right')).to eq('left')
|
249
268
|
end
|
250
269
|
|
251
270
|
it "should invert a percentage" do
|
252
|
-
r2.background_position_swap('25%').
|
271
|
+
expect(r2.background_position_swap('25%')).to eq('75%')
|
253
272
|
end
|
254
273
|
|
255
274
|
it "should convert a unit value" do
|
256
|
-
r2.background_position_swap('25px').
|
275
|
+
expect(r2.background_position_swap('25px')).to eq('right 25px center')
|
257
276
|
end
|
258
277
|
end
|
259
278
|
|
@@ -264,35 +283,35 @@ describe R2::Swapper do
|
|
264
283
|
# See: http://dev.w3.org/csswg/css3-background/#background-position
|
265
284
|
|
266
285
|
it "should swap named-horizontal and ignore named-vertical" do
|
267
|
-
r2.background_position_swap('right bottom').
|
286
|
+
expect(r2.background_position_swap('right bottom')).to eq('left bottom')
|
268
287
|
end
|
269
288
|
|
270
289
|
it "should swap named-horizontal and ignore unit-vertical" do
|
271
|
-
r2.background_position_swap('left 100px').
|
290
|
+
expect(r2.background_position_swap('left 100px')).to eq('right 100px')
|
272
291
|
end
|
273
292
|
|
274
293
|
it "should convert unit-horizontal" do
|
275
|
-
r2.background_position_swap('100px center').
|
294
|
+
expect(r2.background_position_swap('100px center')).to eq('right 100px center')
|
276
295
|
end
|
277
296
|
|
278
297
|
it "should swap named-horizontal and ignore percentage-vertical" do
|
279
|
-
r2.background_position_swap('left 0%').
|
298
|
+
expect(r2.background_position_swap('left 0%')).to eq('right 0%')
|
280
299
|
end
|
281
300
|
|
282
301
|
it "should invert first percentage-horizontal value in a pair" do
|
283
|
-
r2.background_position_swap('25% 100%').
|
302
|
+
expect(r2.background_position_swap('25% 100%')).to eq('75% 100%')
|
284
303
|
end
|
285
304
|
end
|
286
305
|
|
287
306
|
context "with a triplet of values" do
|
288
307
|
it "should swap named-horizontal" do
|
289
|
-
r2.background_position_swap('left 20px center').
|
308
|
+
expect(r2.background_position_swap('left 20px center')).to eq('right 20px center')
|
290
309
|
end
|
291
310
|
end
|
292
311
|
|
293
312
|
context "with a quad of values" do
|
294
313
|
it "should swap named-horizontal value" do
|
295
|
-
r2.background_position_swap('bottom 10px left 20px').
|
314
|
+
expect(r2.background_position_swap('bottom 10px left 20px')).to eq('bottom 10px right 20px')
|
296
315
|
end
|
297
316
|
end
|
298
317
|
end
|
metadata
CHANGED
@@ -1,43 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Sanford
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '3.4'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 3.4.0
|
34
37
|
type: :development
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - ~>
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '3.4'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 3.4.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec-mocks
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.4.0
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 3.4.0
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 3.4.0
|
64
|
+
- - ">="
|
39
65
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
66
|
+
version: 3.4.0
|
41
67
|
description: CSS flipper for right-to-left processing. A Ruby port of https://github.com/ded/r2
|
42
68
|
email:
|
43
69
|
- matt@twitter.com
|
@@ -46,8 +72,8 @@ executables:
|
|
46
72
|
extensions: []
|
47
73
|
extra_rdoc_files: []
|
48
74
|
files:
|
49
|
-
- .gitignore
|
50
|
-
- .travis.yml
|
75
|
+
- ".gitignore"
|
76
|
+
- ".travis.yml"
|
51
77
|
- Gemfile
|
52
78
|
- Guardfile
|
53
79
|
- LICENSE
|
@@ -68,17 +94,17 @@ require_paths:
|
|
68
94
|
- lib
|
69
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
96
|
requirements:
|
71
|
-
- -
|
97
|
+
- - ">="
|
72
98
|
- !ruby/object:Gem::Version
|
73
99
|
version: '0'
|
74
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
101
|
requirements:
|
76
|
-
- -
|
102
|
+
- - ">="
|
77
103
|
- !ruby/object:Gem::Version
|
78
104
|
version: '0'
|
79
105
|
requirements: []
|
80
106
|
rubyforge_project: r2
|
81
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.2.2
|
82
108
|
signing_key:
|
83
109
|
specification_version: 4
|
84
110
|
summary: CSS flipper for right-to-left processing
|