roadie 3.5.1 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -0
- data/.travis.yml +1 -3
- data/Changelog.md +9 -3
- data/Gemfile +2 -0
- data/README.md +1 -1
- data/Rakefile +2 -1
- data/lib/roadie.rb +2 -0
- data/lib/roadie/asset_provider.rb +2 -0
- data/lib/roadie/asset_scanner.rb +2 -0
- data/lib/roadie/cached_provider.rb +2 -0
- data/lib/roadie/deduplicator.rb +2 -0
- data/lib/roadie/document.rb +3 -1
- data/lib/roadie/errors.rb +4 -2
- data/lib/roadie/filesystem_provider.rb +2 -0
- data/lib/roadie/inliner.rb +2 -0
- data/lib/roadie/markup_improver.rb +2 -0
- data/lib/roadie/net_http_provider.rb +2 -1
- data/lib/roadie/null_provider.rb +2 -0
- data/lib/roadie/null_url_rewriter.rb +5 -1
- data/lib/roadie/path_rewriter_provider.rb +2 -0
- data/lib/roadie/provider_list.rb +2 -0
- data/lib/roadie/rspec.rb +2 -0
- data/lib/roadie/rspec/asset_provider.rb +2 -0
- data/lib/roadie/rspec/cache_store.rb +2 -0
- data/lib/roadie/selector.rb +2 -0
- data/lib/roadie/style_attribute_builder.rb +2 -0
- data/lib/roadie/style_block.rb +2 -0
- data/lib/roadie/style_property.rb +2 -0
- data/lib/roadie/stylesheet.rb +3 -1
- data/lib/roadie/url_generator.rb +2 -0
- data/lib/roadie/url_rewriter.rb +6 -6
- data/lib/roadie/utils.rb +2 -0
- data/lib/roadie/version.rb +2 -1
- data/roadie.gemspec +3 -1
- data/spec/hash_as_cache_store_spec.rb +2 -0
- data/spec/integration_spec.rb +2 -0
- data/spec/lib/roadie/asset_scanner_spec.rb +2 -1
- data/spec/lib/roadie/cached_provider_spec.rb +2 -0
- data/spec/lib/roadie/css_not_found_spec.rb +2 -0
- data/spec/lib/roadie/deduplicator_spec.rb +2 -0
- data/spec/lib/roadie/document_spec.rb +2 -1
- data/spec/lib/roadie/filesystem_provider_spec.rb +2 -1
- data/spec/lib/roadie/inliner_spec.rb +2 -1
- data/spec/lib/roadie/markup_improver_spec.rb +2 -1
- data/spec/lib/roadie/net_http_provider_spec.rb +9 -7
- data/spec/lib/roadie/null_provider_spec.rb +2 -1
- data/spec/lib/roadie/null_url_rewriter_spec.rb +2 -1
- data/spec/lib/roadie/path_rewriter_provider_spec.rb +2 -0
- data/spec/lib/roadie/provider_list_spec.rb +2 -1
- data/spec/lib/roadie/selector_spec.rb +2 -1
- data/spec/lib/roadie/style_attribute_builder_spec.rb +2 -0
- data/spec/lib/roadie/style_block_spec.rb +2 -1
- data/spec/lib/roadie/style_property_spec.rb +2 -0
- data/spec/lib/roadie/stylesheet_spec.rb +2 -1
- data/spec/lib/roadie/test_provider_spec.rb +2 -0
- data/spec/lib/roadie/url_generator_spec.rb +2 -1
- data/spec/lib/roadie/url_rewriter_spec.rb +4 -3
- data/spec/lib/roadie/utils_spec.rb +2 -0
- data/spec/shared_examples/asset_provider.rb +2 -0
- data/spec/shared_examples/url_rewriter.rb +5 -3
- data/spec/spec_helper.rb +2 -0
- data/spec/support/have_attribute_matcher.rb +2 -0
- data/spec/support/have_node_matcher.rb +2 -0
- data/spec/support/have_selector_matcher.rb +2 -0
- data/spec/support/have_styling_matcher.rb +2 -0
- data/spec/support/have_xpath_matcher.rb +2 -0
- data/spec/support/test_provider.rb +2 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17f87e779aab695788d0361a733cd56f81b74d4d89bc9c82eb1949f9bdec1796
|
4
|
+
data.tar.gz: 608a6d3a482a827123818c45acaf9709f4dd214328809e43d327fd860ce0d455
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d512b9c8568ec0514161689fa8cb678d3c975b11ec9b6d9b7b1f31c09ad166788c88e195161b7b101256d229de36dec6abcc77f420dfddd6b663ce82233cdfcd
|
7
|
+
data.tar.gz: c94e1245d485c0824057868010d849b24b37faf6fd69ab59989a3f6bae0bf02284255550fa67fef79c0355c95a149d1ad34ec9e22b0ecc8b8c1eec6888ae0545
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/Changelog.md
CHANGED
@@ -1,10 +1,16 @@
|
|
1
1
|
### dev
|
2
2
|
|
3
|
-
|
3
|
+
[full changelog](https://github.com/Mange/roadie/compare/v4.0.0...master)
|
4
|
+
|
5
|
+
Nothing yet.
|
6
|
+
|
7
|
+
### 4.0.0
|
4
8
|
|
5
|
-
[full changelog](https://github.com/Mange/roadie/compare/v3.5.1...
|
9
|
+
[full changelog](https://github.com/Mange/roadie/compare/v3.5.1...v4.0.0)
|
6
10
|
|
7
|
-
*
|
11
|
+
* Drop support for Ruby 2.1, 2.2, and 2.3 and
|
12
|
+
add support for frozen string literals and Ruby 2.6 - [adamkiczula (Adam
|
13
|
+
Kiczula)](https://github.com/adamkiczula) (#164)
|
8
14
|
|
9
15
|
### 3.5.1
|
10
16
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -55,7 +55,7 @@ Install & Usage
|
|
55
55
|
[Add this gem to your Gemfile as recommended by Rubygems](http://rubygems.org/gems/roadie) and run `bundle install`.
|
56
56
|
|
57
57
|
```ruby
|
58
|
-
gem 'roadie', '~>
|
58
|
+
gem 'roadie', '~> 4.0'
|
59
59
|
```
|
60
60
|
|
61
61
|
You can then create a new instance of a Roadie document:
|
data/Rakefile
CHANGED
data/lib/roadie.rb
CHANGED
data/lib/roadie/asset_scanner.rb
CHANGED
data/lib/roadie/deduplicator.rb
CHANGED
data/lib/roadie/document.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Roadie
|
2
4
|
# The main entry point for Roadie. A document represents a working unit and
|
3
5
|
# is built with the input HTML and the configuration options you need.
|
@@ -50,7 +52,7 @@ module Roadie
|
|
50
52
|
@html = html
|
51
53
|
@asset_providers = ProviderList.wrap(FilesystemProvider.new)
|
52
54
|
@external_asset_providers = ProviderList.empty
|
53
|
-
@css = ""
|
55
|
+
@css = +""
|
54
56
|
@mode = :html
|
55
57
|
end
|
56
58
|
|
data/lib/roadie/errors.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Roadie
|
2
4
|
# Base class for all Roadie errors. Rescue this if you want to catch errors
|
3
5
|
# from Roadie.
|
@@ -58,7 +60,7 @@ module Roadie
|
|
58
60
|
# Redundant method argument is to keep API compatability without major version bump.
|
59
61
|
# TODO: Remove argument on version 4.0.
|
60
62
|
def build_message(extra_message = @extra_message)
|
61
|
-
message =
|
63
|
+
message = +%(Could not find stylesheet "#{css_name}")
|
62
64
|
message << ": #{extra_message}" if extra_message
|
63
65
|
message << "\nUsed provider:\n#{provider}" if provider
|
64
66
|
message
|
@@ -75,7 +77,7 @@ module Roadie
|
|
75
77
|
|
76
78
|
private
|
77
79
|
def build_message(extra_message)
|
78
|
-
message =
|
80
|
+
message = +%(Could not find stylesheet "#{css_name}": #{extra_message}\nUsed providers:\n)
|
79
81
|
each_error_row(errors) do |row|
|
80
82
|
message << "\t" << row << "\n"
|
81
83
|
end
|
data/lib/roadie/inliner.rb
CHANGED
data/lib/roadie/null_provider.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Roadie
|
2
4
|
# @api private
|
3
5
|
# Null Object for the URL rewriter role.
|
@@ -7,6 +9,8 @@ module Roadie
|
|
7
9
|
class NullUrlRewriter
|
8
10
|
def initialize(generator = nil) end
|
9
11
|
def transform_dom(dom) end
|
10
|
-
def transform_css(css)
|
12
|
+
def transform_css(css)
|
13
|
+
css
|
14
|
+
end
|
11
15
|
end
|
12
16
|
end
|
data/lib/roadie/provider_list.rb
CHANGED
data/lib/roadie/rspec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
shared_examples_for "roadie asset provider" do |options|
|
2
4
|
valid_name = options[:valid_name] or raise "You must provide a :valid_name option to the shared examples"
|
3
5
|
invalid_name = options[:invalid_name] or raise "You must provide an :invalid_name option to the shared examples"
|
data/lib/roadie/selector.rb
CHANGED
data/lib/roadie/style_block.rb
CHANGED
data/lib/roadie/stylesheet.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Roadie
|
2
4
|
# Domain object that represents a stylesheet (from disc, perhaps).
|
3
5
|
#
|
@@ -6,7 +8,7 @@ module Roadie
|
|
6
8
|
# @attr_reader [String] name the name of the stylesheet ("stylesheets/main.css", "Admin user styles", etc.). The name of the stylesheet will be visible if any errors occur.
|
7
9
|
# @attr_reader [Array<StyleBlock>] blocks
|
8
10
|
class Stylesheet
|
9
|
-
BOM = "\xEF\xBB\xBF".force_encoding('UTF-8').freeze
|
11
|
+
BOM = (+"\xEF\xBB\xBF").force_encoding('UTF-8').freeze
|
10
12
|
|
11
13
|
attr_reader :name, :blocks
|
12
14
|
|
data/lib/roadie/url_generator.rb
CHANGED
data/lib/roadie/url_rewriter.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Roadie
|
2
4
|
# @api private
|
3
5
|
#
|
@@ -35,13 +37,12 @@ module Roadie
|
|
35
37
|
#
|
36
38
|
# This will make all URLs inside url() absolute.
|
37
39
|
#
|
38
|
-
#
|
39
|
-
# the passed string.
|
40
|
+
# Copy of CSS that is mutated is returned, passed string is not mutated.
|
40
41
|
#
|
41
42
|
# @param [String] css the css to mutate
|
42
|
-
# @return [
|
43
|
+
# @return [String] copy of css that is mutated
|
43
44
|
def transform_css(css)
|
44
|
-
css.gsub
|
45
|
+
css.gsub(CSS_URL_REGEXP) do
|
45
46
|
matches = Regexp.last_match
|
46
47
|
"url(#{matches[:quote]}#{generate_url(matches[:url])}#{matches[:quote]})"
|
47
48
|
end
|
@@ -81,8 +82,7 @@ module Roadie
|
|
81
82
|
# We need to use a setter for Nokogiri to detect the string mutation.
|
82
83
|
# If nokogiri used "dumber" data structures, this would all be redundant.
|
83
84
|
css = element["style"]
|
84
|
-
transform_css
|
85
|
-
element["style"] = css
|
85
|
+
element["style"] = transform_css(css)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
data/lib/roadie/utils.rb
CHANGED
data/lib/roadie/version.rb
CHANGED
data/roadie.gemspec
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# roadie.gemspec
|
2
3
|
# -*- encoding: utf-8 -*-
|
3
4
|
|
@@ -15,13 +16,14 @@ Gem::Specification.new do |s|
|
|
15
16
|
s.description = %q{Roadie tries to make sending HTML emails a little less painful by inlining stylesheets and rewriting relative URLs for you.}
|
16
17
|
s.license = "MIT"
|
17
18
|
|
18
|
-
s.required_ruby_version = ">=
|
19
|
+
s.required_ruby_version = ">= 2.4"
|
19
20
|
|
20
21
|
s.add_dependency 'nokogiri', '~> 1.8'
|
21
22
|
s.add_dependency 'css_parser', '~> 1.4'
|
22
23
|
|
23
24
|
s.add_development_dependency 'rspec', '~> 3.0'
|
24
25
|
s.add_development_dependency 'rspec-collection_matchers', '~> 1.0'
|
26
|
+
s.add_development_dependency 'rubocop', '0.75.0'
|
25
27
|
s.add_development_dependency 'webmock', '~> 3.0'
|
26
28
|
|
27
29
|
s.extra_rdoc_files = %w[README.md Changelog.md]
|
data/spec/integration_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'roadie/rspec'
|
3
5
|
require 'shared_examples/asset_provider'
|
@@ -18,13 +20,13 @@ module Roadie
|
|
18
20
|
invalid_name: "http://example.com/red.css"
|
19
21
|
) do
|
20
22
|
before do
|
21
|
-
stub_request(:get, "http://example.com/green.css").and_return(body: "p { color: green; }")
|
23
|
+
stub_request(:get, "http://example.com/green.css").and_return(body: +"p { color: green; }")
|
22
24
|
stub_request(:get, "http://example.com/red.css").and_return(status: 404, body: "Not here!")
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
28
|
it "can download over HTTPS" do
|
27
|
-
stub_request(:get, "https://example.com/style.css").and_return(body: "p { color: green; }")
|
29
|
+
stub_request(:get, "https://example.com/style.css").and_return(body: +"p { color: green; }")
|
28
30
|
expect {
|
29
31
|
NetHttpProvider.new.find_stylesheet!("https://example.com/style.css")
|
30
32
|
}.to_not raise_error
|
@@ -37,7 +39,7 @@ module Roadie
|
|
37
39
|
# asset inlining, but the scheme-less URL implies that there should exist
|
38
40
|
# both a HTTP and a HTTPS endpoint. Let's take the secure one in that
|
39
41
|
# case!
|
40
|
-
stub_request(:get, "https://example.com/style.css").and_return(body: "p { color: green; }")
|
42
|
+
stub_request(:get, "https://example.com/style.css").and_return(body: +"p { color: green; }")
|
41
43
|
expect {
|
42
44
|
NetHttpProvider.new.find_stylesheet!("//example.com/style.css")
|
43
45
|
}.to_not raise_error
|
@@ -48,7 +50,7 @@ module Roadie
|
|
48
50
|
# (US-ASCII). The headers will indicate what charset the client should
|
49
51
|
# use when trying to make sense of these bytes.
|
50
52
|
stub_request(:get, url).and_return(
|
51
|
-
body:
|
53
|
+
body: (+%(p::before { content: "l\xF6ve" })).force_encoding("US-ASCII"),
|
52
54
|
headers: {"Content-Type" => "text/css;charset=ISO-8859-1"},
|
53
55
|
)
|
54
56
|
|
@@ -64,7 +66,7 @@ module Roadie
|
|
64
66
|
|
65
67
|
it "assumes UTF-8 encoding if server headers do not specify a charset" do
|
66
68
|
stub_request(:get, url).and_return(
|
67
|
-
body:
|
69
|
+
body: (+%(p::before { content: "Åh nej" })).force_encoding("US-ASCII"),
|
68
70
|
headers: {"Content-Type" => "text/css"},
|
69
71
|
)
|
70
72
|
|
@@ -119,8 +121,8 @@ module Roadie
|
|
119
121
|
whitelisted_url = "http://whitelisted.example.com/style.css"
|
120
122
|
other_url = "http://www.example.com/style.css"
|
121
123
|
|
122
|
-
whitelisted_request = stub_request(:get, whitelisted_url).and_return(body: "x")
|
123
|
-
other_request = stub_request(:get, other_url).and_return(body: "x")
|
124
|
+
whitelisted_request = stub_request(:get, whitelisted_url).and_return(body: +"x")
|
125
|
+
other_request = stub_request(:get, other_url).and_return(body: +"x")
|
124
126
|
|
125
127
|
expect(provider.find_stylesheet(other_url)).to be_nil
|
126
128
|
expect {
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'shared_examples/url_rewriter'
|
3
5
|
|
@@ -71,9 +73,8 @@ module Roadie
|
|
71
73
|
it "rewrites all url() directives" do
|
72
74
|
expect(generator).to receive(:generate_url).with("some/path.jpg").and_return "http://foo.com/image.jpg"
|
73
75
|
css = "body { background: top url(some/path.jpg) #eee; }"
|
74
|
-
|
75
|
-
|
76
|
-
}.to change { css }.to "body { background: top url(http://foo.com/image.jpg) #eee; }"
|
76
|
+
transformed_css = rewriter.transform_css css
|
77
|
+
expect(transformed_css).to eq "body { background: top url(http://foo.com/image.jpg) #eee; }"
|
77
78
|
end
|
78
79
|
|
79
80
|
it "correctly identifies URLs with single quotes" do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
shared_examples_for "url rewriter" do
|
2
4
|
it "is constructed with a generator" do
|
3
5
|
generator = double "URL generator"
|
@@ -6,7 +8,7 @@ shared_examples_for "url rewriter" do
|
|
6
8
|
}.to_not raise_error
|
7
9
|
end
|
8
10
|
|
9
|
-
it "has a #transform_dom(dom) method that returns
|
11
|
+
it "has a #transform_dom(dom) method that returns the modified string" do
|
10
12
|
expect(subject).to respond_to(:transform_dom)
|
11
13
|
expect(subject.method(:transform_dom).arity).to eq(1)
|
12
14
|
|
@@ -14,10 +16,10 @@ shared_examples_for "url rewriter" do
|
|
14
16
|
expect(subject.transform_dom(dom)).to be_nil
|
15
17
|
end
|
16
18
|
|
17
|
-
it "has a #transform_css(css) method that returns
|
19
|
+
it "has a #transform_css(css) method that returns the modified string" do
|
18
20
|
expect(subject).to respond_to(:transform_css)
|
19
21
|
expect(subject.method(:transform_css).arity).to eq(1)
|
20
22
|
|
21
|
-
expect(subject.transform_css("")).to
|
23
|
+
expect(subject.transform_css("")).to eq("")
|
22
24
|
end
|
23
25
|
end
|
data/spec/spec_helper.rb
CHANGED
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:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magnus Bergmark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.75.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.75.0
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: webmock
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -92,6 +106,7 @@ extra_rdoc_files:
|
|
92
106
|
files:
|
93
107
|
- ".autotest"
|
94
108
|
- ".gitignore"
|
109
|
+
- ".rubocop.yml"
|
95
110
|
- ".travis.yml"
|
96
111
|
- ".yardopts"
|
97
112
|
- Changelog.md
|
@@ -174,7 +189,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
174
189
|
requirements:
|
175
190
|
- - ">="
|
176
191
|
- !ruby/object:Gem::Version
|
177
|
-
version: '
|
192
|
+
version: '2.4'
|
178
193
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
194
|
requirements:
|
180
195
|
- - ">="
|