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 +4 -4
- data/lib/wovnrb/version.rb +1 -1
- data/lib/wovnrb.rb +16 -2
- data/test/lib/wovnrb_test.rb +58 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea8678343beb5b165e98756cdae5701487ab3e4f
|
4
|
+
data.tar.gz: bd2976576eb5e64c6cbc7f822ccab117f427765b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 372502decc7bb4e4e903f297b34b2d7161fa793f8c6bc075a3176d95d86a4642160f3afb63744ab8c7ebfe0d1380ba7b70d2bd56a799d1a06811e5d826f239a8
|
7
|
+
data.tar.gz: 283eacde612587dedc974226aa35c8320330ecd3a806d5d6718f0e005672c511bd1f3eaa4a7b12819c42a69aa8b69c9605556f377123108cc753107a6ecd10db
|
data/lib/wovnrb/version.rb
CHANGED
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
|
|
data/test/lib/wovnrb_test.rb
CHANGED
@@ -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.
|
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-
|
12
|
+
date: 2017-08-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogumbo
|