ampize 0.1.1 → 0.1.2

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -0
  3. data/lib/ampize.rb +18 -6
  4. data/lib/ampize/version.rb +1 -1
  5. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76e486cec50918ebc27c812b4db9cc68140728ef
4
- data.tar.gz: 625c6f3850d7d7990125253b980fe3603215a5ed
3
+ metadata.gz: d8160470d6a391cfb3d2554f61a7112009dcc384
4
+ data.tar.gz: 7efb2f016d0462afa28b0c1e07e28d80af33bf88
5
5
  SHA512:
6
- metadata.gz: 02454369dddffe1065f058b9655d44f8c3ac702c88231af49340aed06fefa279b656c710d35efdecef5740a2e2c65368e49977c1c7b2b8f031200d45accdc642
7
- data.tar.gz: 1758aba6c83f5e454ff9b2c770d625b2c3d2081c350d68cbe6229472efc88b329a9350b2e0e7cc005498c81b86a559258ed32919b4c8e999c5794a86fb85f221
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.
@@ -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
- width = size[0]
38
- height = size[1]
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
- aimg = %Q|<amp-img src="#{src}" width="#{width}" height="#{height}" layout="#{@options[:image_layout]}"></amp-img>|
44
- tag.replace(aimg)
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
@@ -1,3 +1,3 @@
1
1
  module Ampize
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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