r2 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +1 -0
- data/lib/r2.rb +14 -6
- data/lib/r2/version.rb +1 -1
- data/spec/r2_spec.rb +14 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1fa57a5b8f4000ba8d6e91882b7eda70ef205b3
|
4
|
+
data.tar.gz: 34e72abffc40f8b95266805d6e5275bf830eaf1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78b0b6a518f92747338fb1e0dbe32089ca82679ffca5dd7de2c867ae4691da8282926cb39fe08c6dc2f7ca16ec102f443935fba82561be3f22eb1110d7df7942
|
7
|
+
data.tar.gz: ac1f527bbb0a97dafb880e2d849f7a7e4f91137ab7af58997caef3ecd6995c545f556d7c5a7bef3a7311be96d0c2296e4770440943663836c5b0dbdda04446ed
|
data/.travis.yml
CHANGED
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.7 - Add an option to skip R2 processing on a CSS block (error report from [@mapmeld](https://github.com/mapmeld))
|
26
27
|
* v0.2.6 - Handle multi-row selectors (fix from [@n0nick](https://github.com/n0nick))
|
27
28
|
* v0.2.5 - Handle `background:` shorthand
|
28
29
|
* v0.2.4 - Handle `url()` properties better
|
data/lib/r2.rb
CHANGED
@@ -10,6 +10,9 @@ require 'r2/shadow_flipper'
|
|
10
10
|
|
11
11
|
module R2
|
12
12
|
|
13
|
+
# A string that indicates this block should be skipped
|
14
|
+
SKIP_TOKEN = 'SKIP_R2'
|
15
|
+
|
13
16
|
# Short cut method for providing a one-time CSS change
|
14
17
|
def self.r2(css)
|
15
18
|
::R2::Swapper.new.r2(css)
|
@@ -77,9 +80,13 @@ module R2
|
|
77
80
|
# it is a selector with "{" or a closing "}", insert as it is. This is
|
78
81
|
# things like ".foo {" and its matching "}"
|
79
82
|
rule_str = rule
|
83
|
+
elsif rule.match(/#{SKIP_TOKEN}/)
|
84
|
+
# A body that is being skipped
|
85
|
+
rule_str = rule.sub(SKIP_TOKEN, '')
|
80
86
|
else
|
81
87
|
# It is a declaration body, like "padding-left:4px;margin-left:5px;"
|
82
88
|
rule_str = ""
|
89
|
+
|
83
90
|
# Split up the individual rules in the body and process each swap. To handle the
|
84
91
|
# possible ";" in the url() definitions, like
|
85
92
|
# url("data;base64") and url("data:image/svg+xml;charset=...")
|
@@ -109,11 +116,12 @@ module R2
|
|
109
116
|
def minimize(css)
|
110
117
|
return '' unless css
|
111
118
|
|
112
|
-
css.gsub(
|
113
|
-
gsub(
|
114
|
-
gsub(
|
115
|
-
gsub(/\s
|
116
|
-
gsub(
|
119
|
+
css.gsub(/\/\*\s*no-r2\s*\*\//, SKIP_TOKEN). # special skip comment
|
120
|
+
gsub(/\/\*[\s\S]+?\*\//, ''). # comments
|
121
|
+
gsub(/[\n\r]+/, ' '). # line breaks and carriage returns
|
122
|
+
gsub(/\s*([:;,\{\}])\s*/, '\1'). # space between selectors, declarations, properties and values
|
123
|
+
gsub(/\s+/, ' '). # replace multiple spaces with single spaces
|
124
|
+
gsub(/(\A\s+|\s+\z)/, '') # leading or trailing spaces
|
117
125
|
end
|
118
126
|
|
119
127
|
# 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)
|
@@ -241,7 +249,7 @@ module R2
|
|
241
249
|
end
|
242
250
|
|
243
251
|
# If first point is a unit-value
|
244
|
-
if match = points[0].match(/^(
|
252
|
+
if match = points[0].match(/^(-?\d+[a-z]{2,3})/)
|
245
253
|
val = ["right", match[1], points[1] || "center"].compact.join(' ')
|
246
254
|
end
|
247
255
|
|
data/lib/r2/version.rb
CHANGED
data/spec/r2_spec.rb
CHANGED
@@ -107,6 +107,19 @@ describe R2::Swapper do
|
|
107
107
|
|
108
108
|
expect(r2.r2(css)).to eq(expected)
|
109
109
|
end
|
110
|
+
|
111
|
+
it "handles no-r2 comment" do
|
112
|
+
css = <<-EOS
|
113
|
+
.sprite.foo {
|
114
|
+
/* no-r2 */
|
115
|
+
background-position: 0px -50px;
|
116
|
+
}
|
117
|
+
EOS
|
118
|
+
|
119
|
+
expected = ".sprite.foo{ background-position:0px -50px;}"
|
120
|
+
|
121
|
+
expect(r2.r2(css)).to eq(expected)
|
122
|
+
end
|
110
123
|
end
|
111
124
|
|
112
125
|
describe "#declaration_swap" do
|
@@ -274,6 +287,7 @@ describe R2::Swapper do
|
|
274
287
|
it "should convert a unit value" do
|
275
288
|
expect(r2.background_position_swap('25px')).to eq('right 25px center')
|
276
289
|
end
|
290
|
+
|
277
291
|
end
|
278
292
|
|
279
293
|
context "with a pair of values" 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.
|
4
|
+
version: 0.2.7
|
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: 2017-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
106
|
rubyforge_project: r2
|
107
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.5.2
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: CSS flipper for right-to-left processing
|