roadie 3.1.0 → 3.1.1

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: 3ea2ec3b852bbfcc4562e71aad5d934164f513ca
4
- data.tar.gz: cdde955813d54457a745a16b81be79185884a997
3
+ metadata.gz: dc05f1423ea7579bcf0dbe77db9fca005476eab1
4
+ data.tar.gz: 28839fad6470f4b466346d63d0b0b3a96ae7e612
5
5
  SHA512:
6
- metadata.gz: d89044d3d2ac136f025b86a1a92df95f44b895411840478f127642875a40f8cbc4f743c4a4b6be6ee2e9fb95c95c328e5386262142a92cf7dfc26004f274b4b7
7
- data.tar.gz: f53d0fca7bf1fd95bfcc2036c434d242e67babefe183b2752bb82d1ca506c0f5bfb9c19114842d4fcaed104fbbdfa8dceb943375493f30231584113640b20005
6
+ metadata.gz: e62a3b9333e939b9c16b811f3d37ef3db08cd086e15d43fe13f932045af71bfc6551a9a9c57b6f89398c9a8bd5fe5af091e1ef66109149e621a8d3f329f9e9be
7
+ data.tar.gz: 2c851d5ca9539fbf2db20368b8d7178a9d433e24541f26534416c0720afdc1b5fcfd55d4ff0d4188e3f3e2a9c66e43a2360d8563e3e5125838e4af4deedd22ae
@@ -1,3 +1,4 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
4
  - 1.9.3
@@ -7,6 +8,7 @@ rvm:
7
8
  - jruby
8
9
  - rbx
9
10
 
11
+ cache: bundler
10
12
  bundler_args: --without guard
11
13
  script: "rake"
12
14
 
@@ -1,8 +1,15 @@
1
1
  ### dev
2
2
 
