roadie 3.5.1 → 5.1.0
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/.github/workflows/main.yml +46 -0
- data/.rubocop.yml +5 -0
- data/.solargraph.yml +16 -0
- data/Changelog.md +35 -4
- data/Gemfile +7 -2
- data/README.md +14 -14
- data/Rakefile +4 -3
- data/lib/roadie/asset_provider.rb +5 -1
- data/lib/roadie/asset_scanner.rb +8 -6
- data/lib/roadie/cached_provider.rb +3 -0
- data/lib/roadie/deduplicator.rb +3 -0
- data/lib/roadie/document.rb +24 -17
- data/lib/roadie/errors.rb +22 -16
- data/lib/roadie/filesystem_provider.rb +15 -3
- data/lib/roadie/inliner.rb +51 -19
- data/lib/roadie/markup_improver.rb +24 -31
- data/lib/roadie/net_http_provider.rb +27 -12
- data/lib/roadie/null_provider.rb +20 -5
- data/lib/roadie/null_url_rewriter.rb +11 -3
- data/lib/roadie/path_rewriter_provider.rb +6 -1
- data/lib/roadie/provider_list.rb +17 -11
- data/lib/roadie/rspec/asset_provider.rb +6 -1
- data/lib/roadie/rspec/cache_store.rb +2 -0
- data/lib/roadie/rspec.rb +4 -2
- data/lib/roadie/selector.rb +18 -5
- data/lib/roadie/style_attribute_builder.rb +4 -1
- data/lib/roadie/style_block.rb +5 -3
- data/lib/roadie/style_property.rb +5 -2
- data/lib/roadie/stylesheet.rb +4 -13
- data/lib/roadie/url_generator.rb +26 -8
- data/lib/roadie/url_rewriter.rb +12 -9
- data/lib/roadie/utils.rb +3 -1
- data/lib/roadie/version.rb +1 -1
- data/lib/roadie.rb +25 -23
- data/roadie.gemspec +23 -23
- data/spec/hash_as_cache_store_spec.rb +3 -1
- data/spec/integration_spec.rb +75 -44
- data/spec/lib/roadie/asset_scanner_spec.rb +11 -5
- data/spec/lib/roadie/cached_provider_spec.rb +6 -4
- data/spec/lib/roadie/css_not_found_spec.rb +10 -5
- data/spec/lib/roadie/deduplicator_spec.rb +5 -3
- data/spec/lib/roadie/document_spec.rb +57 -28
- data/spec/lib/roadie/filesystem_provider_spec.rb +10 -11
- data/spec/lib/roadie/inliner_spec.rb +42 -45
- data/spec/lib/roadie/markup_improver_spec.rb +19 -26
- data/spec/lib/roadie/net_http_provider_spec.rb +16 -14
- data/spec/lib/roadie/null_provider_spec.rb +4 -3
- data/spec/lib/roadie/null_url_rewriter_spec.rb +4 -3
- data/spec/lib/roadie/path_rewriter_provider_spec.rb +6 -4
- data/spec/lib/roadie/provider_list_spec.rb +27 -22
- data/spec/lib/roadie/selector_spec.rb +7 -5
- data/spec/lib/roadie/style_attribute_builder_spec.rb +7 -5
- data/spec/lib/roadie/style_block_spec.rb +3 -2
- data/spec/lib/roadie/style_property_spec.rb +10 -8
- data/spec/lib/roadie/stylesheet_spec.rb +4 -21
- data/spec/lib/roadie/test_provider_spec.rb +6 -4
- data/spec/lib/roadie/url_generator_spec.rb +3 -2
- data/spec/lib/roadie/url_rewriter_spec.rb +10 -7
- 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 +10 -8
- data/spec/support/have_attribute_matcher.rb +3 -2
- data/spec/support/have_node_matcher.rb +5 -3
- data/spec/support/have_selector_matcher.rb +4 -3
- data/spec/support/have_styling_matcher.rb +12 -11
- data/spec/support/have_xpath_matcher.rb +4 -3
- data/spec/support/test_provider.rb +2 -0
- metadata +24 -8
- data/.travis.yml +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39c01590157057fcedad04740a1594a45f18150d74c7e8fe071dd3aea6908e1f
|
4
|
+
data.tar.gz: 490cc578b42057ca635ce613d8e50b05401b0a07597761f70423467aa99aa673
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d71f85f1aba91c711351972b65074835f690f62d0cd4a0feb663f67df89a86d8acddc855fe7be4e23601fe3b0508c1558f6c18cc260c69c1ad5b1b1857ad04e2
|
7
|
+
data.tar.gz: 1d708c10a62800d44efbe825601546a8713b953f81a2549d91a23e74e26048839adc418d38c38bbd08bd885bc6504a3a07c5cca46f94d3ad147d347f3086ffaa
|
@@ -0,0 +1,46 @@
|
|
1
|
+
name: Main
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- main
|
6
|
+
- master
|
7
|
+
|
8
|
+
pull_request:
|
9
|
+
types: [opened, synchronize, reopened]
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
base:
|
13
|
+
name: Ruby ${{ matrix.ruby }}
|
14
|
+
runs-on: ubuntu-20.04
|
15
|
+
strategy:
|
16
|
+
fail-fast: false
|
17
|
+
matrix:
|
18
|
+
ruby: ["2.6", "2.7", "3.0", "3.1"]
|
19
|
+
|
20
|
+
steps:
|
21
|
+
- name: Checkout code
|
22
|
+
uses: actions/checkout@v2
|
23
|
+
|
24
|
+
# This setup is not compatible with the way Travis CI was
|
25
|
+
# setup, so the cache will only work for the root folder.
|
26
|
+
- name: Setup Ruby
|
27
|
+
uses: ruby/setup-ruby@v1
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby }}
|
30
|
+
bundler-cache: true
|
31
|
+
|
32
|
+
- name: Rake
|
33
|
+
run: bundle exec rake
|
34
|
+
|
35
|
+
- uses: codecov/codecov-action@v2
|
36
|
+
|
37
|
+
lint:
|
38
|
+
runs-on: ubuntu-latest
|
39
|
+
steps:
|
40
|
+
- name: standardrb
|
41
|
+
env:
|
42
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
43
|
+
uses: amoeba/standardrb-action@v2
|
44
|
+
permissions:
|
45
|
+
checks: write
|
46
|
+
contents: read
|
data/.rubocop.yml
ADDED
data/.solargraph.yml
ADDED
data/Changelog.md
CHANGED
@@ -1,10 +1,42 @@
|
|
1
1
|
### dev
|
2
2
|
|
3
|
-
|
3
|
+
[full changelog](https://github.com/Mange/roadie/compare/v5.1.0...master)
|
4
|
+
|
5
|
+
### 5.1.0
|
6
|
+
|
7
|
+
[full changelog](https://github.com/Mange/roadie/compare/v5.0.1...v5.1.0)
|
8
|
+
|
9
|
+
* Support passing serialization options to Nokogiri with `serialization_options=` method -
|
10
|
+
[Dmytro Savochkin](https://github.com/dmytro-savochkin). (#171)
|
11
|
+
|
12
|
+
### 5.0.1
|
13
|
+
|
14
|
+
[full changelog](https://github.com/Mange/roadie/compare/v5.0.0...v5.0.1)
|
4
15
|
|
5
|
-
[
|
16
|
+
* Don't try to inline [the `:host`
|
17
|
+
pseudo-class](https://developer.mozilla.org/en-US/docs/Web/CSS/:host) -
|
18
|
+
[viamin (Bart Agapinan)](https://github.com/viamin). (#170)
|
6
19
|
|
7
|
-
|
20
|
+
### 5.0.0
|
21
|
+
|
22
|
+
[full changelog](https://github.com/Mange/roadie/compare/v4.0.0...v5.0.0)
|
23
|
+
|
24
|
+
* Drop support for Ruby 2.4 and Ruby 2.5
|
25
|
+
* Drop support for JRuby and Rubinius
|
26
|
+
* Test with Ruby 2.7 - [aried3r (Anton Rieder)](https://github.com/aried3r) (#167)
|
27
|
+
* Test with Ruby 3.0 and Ruby 3.1
|
28
|
+
* Add standardrb as code formatter
|
29
|
+
* Drop support for callbacks that accepts only a single argument.
|
30
|
+
* Change signature of `Roadie::CssNotFound` and `Roadie::ProvidersFailed`.
|
31
|
+
|
32
|
+
### 4.0.0
|
33
|
+
|
34
|
+
[full changelog](https://github.com/Mange/roadie/compare/v3.5.1...v4.0.0)
|
35
|
+
|
36
|
+
* Drop support for Ruby 2.1, 2.2, and 2.3 and
|
37
|
+
add support for frozen string literals and Ruby 2.6 - [adamkiczula (Adam
|
38
|
+
Kiczula)](https://github.com/adamkiczula) (#164)
|
39
|
+
* `Roadie::Stylesheet#each_inlinable_block` is now removed.
|
8
40
|
|
9
41
|
### 3.5.1
|
10
42
|
|
@@ -380,4 +412,3 @@ Roadie fork!
|
|
380
412
|
* + some other enhancements
|
381
413
|
* Deprecations:
|
382
414
|
* Removed support for Rails 2.x
|
383
|
-
|
data/Gemfile
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
2
4
|
gemspec
|
3
5
|
|
4
6
|
# Added here so it does not show up on the Gemspec; I only want it for CI builds
|
5
|
-
gem
|
7
|
+
gem "codecov", group: :test, require: false
|
8
|
+
# Not actually required to run the tests for the gem, but a real convenience
|
9
|
+
# for local development.
|
10
|
+
gem "standard", group: [:test, :development], require: false
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
Roadie
|
2
2
|
======
|
3
3
|
|
4
|
-
[](http://travis-ci.org/#!/Mange/roadie)
|
5
4
|
[](https://codeclimate.com/github/Mange/roadie)
|
6
5
|
[](https://codecov.io/github/Mange/roadie?branch=master)
|
7
6
|
[](https://rubygems.org/gems/roadie)
|
@@ -55,7 +54,7 @@ Install & Usage
|
|
55
54
|
[Add this gem to your Gemfile as recommended by Rubygems](http://rubygems.org/gems/roadie) and run `bundle install`.
|
56
55
|
|
57
56
|
```ruby
|
58
|
-
gem 'roadie', '~>
|
57
|
+
gem 'roadie', '~> 4.0'
|
59
58
|
```
|
60
59
|
|
61
60
|
You can then create a new instance of a Roadie document:
|
@@ -95,6 +94,8 @@ Your document instance can be configured with several options:
|
|
95
94
|
* `external_asset_providers` - A list of asset providers that are invoked when absolute CSS URLs are referenced. See below.
|
96
95
|
* `before_transformation` - A callback run before transformation starts.
|
97
96
|
* `after_transformation` - A callback run after transformation is completed.
|
97
|
+
* `serialization_options` - An integer bitmap of options passed along to Nokogiri during serialization.
|
98
|
+
By default it's `Nokogiri::XML::Node::SaveOptions::NO_DECLARATION | Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS`.
|
98
99
|
|
99
100
|
### Making URLs absolute ###
|
100
101
|
|
@@ -333,7 +334,10 @@ class UserAssetsProvider
|
|
333
334
|
end
|
334
335
|
|
335
336
|
def find_stylesheet!(name)
|
336
|
-
find_stylesheet(name) or
|
337
|
+
find_stylesheet(name) or
|
338
|
+
raise Roadie::CssNotFound.new(
|
339
|
+
css_name: name, message: "does not match a user stylesheet", provider: self
|
340
|
+
)
|
337
341
|
end
|
338
342
|
|
339
343
|
# Instead of implementing #find_stylesheet!, you could also:
|
@@ -444,18 +448,14 @@ Partial documents does not have a `<!DOCTYPE>`.
|
|
444
448
|
Build Status
|
445
449
|
------------
|
446
450
|
|
447
|
-
Tested with
|
451
|
+
Tested with Github CI using:
|
448
452
|
|
449
|
-
* MRI 2.
|
450
|
-
* MRI 2.
|
451
|
-
* MRI
|
452
|
-
* MRI
|
453
|
-
* JRuby (latest)
|
454
|
-
* Rubinius (failures on Rubinius will not fail the build due to a long history of instability in `rbx`)
|
453
|
+
* MRI 2.6
|
454
|
+
* MRI 2.7
|
455
|
+
* MRI 3.0
|
456
|
+
* MRI 3.1
|
455
457
|
|
456
|
-
|
457
|
-
|
458
|
-
Let me know if you want any other VM supported officially.
|
458
|
+
Let me know if you want any other runtime supported officially.
|
459
459
|
|
460
460
|
### Versioning ###
|
461
461
|
|
@@ -565,7 +565,7 @@ License
|
|
565
565
|
|
566
566
|
(The MIT License)
|
567
567
|
|
568
|
-
Copyright (c) 2009-
|
568
|
+
Copyright (c) 2009-2022 Magnus Bergmark, Jim Neath / Purify, and contributors.
|
569
569
|
|
570
570
|
* [Magnus Bergmark](https://github.com/Mange) <magnus.bergmark@gmail.com>
|
571
571
|
|
data/Rakefile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/setup"
|
3
4
|
|
4
5
|
Bundler::GemHelper.install_tasks
|
5
6
|
|
@@ -9,4 +10,4 @@ task :spec do
|
|
9
10
|
end
|
10
11
|
|
11
12
|
desc "Default: Run specs"
|
12
|
-
task :
|
13
|
+
task default: :spec
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Roadie
|
2
4
|
# This module can be included in your own code to help you implement the
|
3
5
|
# standard behavior for asset providers.
|
@@ -5,7 +7,9 @@ module Roadie
|
|
5
7
|
# It helps you by declaring {#find_stylesheet!} in the terms of #find_stylesheet in your own class.
|
6
8
|
module AssetProvider
|
7
9
|
def find_stylesheet!(name)
|
8
|
-
find_stylesheet(name) or raise
|
10
|
+
find_stylesheet(name) or raise(
|
11
|
+
CssNotFound.new(css_name: name, provider: self)
|
12
|
+
)
|
9
13
|
end
|
10
14
|
end
|
11
15
|
end
|
data/lib/roadie/asset_scanner.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Roadie
|
2
4
|
# @api private
|
3
5
|
#
|
@@ -41,15 +43,15 @@ module Roadie
|
|
41
43
|
# @see #find_css
|
42
44
|
# @return [Enumerable<Stylesheet>] every extracted stylesheet
|
43
45
|
def extract_css
|
44
|
-
|
46
|
+
@dom.css(STYLE_ELEMENT_QUERY).map { |element|
|
45
47
|
stylesheet = read_stylesheet(element)
|
46
48
|
element.remove if stylesheet
|
47
49
|
stylesheet
|
48
50
|
}.compact
|
49
|
-
stylesheets
|
50
51
|
end
|
51
52
|
|
52
53
|
private
|
54
|
+
|
53
55
|
STYLE_ELEMENT_QUERY = (
|
54
56
|
"style:not([data-roadie-ignore]), " +
|
55
57
|
# TODO: When using Nokogiri 1.6.1 and later; we may use a double :not here
|
@@ -73,7 +75,7 @@ module Roadie
|
|
73
75
|
def read_stylesheet(element)
|
74
76
|
if element.name == "style"
|
75
77
|
read_style_element element
|
76
|
-
elsif element.name == "link" && element[
|
78
|
+
elsif element.name == "link" && element["media"] != "print" && element["href"]
|
77
79
|
read_link_element element
|
78
80
|
end
|
79
81
|
end
|
@@ -84,14 +86,14 @@ module Roadie
|
|
84
86
|
|
85
87
|
def read_link_element(element)
|
86
88
|
if Utils.path_is_absolute?(element["href"])
|
87
|
-
external_asset_provider.find_stylesheet! element[
|
89
|
+
external_asset_provider.find_stylesheet! element["href"] if should_find_external?
|
88
90
|
else
|
89
|
-
normal_asset_provider.find_stylesheet! element[
|
91
|
+
normal_asset_provider.find_stylesheet! element["href"]
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
93
95
|
def clean_css(css)
|
94
|
-
css.gsub(CLEANING_MATCHER,
|
96
|
+
css.gsub(CLEANING_MATCHER, "")
|
95
97
|
end
|
96
98
|
|
97
99
|
def should_find_external?
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Roadie
|
2
4
|
# @api public
|
3
5
|
# The {CachedProvider} wraps another provider (or {ProviderList}) and caches
|
@@ -67,6 +69,7 @@ module Roadie
|
|
67
69
|
end
|
68
70
|
|
69
71
|
private
|
72
|
+
|
70
73
|
def cache_fetch(name)
|
71
74
|
cache[name] || cache[name] = yield
|
72
75
|
rescue CssNotFound
|
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.
|
@@ -40,6 +42,10 @@ module Roadie
|
|
40
42
|
# which would change the styling on the page
|
41
43
|
attr_accessor :merge_media_queries
|
42
44
|
|
45
|
+
# Integer representing a bitmap set of options used by Nokogiri during serialization.
|
46
|
+
# For the complete set of available options look into +Nokogiri::XML::Node::SaveOptions+.
|
47
|
+
attr_reader :serialization_options
|
48
|
+
|
43
49
|
# The mode to generate markup in. Valid values are `:html` (default) and `:xhtml`.
|
44
50
|
attr_reader :mode
|
45
51
|
|
@@ -47,10 +53,13 @@ module Roadie
|
|
47
53
|
def initialize(html)
|
48
54
|
@keep_uninlinable_css = true
|
49
55
|
@merge_media_queries = true
|
56
|
+
@serialization_options =
|
57
|
+
Nokogiri::XML::Node::SaveOptions::NO_DECLARATION |
|
58
|
+
Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS
|
50
59
|
@html = html
|
51
60
|
@asset_providers = ProviderList.wrap(FilesystemProvider.new)
|
52
61
|
@external_asset_providers = ProviderList.empty
|
53
|
-
@css = ""
|
62
|
+
@css = +""
|
54
63
|
@mode = :html
|
55
64
|
end
|
56
65
|
|
@@ -135,11 +144,19 @@ module Roadie
|
|
135
144
|
@external_asset_providers = ProviderList.wrap(list)
|
136
145
|
end
|
137
146
|
|
147
|
+
# Integer representing a bitmap set of options used by Nokogiri during serialization.
|
148
|
+
# For the complete set of available options look into +Nokogiri::XML::Node::SaveOptions+.
|
149
|
+
# (To change the mode in which the document is generated use {#mode=} however.)
|
150
|
+
def serialization_options=(options)
|
151
|
+
@serialization_options = options || 0
|
152
|
+
end
|
153
|
+
|
138
154
|
# Change the mode. The mode affects how the resulting markup is generated.
|
139
155
|
#
|
140
156
|
# Valid modes:
|
141
157
|
# `:html` (default)
|
142
158
|
# `:xhtml`
|
159
|
+
# `:xml`
|
143
160
|
def mode=(mode)
|
144
161
|
if VALID_MODES.include?(mode)
|
145
162
|
@mode = mode
|
@@ -149,7 +166,8 @@ module Roadie
|
|
149
166
|
end
|
150
167
|
|
151
168
|
private
|
152
|
-
|
169
|
+
|
170
|
+
VALID_MODES = %i[html xhtml xml].freeze
|
153
171
|
private_constant :VALID_MODES
|
154
172
|
|
155
173
|
def stylesheet
|
@@ -166,7 +184,7 @@ module Roadie
|
|
166
184
|
Inliner.new(dom_stylesheets + [stylesheet], dom).inline(
|
167
185
|
keep_uninlinable_css: keep_uninlinable_css,
|
168
186
|
keep_uninlinable_in: keep_uninlinable_in,
|
169
|
-
merge_media_queries: merge_media_queries
|
187
|
+
merge_media_queries: merge_media_queries
|
170
188
|
)
|
171
189
|
end
|
172
190
|
|
@@ -180,15 +198,10 @@ module Roadie
|
|
180
198
|
format = {
|
181
199
|
html: save_options::AS_HTML,
|
182
200
|
xhtml: save_options::AS_XHTML,
|
201
|
+
xml: save_options::AS_XML
|
183
202
|
}.fetch(mode)
|
184
203
|
|
185
|
-
dom.dup.to_html(
|
186
|
-
save_with: (
|
187
|
-
save_options::NO_DECLARATION |
|
188
|
-
save_options::NO_EMPTY_TAGS |
|
189
|
-
format
|
190
|
-
),
|
191
|
-
)
|
204
|
+
dom.dup.to_html(save_with: (serialization_options | format))
|
192
205
|
end
|
193
206
|
|
194
207
|
def make_url_rewriter
|
@@ -201,13 +214,7 @@ module Roadie
|
|
201
214
|
|
202
215
|
def callback(callable, dom)
|
203
216
|
if callable.respond_to?(:call)
|
204
|
-
|
205
|
-
# TODO: Remove on next major version (v4.0)
|
206
|
-
if !callable.respond_to?(:parameters) || callable.parameters.size == 1
|
207
|
-
callable.(dom)
|
208
|
-
else
|
209
|
-
callable.(dom, self)
|
210
|
-
end
|
217
|
+
callable.call(dom, self)
|
211
218
|
end
|
212
219
|
end
|
213
220
|
|
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.
|
@@ -16,10 +18,10 @@ module Roadie
|
|
16
18
|
|
17
19
|
def initialize(given_path, cause = nil)
|
18
20
|
@cause = cause
|
19
|
-
if cause
|
20
|
-
|
21
|
+
cause_message = if cause
|
22
|
+
" Caused by: #{cause}"
|
21
23
|
else
|
22
|
-
|
24
|
+
""
|
23
25
|
end
|
24
26
|
super "Cannot use path \"#{given_path}\" in URL generation.#{cause_message}"
|
25
27
|
end
|
@@ -41,24 +43,23 @@ module Roadie
|
|
41
43
|
# Extra message
|
42
44
|
attr_reader :extra_message
|
43
45
|
|
44
|
-
|
45
|
-
def initialize(css_name, extra_message = nil, provider = nil)
|
46
|
+
def initialize(css_name:, message: nil, provider: nil)
|
46
47
|
@css_name = css_name
|
47
48
|
@provider = provider
|
48
|
-
@extra_message =
|
49
|
-
super build_message
|
49
|
+
@extra_message = message
|
50
|
+
super build_message
|
50
51
|
end
|
51
52
|
|
52
53
|
protected
|
54
|
+
|
53
55
|
def error_row
|
54
|
-
"#{provider || "Unknown provider"}: #{extra_message
|
56
|
+
"#{provider || "Unknown provider"}: #{extra_message}"
|
55
57
|
end
|
56
58
|
|
57
59
|
private
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
message = %(Could not find stylesheet "#{css_name}")
|
60
|
+
|
61
|
+
def build_message
|
62
|
+
message = +%(Could not find stylesheet "#{css_name}")
|
62
63
|
message << ": #{extra_message}" if extra_message
|
63
64
|
message << "\nUsed provider:\n#{provider}" if provider
|
64
65
|
message
|
@@ -68,14 +69,19 @@ module Roadie
|
|
68
69
|
class ProvidersFailed < CssNotFound
|
69
70
|
attr_reader :errors
|
70
71
|
|
71
|
-
def initialize(css_name
|
72
|
+
def initialize(css_name:, providers:, errors:)
|
72
73
|
@errors = errors
|
73
|
-
super(
|
74
|
+
super(
|
75
|
+
css_name: css_name,
|
76
|
+
message: "All providers failed",
|
77
|
+
provider: providers
|
78
|
+
)
|
74
79
|
end
|
75
80
|
|
76
81
|
private
|
77
|
-
|
78
|
-
|
82
|
+
|
83
|
+
def build_message
|
84
|
+
message = +%(Could not find stylesheet "#{css_name}": #{extra_message}\nUsed providers:\n)
|
79
85
|
each_error_row(errors) do |row|
|
80
86
|
message << "\t" << row << "\n"
|
81
87
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Roadie
|
2
4
|
# Asset provider that looks for files on your local filesystem.
|
3
5
|
#
|
@@ -30,14 +32,24 @@ module Roadie
|
|
30
32
|
Stylesheet.new file_path, File.read(file_path)
|
31
33
|
else
|
32
34
|
basename = File.basename file_path
|
33
|
-
raise CssNotFound.new(
|
35
|
+
raise CssNotFound.new(
|
36
|
+
css_name: basename,
|
37
|
+
message: %{#{file_path} does not exist. (Original name was "#{name}")},
|
38
|
+
provider: self
|
39
|
+
)
|
34
40
|
end
|
35
41
|
end
|
36
42
|
|
37
|
-
def to_s
|
38
|
-
|
43
|
+
def to_s
|
44
|
+
inspect
|
45
|
+
end
|
46
|
+
|
47
|
+
def inspect
|
48
|
+
"#<#{self.class} #{@path}>"
|
49
|
+
end
|
39
50
|
|
40
51
|
private
|
52
|
+
|
41
53
|
def build_file_path(name)
|
42
54
|
raise InsecurePathError, name if name.include?("..")
|
43
55
|
File.join(@path, name[/^([^?]+)/])
|