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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8550ffae3d9358c1257e8163f6a5d03d945d09f
4
- data.tar.gz: 3a0e2808776280f8c3a87de5d1cf7baa5a18af8d
3
+ metadata.gz: d1fa57a5b8f4000ba8d6e91882b7eda70ef205b3
4
+ data.tar.gz: 34e72abffc40f8b95266805d6e5275bf830eaf1a
5
5
  SHA512:
6
- metadata.gz: d1de570c1fc501a5e278d2757bba45aacce956ef3d39660e9e3f661de8bbf7812391729407363882d9a98bb386bbff37ec8de588f85e9b49592679d3175aac1c
7
- data.tar.gz: 6c80710ffed22c49310fec1766d478e4df07c10af0a9bed75ec3a1ea1c02c18f3da29d311517355fcff44c374fab99c183ca9fc39c034a18300c922938f83f96
6
+ metadata.gz: 78b0b6a518f92747338fb1e0dbe32089ca82679ffca5dd7de2c867ae4691da8282926cb39fe08c6dc2f7ca16ec102f443935fba82561be3f22eb1110d7df7942
7
+ data.tar.gz: ac1f527bbb0a97dafb880e2d849f7a7e4f91137ab7af58997caef3ecd6995c545f556d7c5a7bef3a7311be96d0c2296e4770440943663836c5b0dbdda04446ed
@@ -1,5 +1,5 @@
1
1
 
2
2
  language: ruby
3
3
  rvm:
4
- - 1.9.3
4
+ - 2.2
5
5
  - jruby-19mode # JRuby in 1.9 mode
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(/\/\*[\s\S]+?\*\//, ''). # comments
113
- gsub(/[\n\r]+/, ' '). # line breaks and carriage returns
114
- gsub(/\s*([:;,\{\}])\s*/, '\1'). # space between selectors, declarations, properties and values
115
- gsub(/\s+/, ' '). # replace multiple spaces with single spaces
116
- gsub(/(\A\s+|\s+\z)/, '') # leading or trailing spaces
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(/^(\d+[a-z]{2,3})/)
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
 
@@ -1,3 +1,3 @@
1
1
  module R2
2
- VERSION = "0.2.6"
2
+ VERSION = "0.2.7"
3
3
  end
@@ -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.6
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: 2015-11-20 00:00:00.000000000 Z
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.2.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