wovnrb 0.2.22 → 0.2.23

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: 09697d9b4f33f3d2fec08a6faaac998745f008a0
4
- data.tar.gz: a2ef8996d69b402ef6d538d1a45ae1e884485d9d
3
+ metadata.gz: ea8678343beb5b165e98756cdae5701487ab3e4f
4
+ data.tar.gz: bd2976576eb5e64c6cbc7f822ccab117f427765b
5
5
  SHA512:
6
- metadata.gz: a46121204bf40c4a24014e1869b1831b6da2206979ae27a26085ce821b60785b3e924a25313e8808261e66d45f9cc9186926e55b2102fc4e7b316a0518edeae4
7
- data.tar.gz: 9e7d1964c796d37bd807ae0290a3d08959f8392b3ce3ecf2e40a458b24ade56e77facd86ab058306f468873bcc0bd3bfe56bf1927b936936f89923549492fefe
6
+ metadata.gz: 372502decc7bb4e4e903f297b34b2d7161fa793f8c6bc075a3176d95d86a4642160f3afb63744ab8c7ebfe0d1380ba7b70d2bd56a799d1a06811e5d826f239a8
7
+ data.tar.gz: 283eacde612587dedc974226aa35c8320330ecd3a806d5d6718f0e005672c511bd1f3eaa4a7b12819c42a69aa8b69c9605556f377123108cc753107a6ecd10db
@@ -1,3 +1,3 @@
1
1
  module Wovnrb
2
- VERSION = "0.2.22"
2
+ VERSION = "0.2.23"
3
3
  end
data/lib/wovnrb.rb CHANGED
@@ -86,7 +86,7 @@ module Wovnrb
86
86
  d.encoding = "UTF-8"
87
87
 
88
88
  # If this page has wovn-ignore in the html tag, don't do anything
89
- if ignore_all || !d.xpath('//html[@wovn-ignore]').empty?
89
+ if ignore_all || !d.xpath('//html[@wovn-ignore]').empty? || is_amp_page?(d)
90
90
  ignore_all = true
91
91
  output = d.to_html.gsub(/href="([^"]*)"/) { |m| "href=\"#{URI.decode($1)}\"" }
92
92
  new_body.push(output)
@@ -104,7 +104,21 @@ module Wovnrb
104
104
  body.close if body.respond_to?(:close)
105
105
  new_body
106
106
  end
107
- end
108
107
 
108
+ private
109
+
110
+ # Checks if a given HTML body is an Accelerated Mobile Page (AMP).
111
+ # To do so, it looks at the required attributes for the HTML tag:
112
+ # https://www.ampproject.org/docs/tutorials/create/basic_markup.
113
+ #
114
+ # @param {Nokogiri::HTML5::Document} body The HTML body to check.
115
+ #
116
+ # @returns {Boolean} True is the HTML body is an AMP, false otherwise.
117
+ def is_amp_page?(body)
118
+ html_attributes = body.xpath('//html')[0].try(:attributes) || {}
119
+
120
+ html_attributes['amp'] || html_attributes["\u26A1"]
121
+ end
122
+ end
109
123
  end
110
124
 
@@ -75,6 +75,64 @@ class WovnrbTest < Minitest::Test
75
75
  assert_equal([expected_body], swapped_body)
76
76
  end
77
77
 
78
+ def test_switch_lang_ignores_amp
79
+ interceptor = Wovnrb::Interceptor.new(get_app)
80
+ headers = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://page.com'), Wovnrb.get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
81
+ body = <<HTML
82
+ <html amp>
83
+ <body>
84
+ <h1>Mr. Belvedere Fan Club</h1>
85
+ <div><p>Hello</p></div>
86
+ </body>
87
+ </html>
88
+ HTML
89
+ expected_body = <<HTML
90
+ <html amp="">
91
+ <head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head>
92
+ <body>
93
+ <h1>Mr. Belvedere Fan Club</h1>
94
+ <div><p>Hello</p></div>
95
+
96
+
97
+ </body>
98
+ </html>
99
+ HTML
100
+ values = generate_values
101
+ url = headers.url
102
+ swapped_bodies = interceptor.switch_lang([body], values, url, 'ja', headers)
103
+
104
+ assert_equal([expected_body], swapped_bodies)
105
+ end
106
+
107
+ def test_switch_lang_ignores_amp_defined_with_symbol_attribute
108
+ interceptor = Wovnrb::Interceptor.new(get_app)
109
+ headers = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://page.com'), Wovnrb.get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
110
+ body = <<HTML
111
+ <html ⚡>
112
+ <body>
113
+ <h1>Mr. Belvedere Fan Club</h1>
114
+ <div><p>Hello</p></div>
115
+ </body>
116
+ </html>
117
+ HTML
118
+ expected_body = <<HTML
119
+ <html ⚡="">
120
+ <head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head>
121
+ <body>
122
+ <h1>Mr. Belvedere Fan Club</h1>
123
+ <div><p>Hello</p></div>
124
+
125
+
126
+ </body>
127
+ </html>
128
+ HTML
129
+ values = generate_values
130
+ url = headers.url
131
+ swapped_bodies = interceptor.switch_lang([body], values, url, 'ja', headers)
132
+
133
+ assert_equal([expected_body], swapped_bodies)
134
+ end
135
+
78
136
  def test_switch_lang_with_noscript_in_head
79
137
  i = Wovnrb::Interceptor.new(get_app)
80
138
  h = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://page.com'), Wovnrb.get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wovnrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.22
4
+ version: 0.2.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Sandford
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-06-30 00:00:00.000000000 Z
12
+ date: 2017-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogumbo