roadie 3.1.0 → 3.1.1
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/.travis.yml +2 -0
- data/Changelog.md +9 -2
- data/README.md +1 -1
- data/lib/roadie.rb +1 -0
- data/lib/roadie/deduplicator.rb +46 -0
- data/lib/roadie/style_attribute_builder.rb +1 -1
- data/lib/roadie/version.rb +1 -1
- data/spec/integration_spec.rb +22 -0
- data/spec/lib/roadie/deduplicator_spec.rb +30 -0
- data/spec/lib/roadie/inliner_spec.rb +22 -1
- data/spec/lib/roadie/style_attribute_builder_spec.rb +10 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc05f1423ea7579bcf0dbe77db9fca005476eab1
|
4
|
+
data.tar.gz: 28839fad6470f4b466346d63d0b0b3a96ae7e612
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e62a3b9333e939b9c16b811f3d37ef3db08cd086e15d43fe13f932045af71bfc6551a9a9c57b6f89398c9a8bd5fe5af091e1ef66109149e621a8d3f329f9e9be
|
7
|
+
data.tar.gz: 2c851d5ca9539fbf2db20368b8d7178a9d433e24541f26534416c0720afdc1b5fcfd55d4ff0d4188e3f3e2a9c66e43a2360d8563e3e5125838e4af4deedd22ae
|
data/.travis.yml
CHANGED
data/Changelog.md
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
### dev
|
2
2
|
|
3
|
-
[full changelog](https://github.com/Mange/roadie/compare/v3.1.
|
3
|
+
[full changelog](https://github.com/Mange/roadie/compare/v3.1.1...master)
|
4
4
|
|
5
|
-
|
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.
|
48
|
+
gem 'roadie', '~> 3.1.1'
|
49
49
|
```
|
50
50
|
|
51
51
|
You can then create a new instance of a Roadie document:
|
data/lib/roadie.rb
CHANGED
@@ -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
|
data/lib/roadie/version.rb
CHANGED
data/spec/integration_spec.rb
CHANGED
@@ -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.
|
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
|
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.
|
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
|