wovnrb 0.2.05 → 0.2.06

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f44db81ea6171f81032cd739b569bbb251ea71d
4
- data.tar.gz: 0904bb2bfb09ccc05f6ffdecbdaa0a3de9405b53
3
+ metadata.gz: 7fbcd58ed2ccfe8dfbf90599fada778b321a7a99
4
+ data.tar.gz: 60acb0add45cfac333c6a294fc555e091abf12ac
5
5
  SHA512:
6
- metadata.gz: 7781e8dc905ae4c07b7467d59d00c85c4085af2df65d6759355ab0dafdfa863b6c902f92871e02a5435464a4c5011dc70a8c6d214a88584a77d479197881b67e
7
- data.tar.gz: 2201ca3f501a761c41a7ac1c2afd4b572183b06051f5ef3e17cf7e3a69a7c3a17d13a5bfe06d818a508405a82f0221ad94080826f63feb2b413e7c8d66f1cbdb
6
+ metadata.gz: b7792a095bd24d248a4ea67b1b49f6d0e38d5c6e5ed04996cb88c289aefa93ebfcb2f5a5b745edc52ccdbda5f96744c73da11b5341f9ff96b190c11136b8720e
7
+ data.tar.gz: 5ab611f9513ccb1e4dcdef10e8a259f150dd66dcc7ae9b744b8575f3a648400bd1ba2eb5ad0873d6d7202fab2ec205405a756e0eaaffa966e8d0ceb038f8037a
@@ -71,7 +71,15 @@ module Wovnrb
71
71
  ignore_all = false
72
72
  new_body = []
73
73
  body.each do |b|
74
- d = Nokogiri::HTML5(b)
74
+ # temporarily remove noscripts
75
+ noscripts = []
76
+ b_without_noscripts = b
77
+ b.scan /<noscript.*?>.*?<\/noscript>/m do |match|
78
+ noscript_identifier = "<noscript wovn-id=\"#{noscripts.count}\"></noscript>"
79
+ noscripts << match
80
+ b_without_noscripts = b_without_noscripts.sub(match, noscript_identifier)
81
+ end
82
+ d = Nokogiri::HTML5(b_without_noscripts)
75
83
  d.encoding = "UTF-8"
76
84
 
77
85
  # If this page has wovn-ignore in the html tag, don't do anything
@@ -83,6 +91,11 @@ module Wovnrb
83
91
  end
84
92
 
85
93
  output = lang.switch_dom_lang(d, @store, values, url, headers)
94
+ # put back noscripts
95
+ noscripts.each_with_index do |noscript, index|
96
+ noscript_identifier = "<noscript wovn-id=\"#{index}\"></noscript>"
97
+ output.sub!(noscript_identifier, noscript)
98
+ end
86
99
  new_body.push(output)
87
100
  end
88
101
  body.close if body.respond_to?(:close)
@@ -1,3 +1,3 @@
1
1
  module Wovnrb
2
- VERSION = "0.2.05"
2
+ VERSION = "0.2.06"
3
3
  end
@@ -74,6 +74,136 @@ class WovnrbTest < Minitest::Test
74
74
  assert_equal([expected_body], swapped_body)
75
75
  end
76
76
 
