ampize 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d8160470d6a391cfb3d2554f61a7112009dcc384
4
- data.tar.gz: 7efb2f016d0462afa28b0c1e07e28d80af33bf88
3
+ metadata.gz: 39dc5d847b6f466e3839497b44b8a6d0a6912f58
4
+ data.tar.gz: b3ad78083a1090b6337793b2573baabc5f533605
5
5
  SHA512:
6
- metadata.gz: 128ca0fb99a7604499f1c531d049b4b05d4aa2846019a4163ca3e3a0e5ebabf2810f176de3354797c6513b9160ed7d76ec585fc1a588ebe5f6c2ae53294e11f1
7
- data.tar.gz: bd4fe19c0325002fe3ec57858de37c2c67a8f00287ee43b779842a29baf313e110f59981d32a2012edb3028229e0b7c22d4b2b1ebe3e9bcc5680fd15ff9f8529
6
+ metadata.gz: cd224ade044102450374940a186d22fb3463beb99015521bc884219ce436a82cdb39990aeb5bc2095d721f64fd479eb00d0623f8a83637d56239e86e8546c741
7
+ data.tar.gz: 2e01cde238ff8887591ffb2c7e7a7c4a03eec3a70a896d55825f4c0f7e759a0e87754a3a167007ff255dae6295c50152728197ed47cc0449a0149fa0c2fd9463
data/README.md CHANGED
@@ -27,6 +27,12 @@ puts result
27
27
  >> <amp-img src="./spec/data/rect.jpg" width="100" height="100" layout="responsive"></amp-img>
28
28
  ```
29
29
 
30
+ If img element doesn't have width/height attributes then Ampize download an image to get a dimension.
31
+ Ofcourse if img element have a size Ampize keep it.
32
+
33
+ Currently Ampize doesn't support amp-audio, amp-video, amp-iframe.
34
+ Contribution is always welcome.
35
+
30
36
  ## Contributing
31
37
 
32
38
  Bug reports and pull requests are welcome on GitHub at https://github.com/dotneet/ampize.
@@ -18,19 +18,40 @@ module Ampize
18
18
  end
19
19
 
20
20
  def transform(html)
21
+ if html.nil? || html.size == 0
22
+ return ''
23
+ end
21
24
  doc = Nokogiri::HTML.parse(html)
25
+ process_prohibited_tags doc
26
+ process_anchor doc
27
+ process_style doc
28
+ process_img doc
29
+ process_event doc
30
+ doc.at('body').children.to_s
31
+ end
32
+
33
+ def process_prohibited_tags(doc)
22
34
  prohibit_tags = %W|script frame frameset object param applet embed|
23
35
  prohibit_tags.each do |ptag|
24
36
  doc.search("//#{ptag}").remove
25
37
  end
38
+ end
39
+
40
+ def process_anchor(doc)
26
41
  doc.search('//a[@href]').each do |tag|
27
42
  if tag['href'] =~ /javascript/i
28
43
  tag.attributes['href'].remove
29
44
  end
30
45
  end
46
+ end
47
+
48
+ def process_style(doc)
31
49
  doc.search('//*[@style]').each do |tag|
32
50
  tag.attributes['style'].remove
33
51
  end
52
+ end
53
+
54
+ def process_img(doc)
34
55
  doc.search('//img').each do |tag|
35
56
  src = tag.attributes['src'].value
36
57
  width = tag.attributes['width']
@@ -55,13 +76,16 @@ module Ampize
55
76
  tag.replace(@options[:image_fetch_error_callback].call(src))
56
77
  end
57
78
  end
79
+ end
80
+
81
+ def process_event(doc)
58
82
  %W|onload onerror onblur onchange onclick ondblclick onfocus
59
83
  onkeydown onkeypress onkeyup onmousedown onmouseup onreset
60
84
  onselect onsubmit onunload|.each do |attr|
61
85
  doc.xpath('//@' + attr).remove
62
86
  end
63
- doc.at('body').children.to_s
64
87
  end
88
+
65
89
  end
66
90
  end
67
91
 
@@ -1,3 +1,3 @@
1
1
  module Ampize
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ampize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - devneko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-21 00:00:00.000000000 Z
11
+ date: 2017-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fastimage