ampize 0.1.3 → 0.1.4
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/lib/ampize.rb +24 -1
- data/lib/ampize/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d78fa02c77595aa578a6e136df7913ebdb603a7f
|
4
|
+
data.tar.gz: f6589ad34edb17076fa4676c9d2293113537711a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 226283dc64db161b903fa1bb972fc2e2ff19492ccbe7bb34b0aa6a7ae2124f928cf1b83480c1c2309f9c24eaf5a5e7b65aa70148421c016f960594ba56b7b471
|
7
|
+
data.tar.gz: 081308bc38555d0b0ff90c69221ddb5ec4f080e4bdbedd01e640067dfc644ad9879b62849762271eb41c8dc6415126ec9c2f1088d76806fca170ce2593bc24e4
|
data/lib/ampize.rb
CHANGED
@@ -12,7 +12,8 @@ module Ampize
|
|
12
12
|
end
|
13
13
|
@options = {
|
14
14
|
image_layout: 'responsive',
|
15
|
-
image_fetch_error_callback: default_error_callback
|
15
|
+
image_fetch_error_callback: default_error_callback,
|
16
|
+
iframe_layout: 'responsive'
|
16
17
|
}
|
17
18
|
@options.merge!(options)
|
18
19
|
end
|
@@ -26,6 +27,7 @@ module Ampize
|
|
26
27
|
process_anchor doc
|
27
28
|
process_style doc
|
28
29
|
process_img doc
|
30
|
+
process_iframe doc
|
29
31
|
process_event doc
|
30
32
|
doc.at('body').children.to_s
|
31
33
|
end
|
@@ -77,6 +79,27 @@ module Ampize
|
|
77
79
|
end
|
78
80
|
end
|
79
81
|
end
|
82
|
+
|
83
|
+
def process_iframe(doc)
|
84
|
+
doc.search('//iframe').each do |tag|
|
85
|
+
src = tag.attributes['src'].value
|
86
|
+
width = tag.attributes['width']
|
87
|
+
height = tag.attributes['height']
|
88
|
+
if !width || !height
|
89
|
+
width = 400
|
90
|
+
height = 300
|
91
|
+
else
|
92
|
+
width = width.value.to_s
|
93
|
+
height = height.value.to_s
|
94
|
+
end
|
95
|
+
if width && height
|
96
|
+
aiframe = %Q|<amp-iframe src="#{src}" width="#{width}" height="#{height}" layout="#{@options[:iframe_layout]}"></amp-layout>|
|
97
|
+
tag.replace(aiframe)
|
98
|
+
else
|
99
|
+
tag.replace(@options[:image_fetch_error_callback].call(src))
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
80
103
|
|
81
104
|
def process_event(doc)
|
82
105
|
%W|onload onerror onblur onchange onclick ondblclick onfocus
|
data/lib/ampize/version.rb
CHANGED