roadie 4.0.0 → 5.0.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 +43 -0
- data/.solargraph.yml +16 -0
- data/Changelog.md +14 -2
- data/Gemfile +5 -2
- data/README.md +11 -13
- data/Rakefile +2 -2
- data/lib/roadie/asset_provider.rb +3 -1
- data/lib/roadie/asset_scanner.rb +6 -6
- data/lib/roadie/cached_provider.rb +1 -0
- data/lib/roadie/deduplicator.rb +1 -0
- data/lib/roadie/document.rb +7 -10
- data/lib/roadie/errors.rb +18 -14
- data/lib/roadie/filesystem_provider.rb +13 -3
- data/lib/roadie/inliner.rb +49 -19
- data/lib/roadie/markup_improver.rb +22 -31
- data/lib/roadie/net_http_provider.rb +25 -11
- data/lib/roadie/null_provider.rb +18 -5
- data/lib/roadie/null_url_rewriter.rb +6 -2
- data/lib/roadie/path_rewriter_provider.rb +4 -1
- data/lib/roadie/provider_list.rb +15 -11
- data/lib/roadie/rspec/asset_provider.rb +4 -1
- data/lib/roadie/rspec.rb +2 -2
- data/lib/roadie/selector.rb +15 -5
- data/lib/roadie/style_attribute_builder.rb +2 -1
- data/lib/roadie/style_block.rb +3 -3
- data/lib/roadie/style_property.rb +3 -2
- data/lib/roadie/stylesheet.rb +2 -13
- data/lib/roadie/url_generator.rb +24 -8
- data/lib/roadie/url_rewriter.rb +6 -3
- data/lib/roadie/utils.rb +1 -1
- data/lib/roadie/version.rb +1 -2
- data/lib/roadie.rb +23 -23
- data/roadie.gemspec +23 -25
- data/spec/hash_as_cache_store_spec.rb +1 -1
- data/spec/integration_spec.rb +41 -44
- data/spec/lib/roadie/asset_scanner_spec.rb +9 -4
- data/spec/lib/roadie/cached_provider_spec.rb +4 -4
- data/spec/lib/roadie/css_not_found_spec.rb +8 -5
- data/spec/lib/roadie/deduplicator_spec.rb +3 -3
- data/spec/lib/roadie/document_spec.rb +45 -27
- data/spec/lib/roadie/filesystem_provider_spec.rb +8 -10
- data/spec/lib/roadie/inliner_spec.rb +40 -44
- data/spec/lib/roadie/markup_improver_spec.rb +17 -25
- data/spec/lib/roadie/net_http_provider_spec.rb +8 -8
- data/spec/lib/roadie/null_provider_spec.rb +2 -2
- data/spec/lib/roadie/null_url_rewriter_spec.rb +2 -2
- data/spec/lib/roadie/path_rewriter_provider_spec.rb +4 -4
- data/spec/lib/roadie/provider_list_spec.rb +25 -21
- data/spec/lib/roadie/selector_spec.rb +4 -4
- data/spec/lib/roadie/style_attribute_builder_spec.rb +5 -5
- data/spec/lib/roadie/style_block_spec.rb +1 -1
- data/spec/lib/roadie/style_property_spec.rb +8 -8
- data/spec/lib/roadie/stylesheet_spec.rb +2 -20
- data/spec/lib/roadie/test_provider_spec.rb +4 -4
- data/spec/lib/roadie/url_generator_spec.rb +1 -1
- data/spec/lib/roadie/url_rewriter_spec.rb +6 -4
- data/spec/spec_helper.rb +8 -8
- data/spec/support/have_attribute_matcher.rb +1 -2
- data/spec/support/have_node_matcher.rb +3 -3
- data/spec/support/have_selector_matcher.rb +2 -3
- data/spec/support/have_styling_matcher.rb +10 -11
- data/spec/support/have_xpath_matcher.rb +2 -3
- metadata +22 -21
- data/.travis.yml +0 -20
data/spec/integration_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
describe "Roadie functionality" do
|
6
6
|
describe "on full documents" do
|
@@ -13,14 +13,7 @@ describe "Roadie functionality" do
|
|
13
13
|
document = Roadie::Document.new(html)
|
14
14
|
result = document.transform
|
15
15
|
|
16
|
-
|
17
|
-
# JRuby has a bug that makes DTD manipulation impossible
|
18
|
-
# See Nokogiri bugs #984 and #985
|
19
|
-
# https://github.com/sparklemotion/nokogiri/issues/984
|
20
|
-
# https://github.com/sparklemotion/nokogiri/issues/985
|
21
|
-
expect(result).to include("<!DOCTYPE html>")
|
22
|
-
end
|
23
|
-
|
16
|
+
expect(result).to include("<!DOCTYPE html>")
|
24
17
|
expect(result).to include("<html>")
|
25
18
|
expect(result).to include("<head>")
|
26
19
|
expect(result).to include("<body>")
|
@@ -47,8 +40,8 @@ describe "Roadie functionality" do
|
|
47
40
|
CSS
|
48
41
|
|
49
42
|
result = parse_html document.transform
|
50
|
-
expect(result).to have_styling(
|
51
|
-
expect(result).to have_styling(
|
43
|
+
expect(result).to have_styling("text-align" => "center").at_selector("h1")
|
44
|
+
expect(result).to have_styling("color" => "red").at_selector("p > em")
|
52
45
|
end
|
53
46
|
|
54
47
|
it "stores styles that cannot be inlined in the <head>" do
|
@@ -112,7 +105,7 @@ describe "Roadie functionality" do
|
|
112
105
|
HTML
|
113
106
|
|
114
107
|
result = parse_html document.transform
|
115
|
-
expect(result).to have_styling(
|
108
|
+
expect(result).to have_styling("font-size" => "200%").at_selector("p > em")
|
116
109
|
end
|
117
110
|
|
118
111
|
it "crashes when stylesheets cannot be found, unless using NullProvider" do
|
@@ -127,7 +120,9 @@ describe "Roadie functionality" do
|
|
127
120
|
</html>
|
128
121
|
HTML
|
129
122
|
|
130
|
-
expect {
|
123
|
+
expect {
|
124
|
+
document.transform
|
125
|
+
}.to raise_error(Roadie::CssNotFound, /does_not_exist\.css/)
|
131
126
|
|
132
127
|
document.asset_providers << Roadie::NullProvider.new
|
133
128
|
expect { document.transform }.to_not raise_error
|
@@ -151,8 +146,8 @@ describe "Roadie functionality" do
|
|
151
146
|
document.external_asset_providers = []
|
152
147
|
|
153
148
|
result = parse_html document.transform
|
154
|
-
expect(result).to have_selector(
|
155
|
-
expect(result).to have_styling([]).at_selector(
|
149
|
+
expect(result).to have_selector("head > link")
|
150
|
+
expect(result).to have_styling([]).at_selector("p > em")
|
156
151
|
end
|
157
152
|
|
158
153
|
it "inlines external css if configured" do
|
@@ -175,8 +170,8 @@ describe "Roadie functionality" do
|
|
175
170
|
)
|
176
171
|
|
177
172
|
result = parse_html document.transform
|
178
|
-
expect(result).to have_styling(
|
179
|
-
expect(result).to_not have_selector(
|
173
|
+
expect(result).to have_styling("font-size" => "200%").at_selector("p > em")
|
174
|
+
expect(result).to_not have_selector("head > link")
|
180
175
|
end
|
181
176
|
|
182
177
|
it "does not inline the same properties several times" do
|
@@ -197,8 +192,8 @@ describe "Roadie functionality" do
|
|
197
192
|
|
198
193
|
result = parse_html document.transform
|
199
194
|
expect(result).to have_styling([
|
200
|
-
[
|
201
|
-
]).at_selector(
|
195
|
+
["color", "red"]
|
196
|
+
]).at_selector("p")
|
202
197
|
end
|
203
198
|
|
204
199
|
it "makes URLs absolute" do
|
@@ -232,7 +227,7 @@ describe "Roadie functionality" do
|
|
232
227
|
).at_selector("body")
|
233
228
|
|
234
229
|
expect(result).to have_styling(
|
235
|
-
"background" =>
|
230
|
+
"background" => "url(https://myapp.com/rails/app/assets/link-abcdef1234567890.png)"
|
236
231
|
).at_selector("a")
|
237
232
|
end
|
238
233
|
|
@@ -324,10 +319,10 @@ describe "Roadie functionality" do
|
|
324
319
|
)
|
325
320
|
|
326
321
|
result = parse_html document.transform
|
327
|
-
expect(result).to have_styling(
|
322
|
+
expect(result).to have_styling("color" => "green").at_selector(".colorful")
|
328
323
|
end
|
329
324
|
|
330
|
-
it
|
325
|
+
it "puts non-inlineable media queries in the head" do
|
331
326
|
document = Roadie::Document.new <<-HTML
|
332
327
|
<html>
|
333
328
|
<head>
|
@@ -353,18 +348,18 @@ describe "Roadie functionality" do
|
|
353
348
|
|
354
349
|
result = parse_html document.transform
|
355
350
|
|
356
|
-
styles = result.at_css(
|
351
|
+
styles = result.at_css("html > head > style").text
|
357
352
|
expected_result = <<-CSS
|
358
353
|
@media screen and (max-width 800px) { .colorful{color:blue} }
|
359
354
|
@media screen, print and (max-width 800px) { .colorful{color:blue} }
|
360
355
|
CSS
|
361
|
-
expected_result = expected_result.gsub(
|
362
|
-
actual_result = styles.gsub(
|
356
|
+
expected_result = expected_result.gsub(/\s+/, " ").strip
|
357
|
+
actual_result = styles.gsub(/\s+/, " ").strip
|
363
358
|
|
364
359
|
expect(actual_result).to eq(expected_result)
|
365
360
|
end
|
366
361
|
|
367
|
-
it
|
362
|
+
it "groups non-inlineable media queries in the head by default" do
|
368
363
|
document = Roadie::Document.new <<-HTML
|
369
364
|
<html>
|
370
365
|
<head>
|
@@ -390,20 +385,20 @@ describe "Roadie functionality" do
|
|
390
385
|
|
391
386
|
result = parse_html document.transform
|
392
387
|
|
393
|
-
styles = result.at_css(
|
388
|
+
styles = result.at_css("html > head > style").text
|
394
389
|
expected_result = <<-CSS
|
395
390
|
@media screen and (max-width 600px) {
|
396
391
|
.colorful{color:red;width:600px}
|
397
392
|
.colorful-2{color:red;width:600px}
|
398
393
|
}
|
399
394
|
CSS
|
400
|
-
expected_result = expected_result.gsub(
|
401
|
-
actual_result = styles.gsub(
|
395
|
+
expected_result = expected_result.gsub(/\s+/, " ").strip
|
396
|
+
actual_result = styles.gsub(/\s+/, " ").strip
|
402
397
|
|
403
398
|
expect(actual_result).to eq(expected_result)
|
404
399
|
end
|
405
400
|
|
406
|
-
describe
|
401
|
+
describe "if merge_media_queries is set to false" do
|
407
402
|
it "doesn't group non-inlineable media queries in the head" do
|
408
403
|
document = Roadie::Document.new <<-HTML
|
409
404
|
<html>
|
@@ -432,7 +427,7 @@ describe "Roadie functionality" do
|
|
432
427
|
|
433
428
|
result = parse_html document.transform
|
434
429
|
|
435
|
-
styles = result.at_css(
|
430
|
+
styles = result.at_css("html > head > style").text
|
436
431
|
expected_result = <<-CSS
|
437
432
|
@media screen and (max-width 600px) {
|
438
433
|
.colorful{color:red;width:600px}
|
@@ -441,8 +436,8 @@ describe "Roadie functionality" do
|
|
441
436
|
.colorful-2{color:red;width:600px}
|
442
437
|
}
|
443
438
|
CSS
|
444
|
-
expected_result = expected_result.gsub(
|
445
|
-
actual_result = styles.gsub(
|
439
|
+
expected_result = expected_result.gsub(/\s+/, " ").strip
|
440
|
+
actual_result = styles.gsub(/\s+/, " ").strip
|
446
441
|
|
447
442
|
expect(actual_result).to eq(expected_result)
|
448
443
|
end
|
@@ -474,8 +469,8 @@ describe "Roadie functionality" do
|
|
474
469
|
CSS
|
475
470
|
|
476
471
|
result = parse_html document.transform_partial
|
477
|
-
expect(result).to have_styling(
|
478
|
-
expect(result).to have_styling(
|
472
|
+
expect(result).to have_styling("text-align" => "center").at_selector("h1")
|
473
|
+
expect(result).to have_styling("color" => "red").at_selector("p > em")
|
479
474
|
end
|
480
475
|
|
481
476
|
it "stores styles that cannot be inlined in a new <style> element" do
|
@@ -523,7 +518,7 @@ describe "Roadie functionality" do
|
|
523
518
|
HTML
|
524
519
|
|
525
520
|
result = parse_html document.transform_partial
|
526
|
-
expect(result).to have_styling(
|
521
|
+
expect(result).to have_styling("font-size" => "200%").at_selector("p > em")
|
527
522
|
end
|
528
523
|
|
529
524
|
it "crashes when stylesheets cannot be found, unless using NullProvider" do
|
@@ -531,7 +526,9 @@ describe "Roadie functionality" do
|
|
531
526
|
<link rel="stylesheet" href="/spec/fixtures/does_not_exist.css">
|
532
527
|
HTML
|
533
528
|
|
534
|
-
expect {
|
529
|
+
expect {
|
530
|
+
document.transform_partial
|
531
|
+
}.to raise_error(Roadie::CssNotFound, /does_not_exist\.css/)
|
535
532
|
|
536
533
|
document.asset_providers << Roadie::NullProvider.new
|
537
534
|
expect { document.transform_partial }.to_not raise_error
|
@@ -547,8 +544,8 @@ describe "Roadie functionality" do
|
|
547
544
|
document.external_asset_providers = []
|
548
545
|
|
549
546
|
result = parse_html document.transform_partial
|
550
|
-
expect(result).to have_xpath(
|
551
|
-
expect(result).to have_styling([]).at_selector(
|
547
|
+
expect(result).to have_xpath("./link")
|
548
|
+
expect(result).to have_styling([]).at_selector("p > em")
|
552
549
|
end
|
553
550
|
|
554
551
|
it "inlines external css if configured" do
|
@@ -563,8 +560,8 @@ describe "Roadie functionality" do
|
|
563
560
|
)
|
564
561
|
|
565
562
|
result = parse_html document.transform_partial
|
566
|
-
expect(result).to have_styling(
|
567
|
-
expect(result).to_not have_xpath(
|
563
|
+
expect(result).to have_styling("font-size" => "200%").at_selector("p > em")
|
564
|
+
expect(result).to_not have_xpath("./link")
|
568
565
|
end
|
569
566
|
|
570
567
|
it "does not inline the same properties several times" do
|
@@ -581,8 +578,8 @@ describe "Roadie functionality" do
|
|
581
578
|
|
582
579
|
result = parse_html document.transform_partial
|
583
580
|
expect(result).to have_styling([
|
584
|
-
[
|
585
|
-
]).at_selector(
|
581
|
+
["color", "red"]
|
582
|
+
]).at_selector("p")
|
586
583
|
end
|
587
584
|
|
588
585
|
it "makes URLs absolute" do
|
@@ -615,7 +612,7 @@ describe "Roadie functionality" do
|
|
615
612
|
).at_selector("div")
|
616
613
|
|
617
614
|
expect(result).to have_styling(
|
618
|
-
"background" =>
|
615
|
+
"background" => "url(https://myapp.com/rails/app/assets/link-abcdef1234567890.png)"
|
619
616
|
).at_selector("a")
|
620
617
|
end
|
621
618
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
module Roadie
|
6
6
|
describe AssetScanner do
|
@@ -8,8 +8,13 @@ module Roadie
|
|
8
8
|
let(:external_provider) { ProviderList.empty }
|
9
9
|
let(:dom) { dom_document "<html></html>" }
|
10
10
|
|
11
|
-
def dom_fragment(html)
|
12
|
-
|
11
|
+
def dom_fragment(html)
|
12
|
+
Nokogiri::HTML.fragment html
|
13
|
+
end
|
14
|
+
|
15
|
+
def dom_document(html)
|
16
|
+
Nokogiri::HTML.parse html
|
17
|
+
end
|
13
18
|
|
14
19
|
it "is initialized with a DOM tree, a normal asset provider set, and an external asset provider set" do
|
15
20
|
scanner = AssetScanner.new dom, normal_provider, external_provider
|
@@ -111,7 +116,7 @@ module Roadie
|
|
111
116
|
expect(scanner.find_css).to eq([])
|
112
117
|
end
|
113
118
|
|
114
|
-
it
|
119
|
+
it "ignores HTML comments and CDATA sections" do
|
115
120
|
# TinyMCE posts invalid CSS. We support that just to be pragmatic.
|
116
121
|
dom = dom_fragment %(<style><![CDATA[
|
117
122
|
<!--
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "spec_helper"
|
4
|
+
require "roadie/rspec"
|
5
|
+
require "shared_examples/asset_provider"
|
6
6
|
|
7
7
|
module Roadie
|
8
8
|
describe CachedProvider do
|
9
9
|
let(:upstream) { TestProvider.new("good.css" => "body { color: green; }") }
|
10
|
-
let(:cache) {
|
10
|
+
let(:cache) { {} }
|
11
11
|
subject(:provider) { CachedProvider.new(upstream, cache) }
|
12
12
|
|
13
13
|
it_behaves_like "roadie asset provider", valid_name: "good.css", invalid_name: "bad.css"
|
@@ -1,24 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
module Roadie
|
6
6
|
describe CssNotFound do
|
7
7
|
it "is initialized with a name" do
|
8
|
-
error = CssNotFound.new(
|
9
|
-
expect(error.css_name).to eq(
|
8
|
+
error = CssNotFound.new(css_name: "style.css")
|
9
|
+
expect(error.css_name).to eq("style.css")
|
10
10
|
expect(error.message).to eq('Could not find stylesheet "style.css"')
|
11
11
|
end
|
12
12
|
|
13
13
|
it "can be initialized with an extra message" do
|
14
|
-
|
14
|
+
error = CssNotFound.new(css_name: "file.css", message: "directory is missing")
|
15
|
+
expect(error.message).to eq(
|
15
16
|
'Could not find stylesheet "file.css": directory is missing'
|
16
17
|
)
|
17
18
|
end
|
18
19
|
|
19
20
|
it "shows information about used provider when given" do
|
20
21
|
provider = double("Some cool provider")
|
21
|
-
|
22
|
+
error = CssNotFound.new(css_name: "style.css", provider: provider)
|
23
|
+
|
24
|
+
expect(error.message).to eq(
|
22
25
|
%(Could not find stylesheet "style.css"\nUsed provider:\n#{provider})
|
23
26
|
)
|
24
27
|
end
|
@@ -9,13 +9,13 @@ module Roadie
|
|
9
9
|
["a", "1"],
|
10
10
|
["b", "2"],
|
11
11
|
["a", "3"],
|
12
|
-
["a", "1"]
|
12
|
+
["a", "1"]
|
13
13
|
]
|
14
14
|
|
15
15
|
expect(Deduplicator.apply(input)).to eq [
|
16
16
|
["b", "2"],
|
17
17
|
["a", "3"],
|
18
|
-
["a", "1"]
|
18
|
+
["a", "1"]
|
19
19
|
]
|
20
20
|
end
|
21
21
|
|
@@ -23,7 +23,7 @@ module Roadie
|
|
23
23
|
input = [
|
24
24
|
["a", "1"],
|
25
25
|
["a", "3"],
|
26
|
-
["a", "2"]
|
26
|
+
["a", "2"]
|
27
27
|
]
|
28
28
|
|
29
29
|
expect(Deduplicator.apply(input)).to eq input
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "spec_helper"
|
4
4
|
|
5
5
|
module Roadie
|
6
6
|
describe Document do
|
@@ -70,6 +70,9 @@ module Roadie
|
|
70
70
|
|
71
71
|
document.mode = :html
|
72
72
|
expect(document.mode).to eq(:html)
|
73
|
+
|
74
|
+
document.mode = :xml
|
75
|
+
expect(document.mode).to eq(:xml)
|
73
76
|
end
|
74
77
|
|
75
78
|
it "does not allow unknown modes" do
|
@@ -91,8 +94,8 @@ module Roadie
|
|
91
94
|
describe "transforming" do
|
92
95
|
it "runs the before and after callbacks" do
|
93
96
|
document = Document.new "<body></body>"
|
94
|
-
before = ->{}
|
95
|
-
after = ->{}
|
97
|
+
before = -> {}
|
98
|
+
after = -> {}
|
96
99
|
document.before_transformation = before
|
97
100
|
document.after_transformation = after
|
98
101
|
|
@@ -103,21 +106,6 @@ module Roadie
|
|
103
106
|
document.transform
|
104
107
|
end
|
105
108
|
|
106
|
-
# TODO: Remove on next major version.
|
107
|
-
it "works on callables that don't expect more than one argument" do
|
108
|
-
document = Document.new "<body></body>"
|
109
|
-
document.before_transformation = ->(first) { }
|
110
|
-
document.after_transformation = ->(first = nil) { }
|
111
|
-
|
112
|
-
expect { document.transform }.to_not raise_error
|
113
|
-
|
114
|
-
# It still supplies the second argument, if possible.
|
115
|
-
document.after_transformation = ->(first, second = nil) {
|
116
|
-
raise "Oops" unless second
|
117
|
-
}
|
118
|
-
expect { document.transform }.to_not raise_error
|
119
|
-
end
|
120
|
-
|
121
109
|
context "in HTML mode" do
|
122
110
|
it "does not escape curly braces" do
|
123
111
|
document = Document.new "<body><a href='https://google.com/{{hello}}'>Hello</a></body>"
|
@@ -126,26 +114,41 @@ module Roadie
|
|
126
114
|
expect(document.transform).to include("{{hello}}")
|
127
115
|
end
|
128
116
|
end
|
117
|
+
|
118
|
+
context "in XML mode" do
|
119
|
+
it "doesn't replace empty tags with self-closed ones" do
|
120
|
+
document = Document.new "<img src='https://google.com/image.png'></img>"
|
121
|
+
document.mode = :xml
|
122
|
+
|
123
|
+
expect(document.transform_partial).to end_with("</img>")
|
124
|
+
end
|
125
|
+
|
126
|
+
it "does not escape curly braces" do
|
127
|
+
document = Document.new "<a href='https://google.com/{{hello}}'>Hello</a>"
|
128
|
+
document.mode = :xml
|
129
|
+
expect(document.transform_partial).to include("{{hello}}")
|
130
|
+
end
|
131
|
+
end
|
129
132
|
end
|
130
133
|
|
131
134
|
describe "partial transforming" do
|
132
135
|
it "runs the before and after callbacks" do
|
133
136
|
document = Document.new "<p></p>"
|
134
|
-
before = ->{}
|
135
|
-
after = ->{}
|
137
|
+
before = -> {}
|
138
|
+
after = -> {}
|
136
139
|
document.before_transformation = before
|
137
140
|
document.after_transformation = after
|
138
141
|
|
139
142
|
expect(before).to receive(:call).with(
|
140
143
|
instance_of(Nokogiri::HTML::DocumentFragment),
|
141
|
-
document
|
144
|
+
document
|
142
145
|
).ordered
|
143
146
|
|
144
147
|
expect(Inliner).to receive(:new).ordered.and_return double.as_null_object
|
145
148
|
|
146
149
|
expect(after).to receive(:call).with(
|
147
150
|
instance_of(Nokogiri::HTML::DocumentFragment),
|
148
|
-
document
|
151
|
+
document
|
149
152
|
).ordered
|
150
153
|
|
151
154
|
document.transform_partial
|
@@ -159,6 +162,21 @@ module Roadie
|
|
159
162
|
expect(document.transform_partial).to include("{{hello}}")
|
160
163
|
end
|
161
164
|
end
|
165
|
+
|
166
|
+
context "in XML mode" do
|
167
|
+
it "doesn't replace empty tags with self-closed ones" do
|
168
|
+
document = Document.new "<img src='https://google.com/image.png'></img>"
|
169
|
+
document.mode = :xml
|
170
|
+
|
171
|
+
expect(document.transform_partial).to end_with("</img>")
|
172
|
+
end
|
173
|
+
|
174
|
+
it "does not escape curly braces" do
|
175
|
+
document = Document.new "<a href='https://google.com/{{hello}}'>Hello</a>"
|
176
|
+
document.mode = :xml
|
177
|
+
expect(document.transform_partial).to include("{{hello}}")
|
178
|
+
end
|
179
|
+
end
|
162
180
|
end
|
163
181
|
end
|
164
182
|
|
@@ -179,11 +197,11 @@ module Roadie
|
|
179
197
|
|
180
198
|
result = Nokogiri::HTML.parse document.transform
|
181
199
|
|
182
|
-
expect(result).to have_selector(
|
183
|
-
expect(result.at_css(
|
200
|
+
expect(result).to have_selector("html > head > title")
|
201
|
+
expect(result.at_css("title").text).to eq("Greetings")
|
184
202
|
|
185
|
-
expect(result).to have_selector(
|
186
|
-
paragraph = result.at_css(
|
203
|
+
expect(result).to have_selector("html > body > p")
|
204
|
+
paragraph = result.at_css("p")
|
187
205
|
expect(paragraph.text).to eq("Hello, world!")
|
188
206
|
expect(paragraph.to_xml).to eq('<p style="color:green">Hello, world!</p>')
|
189
207
|
end
|
@@ -202,7 +220,7 @@ module Roadie
|
|
202
220
|
HTML
|
203
221
|
|
204
222
|
document.asset_providers = TestProvider.new({
|
205
|
-
"/sample.css" => "p { color: red; text-align: right; }"
|
223
|
+
"/sample.css" => "p { color: red; text-align: right; }"
|
206
224
|
})
|
207
225
|
|
208
226
|
document.add_css "p { color: green; text-size: 2em; }"
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "spec_helper"
|
4
|
+
require "roadie/rspec"
|
5
|
+
require "shared_examples/asset_provider"
|
6
6
|
|
7
7
|
module Roadie
|
8
8
|
describe FilesystemProvider do
|
@@ -63,13 +63,11 @@ module Roadie
|
|
63
63
|
end
|
64
64
|
|
65
65
|
it "shows that the query string is ignored inside raised errors" do
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
expect(error.to_s).to include("/foo.css?query-string")
|
72
|
-
end
|
66
|
+
provider.find_stylesheet!("/foo.css?query-string")
|
67
|
+
fail "No error was raised"
|
68
|
+
rescue CssNotFound => error
|
69
|
+
expect(error.css_name).to eq("foo.css")
|
70
|
+
expect(error.to_s).to include("/foo.css?query-string")
|
73
71
|
end
|
74
72
|
end
|
75
73
|
end
|