3
- [full changelog](https://github.com/Mange/roadie/compare/v3.1.0...master)
3
+ [full changelog](https://github.com/Mange/roadie/compare/v3.1.1...master)
4
4
 
5
- * Nothing yet.
5
+ ### 3.1.1
6
+
7
+ [full changelog](https://github.com/Mange/roadie/compare/v3.1.0...v3.1.1)
8
+
9
+ * Enhancements:
10
+ * Duplicate style properties are now removed when inlining.
11
+ * This means that `color: green; color: red; color: green` will now be `color: red; color: green`.
12
+ * The size of your emails should be the same, or smaller.
6
13
 
7
14
  ### 3.1.0
8
15
 
data/README.md CHANGED
@@ -45,7 +45,7 @@ Install & Usage
45
45
  [Add this gem to your Gemfile as recommended by Rubygems](http://rubygems.org/gems/roadie) and run `bundle install`.
46
46
 
47
47
  ```ruby
48
- gem 'roadie', '~> 3.1.0'
48
+ gem 'roadie', '~> 3.1.1'
49
49
  ```
50
50
 
51
51
  You can then create a new instance of a Roadie document:
@@ -5,6 +5,7 @@ require 'roadie/version'
5
5
  require 'roadie/errors'
6
6
 
7
7
  require 'roadie/utils'
8
+ require 'roadie/deduplicator'
8
9
 
9
10
  require 'roadie/stylesheet'
10
11
  require 'roadie/selector'
@@ -0,0 +1,46 @@
1
+ module Roadie
2
+ class Deduplicator
3
+ def self.apply(input)
4
+ new(input).apply
5
+ end
6
+
7
+ def initialize(input)
8
+ @input = input
9
+ @duplicates = false
10
+ end
11
+
12
+ def apply
13
+ # Bail early for very small inputs
14
+ input if input.size < 2
15
+
16
+ calculate_latest_occurance
17
+
18
+ # Another early bail in case we never even have a duplicate value
19
+ if has_duplicates?
20
+ strip_out_duplicates
21
+ else
22
+ input
23
+ end
24
+ end
25
+
26
+ private
27
+ attr_reader :input, :latest_occurance
28
+
29
+ def has_duplicates?
30
+ @duplicates
31
+ end
32
+
33
+ def calculate_latest_occurance
34
+ @latest_occurance = input.each_with_index.each_with_object({}) do |(value, index), map|
35
+ @duplicates = true if map.has_key?(value)
36
+ map[value] = index
37
+ end
38
+ end
39
+
40
+ def strip_out_duplicates
41
+ input.each_with_index.select { |value, index|
42
+ latest_occurance[value] == index
43
+ }.map(&:first)
44
+ end
45
+ end
46
+ end
@@ -9,7 +9,7 @@ module Roadie
9
9
  end
10
10
 
11
11
  def attribute_string
12
- stable_sort(@styles).map(&:to_s).join(';')
12
+ Deduplicator.apply(stable_sort(@styles).map(&:to_s)).join(';')
13
13
  end
14
14
 
15
15
  private
@@ -1,3 +1,3 @@
1
1
  module Roadie
2
- VERSION = '3.1.0'
2
+ VERSION = '3.1.1'
3
3
  end
@@ -176,6 +176,28 @@ describe "Roadie functionality" do
176
176
  expect(result).to_not have_selector('head > link')
177
177
  end
178
178
 
179
+ it "does not inline the same properties several times" do
180
+ document = Roadie::Document.new <<-HTML
181
+ <head>
182
+ <link rel="stylesheet" href="hello.css">
183
+ </head>
184
+ <body>
185
+ <p class="hello world">Hello world</p>
186
+ </body>
187
+ HTML
188
+
189
+ document.asset_providers = TestProvider.new("hello.css" => <<-CSS)
190
+ p { color: red; }
191
+ .hello { color: red; }
192
+ .world { color: red; }
193
+ CSS
194
+
195
+ result = parse_html document.transform
196
+ expect(result).to have_styling([
197
+ ['color', 'red']
198
+ ]).at_selector('p')
199
+ end
200
+
179
201
  it "makes URLs absolute" do
180
202
  document = Roadie::Document.new <<-HTML
181
203
  <!DOCTYPE html>
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ module Roadie
4
+ describe Deduplicator do
5
+ it "removes identical pairs, keeping the last one" do
6
+ input = [
7
+ ["a", "1"],
8
+ ["b", "2"],
9
+ ["a", "3"],
10
+ ["a", "1"],
11
+ ]
12
+
13
+ expect(Deduplicator.apply(input)).to eq [
14
+ ["b", "2"],
15
+ ["a", "3"],
16
+ ["a", "1"],
17
+ ]
18
+ end
19
+
20
+ it "returns input when no duplicates are present" do
21
+ input = [
22
+ ["a", "1"],
23
+ ["a", "3"],
24
+ ["a", "2"],
25
+ ]
26
+
27
+ expect(Deduplicator.apply(input)).to eq input
28
+ end
29
+ end
30
+ end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  module Roadie
5
5
  describe Inliner do
6
- before { @stylesheet = "" }
6
+ before { @stylesheet = "".freeze }
7
7
  def use_css(css) @stylesheet = Stylesheet.new("example", css) end
8
8
 
9
9
  def rendering(html, stylesheet = @stylesheet)
@@ -18,6 +18,27 @@ module Roadie
18
18
  expect(rendering('<p></p>')).to have_styling('color' => 'green')
19
19
  end
20
20
 
21
+ it "keeps multiple versions of the same property to support progressive enhancement" do
22
+ # https://github.com/premailer/css_parser/issues/44
23
+ pending "css_parser issue #44"
24
+
25
+ use_css 'p { color: #eee; color: rgba(255, 255, 255, 0.9); }'
26
+ expect(rendering('<p></p>')).to have_styling(
27
+ [['color', 'green'], ['color', 'rgba(255, 255, 255, 0.9)']]
28
+ )
29
+ end
30
+
31
+ it "de-duplicates identical styles" do
32
+ use_css '
33
+ p { color: green; }
34
+ .message { color: blue; }
35
+ .positive { color: green; }
36
+ '
37
+ expect(rendering('<p class="message positive"></p>')).to have_styling(
38
+ [['color', 'blue'], ['color', 'green']]
39
+ )
40
+ end
41
+
21
42
  it "inlines browser-prefixed attributes" do
22
43
  use_css 'p { -vendor-color: green }'
23
44
  expect(rendering('<p></p>')).to have_styling('-vendor-color' => 'green')
@@ -25,5 +25,15 @@ module Roadie
25
25
 
26
26
  expect(builder.attribute_string).to eq "background:white;color:pink;color:red;color:green"
27
27
  end
28
+
29
+ it "removes duplicate properties" do
30
+ builder = StyleAttributeBuilder.new
31
+
32
+ builder << StyleProperty.new("color", "pink", false, 10)
33
+ builder << StyleProperty.new("color", "green", false, 20)
34
+ builder << StyleProperty.new("color", "pink", false, 50)
35
+
36
+ expect(builder.attribute_string).to eq "color:green;color:pink"
37
+ end
28
38
  end
29
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roadie
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnus Bergmark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-17 00:00:00.000000000 Z
11
+ date: 2015-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -111,6 +111,7 @@ files:
111
111
  - lib/roadie/asset_provider.rb
112
112
  - lib/roadie/asset_scanner.rb
113
113
  - lib/roadie/cached_provider.rb
114
+ - lib/roadie/deduplicator.rb
114
115
  - lib/roadie/document.rb
115
116
  - lib/roadie/errors.rb
116
117
  - lib/roadie/filesystem_provider.rb
@@ -141,6 +142,7 @@ files:
141
142
  - spec/lib/roadie/asset_scanner_spec.rb
142
143
  - spec/lib/roadie/cached_provider_spec.rb
143
144
  - spec/lib/roadie/css_not_found_spec.rb
145
+ - spec/lib/roadie/deduplicator_spec.rb
144
146
  - spec/lib/roadie/document_spec.rb
145
147
  - spec/lib/roadie/filesystem_provider_spec.rb
146
148
  - spec/lib/roadie/inliner_spec.rb
@@ -187,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
189
  version: '0'
188
190
  requirements: []
189
191
  rubyforge_project:
190
- rubygems_version: 2.2.2
192
+ rubygems_version: 2.4.6
191
193
  signing_key:
192
194
  specification_version: 4
193
195
  summary: Making HTML emails comfortable for the Ruby rockstars
@@ -199,6 +201,7 @@ test_files:
199
201
  - spec/lib/roadie/asset_scanner_spec.rb
200
202
  - spec/lib/roadie/cached_provider_spec.rb
201
203
  - spec/lib/roadie/css_not_found_spec.rb
204
+ - spec/lib/roadie/deduplicator_spec.rb
202
205
  - spec/lib/roadie/document_spec.rb
203
206
  - spec/lib/roadie/filesystem_provider_spec.rb
204
207
  - spec/lib/roadie/inliner_spec.rb