preadly-bulbasaur 0.8.0 → 0.8.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31c936bb121a4f61275241d5c059222c02f3e7b6
|
4
|
+
data.tar.gz: eeeb22a1d7d7177372fe8e40d7f2ad58feab00d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f83867d13892773d3e73758b99f3d1c2289f41ad8a7fdfc073d902b4f21f83612b71cb320da2eac96937fbf733af3a7e520b0134e3a2c98657ad1501f776c241
|
7
|
+
data.tar.gz: 813a56226a7f1ae0db8fd34d3fdafd8666a0aec5c6abea393ec7f73afdbab54805c2b353aeaa010899ba02f4fe7d905ae76e63a22f2ddc2c800575c2aabcdb0d
|
@@ -28,13 +28,17 @@ module Bulbasaur
|
|
28
28
|
|
29
29
|
def adjust(element, attr)
|
30
30
|
element.set_attribute 'src', lazy_load_url(element, element.xpath(attr).text)
|
31
|
-
element
|
31
|
+
remove_target_attrs_from element
|
32
32
|
end
|
33
33
|
|
34
34
|
def lazy_load_url(element, text)
|
35
35
|
text_match = text.match(DOMAIN_REGEX).to_s
|
36
36
|
element_match = element.css('@src').text.match(DOMAIN_REGEX).to_s
|
37
|
-
|
37
|
+
element_match.empty? || text_match == element_match ? text : "#{element_match}/#{text}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def remove_target_attrs_from(element)
|
41
|
+
@target_attrs.each { |attr| element.xpath("@#{attr}").remove }
|
38
42
|
end
|
39
43
|
end
|
40
44
|
end
|
data/lib/bulbasaur/version.rb
CHANGED
@@ -14,7 +14,10 @@ RSpec.describe Bulbasaur::NormalizeImageSources do
|
|
14
14
|
<img src="http://somewhere.to/get/another-pixel.gif" data-image="http://somewhere.to/get/the-other-real-image.jpg">
|
15
15
|
<img src="http://somewhere.to/get/a-third-pixel.gif" data-src="get/the-third-real-image.jpg">
|
16
16
|
<img src="otherplace.to/load/a-fourth-pixel.gif" lazy-data="otherplace.to/load/the-fourth-real-image.jpg">
|
17
|
-
|
17
|
+
<img src="https://place.where/an-image/is/without-extension/" data-src="https://place.where/an-image/is/without-extension/">
|
18
|
+
<img src="https://place.where/an-image/has-two/lazy-params/" data-src="https://place.where/an-image/has-two/lazy-params/" data-image="https://place.where/an-image/has-two/lazy-params/">
|
19
|
+
<img lazy-data="https://place.where/an-image/has/no-src-tag.jpg">
|
20
|
+
)
|
18
21
|
end
|
19
22
|
|
20
23
|
context "When there are no target attributes" do
|
@@ -40,7 +43,10 @@ RSpec.describe Bulbasaur::NormalizeImageSources do
|
|
40
43
|
<img src="http://somewhere.to/get/the-other-real-image.jpg">
|
41
44
|
<img src="http://somewhere.to/get/a-third-pixel.gif" data-src="get/the-third-real-image.jpg">
|
42
45
|
<img src="otherplace.to/load/a-fourth-pixel.gif" lazy-data="otherplace.to/load/the-fourth-real-image.jpg">
|
43
|
-
|
46
|
+
<img src="https://place.where/an-image/is/without-extension/" data-src="https://place.where/an-image/is/without-extension/">
|
47
|
+
<img src="https://place.where/an-image/has-two/lazy-params/" data-src="https://place.where/an-image/has-two/lazy-params/">
|
48
|
+
<img lazy-data="https://place.where/an-image/has/no-src-tag.jpg">
|
49
|
+
)
|
44
50
|
end
|
45
51
|
|
46
52
|
it "Returns the HTML code with the specified image tags adjusted" do
|
@@ -60,6 +66,9 @@ RSpec.describe Bulbasaur::NormalizeImageSources do
|
|
60
66
|
<img src="http://somewhere.to/get/the-other-real-image.jpg">
|
61
67
|
<img src="http://somewhere.to/get/the-third-real-image.jpg">
|
62
68
|
<img src="otherplace.to/load/the-fourth-real-image.jpg">
|
69
|
+
<img src="https://place.where/an-image/is/without-extension/">
|
70
|
+
<img src="https://place.where/an-image/has-two/lazy-params/">
|
71
|
+
<img src="https://place.where/an-image/has/no-src-tag.jpg">
|
63
72
|
)
|
64
73
|
end
|
65
74
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: preadly-bulbasaur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Magno Costa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|