77
+ def test_switch_lang_with_noscript_in_head
78
+ i = Wovnrb::Interceptor.new(get_app)
79
+ h = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://page.com'), Wovnrb.get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
80
+ body = "<html><head><noscript><div>test</div></noscript></head><body><h1>Mr. Belvedere Fan Club</h1>
81
+ <div><p>Hello</p></div>
82
+ </body></html>"
83
+ values = generate_values
84
+ url = h.url
85
+ swapped_body = i.switch_lang([body], values, url, 'ja', h)
86
+
87
+ expected_body = "<html lang=\"ja\">
88
+ <head>
89
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
90
+ <script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&amp;backend=true&amp;currentLang=ja&amp;defaultLang=en&amp;urlPattern=path&amp;version=#{Wovnrb::VERSION}\"> </script><noscript><div>test</div></noscript>
91
+ <link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\">
92
+ </head>
93
+ <body>
94
+ <h1>ベルベデアさんファンクラブ</h1>
95
+ <div><p>こんにちは</p></div>
96
+ </body>
97
+ </html>
98
+ "
99
+ assert_equal([expected_body], swapped_body)
100
+ end
101
+
102
+ def test_switch_lang_with_multiline_noscript_in_head
103
+ i = Wovnrb::Interceptor.new(get_app)
104
+ h = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://page.com'), Wovnrb.get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
105
+ body = "<html><head><noscript>
106
+ <div>test</div>
107
+ </noscript></head><body><h1>Mr. Belvedere Fan Club</h1>
108
+ <div><p>Hello</p></div>
109
+ </body></html>"
110
+ values = generate_values
111
+ url = h.url
112
+ swapped_body = i.switch_lang([body], values, url, 'ja', h)
113
+
114
+ expected_body = "<html lang=\"ja\">
115
+ <head>
116
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
117
+ <script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&amp;backend=true&amp;currentLang=ja&amp;defaultLang=en&amp;urlPattern=path&amp;version=#{Wovnrb::VERSION}\"> </script><noscript>
118
+ <div>test</div>
119
+ </noscript>
120
+ <link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\">
121
+ </head>
122
+ <body>
123
+ <h1>ベルベデアさんファンクラブ</h1>
124
+ <div><p>こんにちは</p></div>
125
+ </body>
126
+ </html>
127
+ "
128
+ assert_equal([expected_body], swapped_body)
129
+ end
130
+
131
+ def test_switch_lang_with_multiple_noscript_in_head
132
+ i = Wovnrb::Interceptor.new(get_app)
133
+ h = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://page.com'), Wovnrb.get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
134
+ body = "<html><head><noscript><div>test</div></noscript><title>plop</title><noscript><div>test2</div></noscript></head><body><h1>Mr. Belvedere Fan Club</h1>
135
+ <div><p>Hello</p></div>
136
+ </body></html>"
137
+ values = generate_values
138
+ url = h.url
139
+ swapped_body = i.switch_lang([body], values, url, 'ja', h)
140
+
141
+ expected_body = "<html lang=\"ja\">
142
+ <head>
143
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
144
+ <script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&amp;backend=true&amp;currentLang=ja&amp;defaultLang=en&amp;urlPattern=path&amp;version=#{Wovnrb::VERSION}\"> </script><noscript><div>test</div></noscript>
145
+ <title>plop</title>
146
+ <noscript><div>test2</div></noscript>
147
+ <link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\">
148
+ </head>
149
+ <body>
150
+ <h1>ベルベデアさんファンクラブ</h1>
151
+ <div><p>こんにちは</p></div>
152
+ </body>
153
+ </html>
154
+ "
155
+ assert_equal([expected_body], swapped_body)
156
+ end
157
+
158
+ def test_switch_lang_with_noscript_in_head_and_comment_inside
159
+ i = Wovnrb::Interceptor.new(get_app)
160
+ h = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://page.com'), Wovnrb.get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
161
+ body = "<html><head><noscript><!-- --><div>test</div></noscript></head><body><h1>Mr. Belvedere Fan Club</h1>
162
+ <div><p>Hello</p></div>
163
+ </body></html>"
164
+ values = generate_values
165
+ url = h.url
166
+ swapped_body = i.switch_lang([body], values, url, 'ja', h)
167
+
168
+ expected_body = "<html lang=\"ja\">
169
+ <head>
170
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
171
+ <script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&amp;backend=true&amp;currentLang=ja&amp;defaultLang=en&amp;urlPattern=path&amp;version=#{Wovnrb::VERSION}\"> </script><noscript><!-- --><div>test</div></noscript>
172
+ <link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\">
173
+ </head>
174
+ <body>
175
+ <h1>ベルベデアさんファンクラブ</h1>
176
+ <div><p>こんにちは</p></div>
177
+ </body>
178
+ </html>
179
+ "
180
+ assert_equal([expected_body], swapped_body)
181
+ end
182
+
183
+ def test_switch_lang_with_commented_noscript_in_head
184
+ i = Wovnrb::Interceptor.new(get_app)
185
+ h = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://page.com'), Wovnrb.get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
186
+ body = "<html><head><!--<noscript><div>test</div></noscript>--></head><body><h1>Mr. Belvedere Fan Club</h1>
187
+ <div><p>Hello</p></div>
188
+ </body></html>"
189
+ values = generate_values
190
+ url = h.url
191
+ swapped_body = i.switch_lang([body], values, url, 'ja', h)
192
+
193
+ expected_body = "<html lang=\"ja\">
194
+ <head>
195
+ <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
196
+ <script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&amp;backend=true&amp;currentLang=ja&amp;defaultLang=en&amp;urlPattern=path&amp;version=#{Wovnrb::VERSION}\"> </script><!--<noscript><div>test</div></noscript>--><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\">
197
+ </head>
198
+ <body>
199
+ <h1>ベルベデアさんファンクラブ</h1>
200
+ <div><p>こんにちは</p></div>
201
+ </body>
202
+ </html>
203
+ "
204
+ assert_equal([expected_body], swapped_body)
205
+ end
206
+
77
207
  def get_app
78
208
  RackMock.new
79
209
  end
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.05
4
+ version: 0.2.06
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: 2016-06-20 00:00:00.000000000 Z
12
+ date: 2016-06-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogumbo
@@ -350,7 +350,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
350
350
  version: '0'
351
351
  requirements: []
352
352
  rubyforge_project:
353
- rubygems_version: 2.2.0
353
+ rubygems_version: 2.6.3
354
354
  signing_key:
355
355
  specification_version: 4
356
356
  summary: Gem for WOVN.io
@@ -374,4 +374,3 @@ test_files:
374
374
  - test/lib/wovnrb_test.rb
375
375
  - test/services/url_test.rb
376
376
  - test/test_helper.rb
377
- has_rdoc: