ampize 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +21 -0
- data/lib/ampize.rb +18 -6
- data/lib/ampize/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8160470d6a391cfb3d2554f61a7112009dcc384
|
4
|
+
data.tar.gz: 7efb2f016d0462afa28b0c1e07e28d80af33bf88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 128ca0fb99a7604499f1c531d049b4b05d4aa2846019a4163ca3e3a0e5ebabf2810f176de3354797c6513b9160ed7d76ec585fc1a588ebe5f6c2ae53294e11f1
|
7
|
+
data.tar.gz: bd4fe19c0325002fe3ec57858de37c2c67a8f00287ee43b779842a29baf313e110f59981d32a2012edb3028229e0b7c22d4b2b1ebe3e9bcc5680fd15ff9f8529
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 devneko <dotneet@gmail.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/lib/ampize.rb
CHANGED
@@ -7,8 +7,12 @@ require 'nokogiri'
|
|
7
7
|
module Ampize
|
8
8
|
class Ampize
|
9
9
|
def initialize(options={})
|
10
|
+
default_error_callback = Proc.new do |src|
|
11
|
+
%Q|'#{src}' is not found.|
|
12
|
+
end
|
10
13
|
@options = {
|
11
|
-
image_layout: 'responsive'
|
14
|
+
image_layout: 'responsive',
|
15
|
+
image_fetch_error_callback: default_error_callback
|
12
16
|
}
|
13
17
|
@options.merge!(options)
|
14
18
|
end
|
@@ -32,16 +36,24 @@ module Ampize
|
|
32
36
|
width = tag.attributes['width']
|
33
37
|
height = tag.attributes['height']
|
34
38
|
if !width || !height
|
35
|
-
fi = FastImage.new(src, {raise_on_failure: true})
|
36
39
|
size = FastImage.size(src)
|
37
|
-
|
38
|
-
|
40
|
+
if size.nil?
|
41
|
+
width = nil
|
42
|
+
height = nil
|
43
|
+
else
|
44
|
+
width = size[0]
|
45
|
+
height = size[1]
|
46
|
+
end
|
39
47
|
else
|
40
48
|
width = width.value.to_s
|
41
49
|
height = height.value.to_s
|
42
50
|
end
|
43
|
-
|
44
|
-
|
51
|
+
if width && height
|
52
|
+
aimg = %Q|<amp-img src="#{src}" width="#{width}" height="#{height}" layout="#{@options[:image_layout]}"></amp-img>|
|
53
|
+
tag.replace(aimg)
|
54
|
+
else
|
55
|
+
tag.replace(@options[:image_fetch_error_callback].call(src))
|
56
|
+
end
|
45
57
|
end
|
46
58
|
%W|onload onerror onblur onchange onclick ondblclick onfocus
|
47
59
|
onkeydown onkeypress onkeyup onmousedown onmouseup onreset
|
data/lib/ampize/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ampize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- devneko
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- ".gitignore"
|
92
92
|
- ".rspec"
|
93
93
|
- Gemfile
|
94
|
+
- LICENSE
|
94
95
|
- README.md
|
95
96
|
- Rakefile
|
96
97
|
- ampize.gemspec
|