wovnrb 3.0.1 → 3.3.1
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/.circleci/config.yml +21 -10
- data/.rubocop_todo.yml +9 -44
- data/Gemfile +0 -5
- data/README.en.md +21 -16
- data/README.ja.md +6 -6
- data/docker/docker-compose.yml +5 -0
- data/docker/rails/TestSite/Gemfile +1 -1
- data/docker/rails/TestSite/app/controllers/custom_response_controller.rb +16 -0
- data/docker/rails/TestSite/config/routes.rb +1 -0
- data/docker/rails/TestSite/start.sh +1 -0
- data/docker/rails/TestSite/yarn.lock +12 -12
- data/lib/wovnrb/api_translator.rb +39 -17
- data/lib/wovnrb/headers.rb +30 -39
- data/lib/wovnrb/helpers/nokogumbo_helper.rb +7 -9
- data/lib/wovnrb/lang.rb +15 -14
- data/lib/wovnrb/railtie.rb +3 -1
- data/lib/wovnrb/services/html_converter.rb +8 -8
- data/lib/wovnrb/services/wovn_logger.rb +9 -2
- data/lib/wovnrb/store.rb +16 -17
- data/lib/wovnrb/version.rb +1 -1
- data/lib/wovnrb.rb +2 -4
- data/test/lib/api_translator_test.rb +48 -9
- data/test/lib/headers_test.rb +2 -2
- data/test/lib/lang_test.rb +5 -136
- data/test/lib/services/html_converter_test.rb +14 -14
- data/test/lib/services/wovn_logger_test.rb +5 -3
- data/test/lib/store_test.rb +22 -16
- data/test/lib/wovnrb_test.rb +16 -16
- data/wovnrb.gemspec +2 -1
- metadata +10 -10
- data/.travis.yml +0 -14
- data/lib/wovnrb/text_caches/cache_base.rb +0 -53
- data/lib/wovnrb/text_caches/memory_cache.rb +0 -51
- data/test/lib/text_caches/cache_base_test.rb +0 -31
- data/test/lib/text_caches/memory_cache_test.rb +0 -91
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5c458ea4be1b5bc1325a0c54a9672f7fd744b864975699ae48e70acde6d5265
|
4
|
+
data.tar.gz: 318102aa29ae9bbb03d5cf0b1ccffa3f39ada7a8fc963daad856b058f46e46ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd81bc766461ce8212a32afafc0a673790985213304c55765322e42591e34107a649d70e1133a597b88c6cda3ee0813cd1b4efbac1ff45d2d794f52d78c80814
|
7
|
+
data.tar.gz: fd4304143e2226ab1b9a887d45e2326da8b8b452e0a60bcbb94f3b680fc4280459e47fb3b025d6660c2d338a1d3150617fc279b279e68693b0566a41050bd3de
|
data/.circleci/config.yml
CHANGED
@@ -1,18 +1,29 @@
|
|
1
|
-
version: 2
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
orbs:
|
4
|
+
# https://github.com/CircleCI-Public/ruby-orb
|
5
|
+
ruby: circleci/ruby@1.1
|
2
6
|
|
3
7
|
jobs:
|
4
|
-
|
8
|
+
test:
|
9
|
+
parameters:
|
10
|
+
ruby-version:
|
11
|
+
type: string
|
5
12
|
docker:
|
6
|
-
- image:
|
13
|
+
- image: cimg/ruby:<< parameters.ruby-version >>
|
7
14
|
steps:
|
8
15
|
- checkout
|
9
|
-
- restore_cache:
|
10
|
-
keys:
|
11
|
-
- bundler-
|
12
16
|
- run: bundle install --path vendor/bundle --jobs=4
|
13
|
-
- save_cache:
|
14
|
-
key: bundler-{{ checksum "Gemfile.lock" }}
|
15
|
-
paths:
|
16
|
-
- vendor/bundle
|
17
17
|
- run: bundle exec rubocop
|
18
18
|
- run: bundle exec rake test
|
19
|
+
|
20
|
+
# https://circleci.com/blog/circleci-matrix-jobs/
|
21
|
+
workflows:
|
22
|
+
build_and_test:
|
23
|
+
jobs:
|
24
|
+
- test:
|
25
|
+
matrix:
|
26
|
+
parameters:
|
27
|
+
# https://github.com/CircleCI-Public/cimg-ruby
|
28
|
+
# only supports the last three ruby versions
|
29
|
+
ruby-version: ["2.5", "2.6", "2.7"]
|
data/.rubocop_todo.yml
CHANGED
@@ -6,17 +6,8 @@
|
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
Layout/EmptyLinesAroundAccessModifier:
|
12
|
-
Exclude:
|
13
|
-
- 'lib/wovnrb/text_caches/memory_cache.rb'
|
14
|
-
|
15
|
-
# Offense count: 1
|
16
|
-
# Cop supports --auto-correct.
|
17
|
-
Layout/EmptyLinesAroundMethodBody:
|
18
|
-
Exclude:
|
19
|
-
- 'test/lib/text_caches/memory_cache_test.rb'
|
9
|
+
Gemspec/RequiredRubyVersion:
|
10
|
+
Enabled: false
|
20
11
|
|
21
12
|
# Offense count: 11
|
22
13
|
# Cop supports --auto-correct.
|
@@ -25,13 +16,9 @@ Layout/ExtraSpacing:
|
|
25
16
|
Exclude:
|
26
17
|
- 'lib/wovnrb/lang.rb'
|
27
18
|
|
28
|
-
|
29
|
-
# Cop supports --auto-correct.
|
30
|
-
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
31
|
-
# SupportedStyles: special_inside_parentheses, consistent, align_braces
|
32
|
-
Layout/FirstHashElementIndentation:
|
19
|
+
Style/HashEachMethods:
|
33
20
|
Exclude:
|
34
|
-
- 'lib/wovnrb/
|
21
|
+
- 'lib/wovnrb/store.rb'
|
35
22
|
|
36
23
|
# Offense count: 4
|
37
24
|
# Cop supports --auto-correct.
|
@@ -42,13 +29,6 @@ Layout/HeredocIndentation:
|
|
42
29
|
- 'test/lib/lang_test.rb'
|
43
30
|
- 'test/lib/wovnrb_test.rb'
|
44
31
|
|
45
|
-
# Offense count: 1
|
46
|
-
# Cop supports --auto-correct.
|
47
|
-
# Configuration parameters: AllowForAlignment.
|
48
|
-
Layout/SpaceAroundOperators:
|
49
|
-
Exclude:
|
50
|
-
- 'lib/wovnrb/text_caches/memory_cache.rb'
|
51
|
-
|
52
32
|
# Offense count: 3
|
53
33
|
# Configuration parameters: AllowSafeAssignment.
|
54
34
|
Lint/AssignmentInCondition:
|
@@ -70,13 +50,6 @@ Lint/ImplicitStringConcatenation:
|
|
70
50
|
Exclude:
|
71
51
|
- 'test/lib/lang_test.rb'
|
72
52
|
|
73
|
-
# Offense count: 3
|
74
|
-
# Cop supports --auto-correct.
|
75
|
-
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
|
76
|
-
Lint/UnusedMethodArgument:
|
77
|
-
Exclude:
|
78
|
-
- 'lib/wovnrb/text_caches/cache_base.rb'
|
79
|
-
|
80
53
|
# Offense count: 5
|
81
54
|
Lint/UselessAssignment:
|
82
55
|
Exclude:
|
@@ -116,12 +89,13 @@ Metrics/MethodLength:
|
|
116
89
|
# Offense count: 12
|
117
90
|
Metrics/PerceivedComplexity:
|
118
91
|
Max: 22
|
92
|
+
Exclude:
|
93
|
+
- 'lib/wovnrb/headers.rb'
|
119
94
|
|
120
95
|
# Offense count: 3
|
121
96
|
Naming/AccessorMethodName:
|
122
97
|
Exclude:
|
123
98
|
- 'lib/wovnrb/services/wovn_logger.rb'
|
124
|
-
- 'lib/wovnrb/text_caches/cache_base.rb'
|
125
99
|
|
126
100
|
# Offense count: 120
|
127
101
|
# Configuration parameters: .
|
@@ -153,12 +127,6 @@ Style/ClassCheck:
|
|
153
127
|
Exclude:
|
154
128
|
- 'lib/wovnrb/store.rb'
|
155
129
|
|
156
|
-
# Offense count: 6
|
157
|
-
Style/ClassVars:
|
158
|
-
Exclude:
|
159
|
-
- 'lib/wovnrb/text_caches/cache_base.rb'
|
160
|
-
- 'lib/wovnrb/text_caches/memory_cache.rb'
|
161
|
-
|
162
130
|
# Offense count: 1
|
163
131
|
# Cop supports --auto-correct.
|
164
132
|
# Configuration parameters: Keywords.
|
@@ -183,8 +151,6 @@ Style/Documentation:
|
|
183
151
|
- 'lib/wovnrb/services/wovn_logger.rb'
|
184
152
|
- 'lib/wovnrb/settings.rb'
|
185
153
|
- 'lib/wovnrb/store.rb'
|
186
|
-
- 'lib/wovnrb/text_caches/cache_base.rb'
|
187
|
-
- 'lib/wovnrb/text_caches/memory_cache.rb'
|
188
154
|
|
189
155
|
# Offense count: 2
|
190
156
|
Style/DoubleNegation:
|
@@ -224,7 +190,6 @@ Style/IfUnlessModifier:
|
|
224
190
|
- 'Rakefile'
|
225
191
|
- 'lib/wovnrb/helpers/nokogumbo_helper.rb'
|
226
192
|
- 'lib/wovnrb/store.rb'
|
227
|
-
- 'lib/wovnrb/text_caches/memory_cache.rb'
|
228
193
|
|
229
194
|
# Offense count: 1
|
230
195
|
# Cop supports --auto-correct.
|
@@ -241,7 +206,6 @@ Style/NegatedIf:
|
|
241
206
|
Style/PreferredHashMethods:
|
242
207
|
Exclude:
|
243
208
|
- 'lib/wovnrb/store.rb'
|
244
|
-
- 'lib/wovnrb/text_caches/memory_cache.rb'
|
245
209
|
|
246
210
|
# Offense count: 2
|
247
211
|
# Cop supports --auto-correct.
|
@@ -297,7 +261,7 @@ Style/ZeroLengthPredicate:
|
|
297
261
|
# Offense count: 1436
|
298
262
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
299
263
|
# URISchemes: http, https
|
300
|
-
|
264
|
+
Layout/LineLength:
|
301
265
|
Max: 1424
|
302
266
|
|
303
267
|
Style/FrozenStringLiteralComment:
|
@@ -310,6 +274,7 @@ Style/SafeNavigation:
|
|
310
274
|
Enabled: false
|
311
275
|
|
312
276
|
AllCops:
|
277
|
+
NewCops: enable
|
313
278
|
Exclude:
|
314
279
|
- 'docker/**/*'
|
315
|
-
- 'vendor/**/*'
|
280
|
+
- 'vendor/**/*'
|
data/Gemfile
CHANGED
data/README.en.md
CHANGED
@@ -39,8 +39,8 @@ Insert the following into either config/application.rb or config/environments/.
|
|
39
39
|
|
40
40
|
config.wovnrb = {
|
41
41
|
:project_token => 'EnS!t3',
|
42
|
-
:default_lang => '
|
43
|
-
:supported_langs => ['en'],
|
42
|
+
:default_lang => 'ja',
|
43
|
+
:supported_langs => ['ja', en'],
|
44
44
|
:url_pattern => 'path'
|
45
45
|
}
|
46
46
|
|
@@ -60,8 +60,8 @@ require 'wovnrb'
|
|
60
60
|
|
61
61
|
use Wovnrb::Interceptor, {
|
62
62
|
:project_token => 'EnS!t3',
|
63
|
-
:default_lang => '
|
64
|
-
:supported_langs => ['en'],
|
63
|
+
:default_lang => 'ja',
|
64
|
+
:supported_langs => ['ja', 'en'],
|
65
65
|
:url_pattern => 'path'
|
66
66
|
}
|
67
67
|
|
@@ -74,18 +74,19 @@ After completing setup, start the Ruby Application, and make sure the WOVN.io li
|
|
74
74
|
|
75
75
|
The following is a list of the WOVN.io Ruby Library's valid parameters.
|
76
76
|
|
77
|
-
Parameter Name
|
78
|
-
|
79
|
-
project_token
|
80
|
-
default_lang
|
81
|
-
supported_langs
|
82
|
-
url_pattern
|
83
|
-
lang_param_name
|
84
|
-
query
|
85
|
-
ignore_class
|
86
|
-
translate_fragment
|
87
|
-
ignore_paths
|
88
|
-
install_middleware
|
77
|
+
Parameter Name | Required | Default Setting
|
78
|
+
----------------------| -------- | ----------------
|
79
|
+
project_token | yes | ''
|
80
|
+
default_lang | yes | 'ja'
|
81
|
+
supported_langs | yes | ['ja', 'en']
|
82
|
+
url_pattern | yes | 'path'
|
83
|
+
lang_param_name | | 'wovn'
|
84
|
+
query | | []
|
85
|
+
ignore_class | | []
|
86
|
+
translate_fragment | | true
|
87
|
+
ignore_paths | | []
|
88
|
+
install_middleware | | true
|
89
|
+
compress_api_requests | | true
|
89
90
|
|
90
91
|
### 2.1. project_token
|
91
92
|
|
@@ -196,3 +197,7 @@ WOVN.rb needs to be added after any compression middleware.
|
|
196
197
|
:install_middleware => false
|
197
198
|
}
|
198
199
|
```
|
200
|
+
|
201
|
+
### 2.11 compress_api_requests
|
202
|
+
|
203
|
+
By default, requests to the translation API will be sent with gzip compression. Set to false to disable compression.
|
data/README.ja.md
CHANGED
@@ -44,8 +44,8 @@ bundle install
|
|
44
44
|
|
45
45
|
config.wovnrb = {
|
46
46
|
:project_token => 'EnS!t3',
|
47
|
-
:default_lang => '
|
48
|
-
:supported_langs => ['en'],
|
47
|
+
:default_lang => 'ja',
|
48
|
+
:supported_langs => ['ja', en'],
|
49
49
|
:url_pattern => 'path'
|
50
50
|
}
|
51
51
|
|
@@ -63,8 +63,8 @@ require 'wovnrb'
|
|
63
63
|
|
64
64
|
use Wovnrb::Interceptor, {
|
65
65
|
:project_token => 'EnS!t3',
|
66
|
-
:default_lang => '
|
67
|
-
:supported_langs => ['en'],
|
66
|
+
:default_lang => 'ja',
|
67
|
+
:supported_langs => ['ja', 'en'],
|
68
68
|
:url_pattern => 'path'
|
69
69
|
}
|
70
70
|
|
@@ -80,8 +80,8 @@ use Wovnrb::Interceptor, {
|
|
80
80
|
パラメータ名 | 必須 | デフォルト設定
|
81
81
|
------------------ | -------- | ----------------
|
82
82
|
project_token | yes | ''
|
83
|
-
default_lang | yes | '
|
84
|
-
supported_langs | yes | ['en']
|
83
|
+
default_lang | yes | 'ja'
|
84
|
+
supported_langs | yes | ['ja', 'en']
|
85
85
|
url_pattern | yes | 'path'
|
86
86
|
lang_param_name | | 'wovn'
|
87
87
|
query | | []
|
data/docker/docker-compose.yml
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
class CustomResponseController < ApplicationController
|
2
|
+
skip_before_action :verify_authenticity_token2
|
3
|
+
|
4
|
+
def make_response
|
5
|
+
response_args_json = params[:response]
|
6
|
+
raise ActionController::BadRequest unless response_args_json
|
7
|
+
|
8
|
+
(response_args_json[:headers] || {}).each do |name, value|
|
9
|
+
response.headers[name] = value
|
10
|
+
end
|
11
|
+
|
12
|
+
render inline: response_args_json[:body],
|
13
|
+
status: response_args_json[:status],
|
14
|
+
content_type: response_args_json[:content_type]
|
15
|
+
end
|
16
|
+
end
|
@@ -2592,9 +2592,9 @@ dns-equal@^1.0.0:
|
|
2592
2592
|
integrity sha1-s55/HabrCnW6nBcySzR1PEfgZU0=
|
2593
2593
|
|
2594
2594
|
dns-packet@^1.3.1:
|
2595
|
-
version "1.3.
|
2596
|
-
resolved "https://registry.yarnpkg.com/dns-packet/-/dns-packet-1.3.
|
2597
|
-
integrity sha512-
|
2595
|
+
version "1.3.4"
|
2596
|
+
resolved "https://registry.yarnpkg.com/dns-packet/-/dns-packet-1.3.4.tgz#e3455065824a2507ba886c55a89963bb107dec6f"
|
2597
|
+
integrity sha512-BQ6F4vycLXBvdrJZ6S3gZewt6rcrks9KBgM9vrhW+knGRqc8uEdT7fuCwloc7nny5xNoMJ17HGH0R/6fpo8ECA==
|
2598
2598
|
dependencies:
|
2599
2599
|
ip "^1.1.0"
|
2600
2600
|
safe-buffer "^5.0.1"
|
@@ -5863,9 +5863,9 @@ postcss-values-parser@^2.0.0, postcss-values-parser@^2.0.1:
|
|
5863
5863
|
uniq "^1.0.1"
|
5864
5864
|
|
5865
5865
|
postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.14, postcss@^7.0.17, postcss@^7.0.2, postcss@^7.0.26, postcss@^7.0.27, postcss@^7.0.32, postcss@^7.0.5, postcss@^7.0.6:
|
5866
|
-
version "7.0.
|
5867
|
-
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.
|
5868
|
-
integrity sha512-
|
5866
|
+
version "7.0.36"
|
5867
|
+
resolved "https://registry.yarnpkg.com/postcss/-/postcss-7.0.36.tgz#056f8cffa939662a8f5905950c07d5285644dfcb"
|
5868
|
+
integrity sha512-BebJSIUMwJHRH0HAQoxN4u1CN86glsrwsW0q7T+/m44eXOUAxSNdHRkNZPYz5vVUbg17hFgOQDE7fZk7li3pZw==
|
5869
5869
|
dependencies:
|
5870
5870
|
chalk "^2.4.2"
|
5871
5871
|
source-map "^0.6.1"
|
@@ -7269,9 +7269,9 @@ urix@^0.1.0:
|
|
7269
7269
|
integrity sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI=
|
7270
7270
|
|
7271
7271
|
url-parse@^1.4.3, url-parse@^1.5.1:
|
7272
|
-
version "1.5.
|
7273
|
-
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.
|
7274
|
-
integrity sha512-
|
7272
|
+
version "1.5.3"
|
7273
|
+
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.3.tgz#71c1303d38fb6639ade183c2992c8cc0686df862"
|
7274
|
+
integrity sha512-IIORyIQD9rvj0A4CLWsHkBBJuNqWpFQe224b6j9t/ABmquIS0qDU2pY6kl6AuOrL5OkCXHMCFNe1jBcuAggjvQ==
|
7275
7275
|
dependencies:
|
7276
7276
|
querystringify "^2.1.1"
|
7277
7277
|
requires-port "^1.0.0"
|
@@ -7581,9 +7581,9 @@ wrappy@1:
|
|
7581
7581
|
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=
|
7582
7582
|
|
7583
7583
|
ws@^6.2.1:
|
7584
|
-
version "6.2.
|
7585
|
-
resolved "https://registry.yarnpkg.com/ws/-/ws-6.2.
|
7586
|
-
integrity sha512-
|
7584
|
+
version "6.2.2"
|
7585
|
+
resolved "https://registry.yarnpkg.com/ws/-/ws-6.2.2.tgz#dd5cdbd57a9979916097652d78f1cc5faea0c32e"
|
7586
|
+
integrity sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==
|
7587
7587
|
dependencies:
|
7588
7588
|
async-limiter "~1.0.0"
|
7589
7589
|
|
@@ -5,9 +5,10 @@ require 'zlib'
|
|
5
5
|
|
6
6
|
module Wovnrb
|
7
7
|
class ApiTranslator
|
8
|
-
def initialize(store, headers)
|
8
|
+
def initialize(store, headers, uuid)
|
9
9
|
@store = store
|
10
10
|
@headers = headers
|
11
|
+
@uuid = uuid
|
11
12
|
end
|
12
13
|
|
13
14
|
def translate(body)
|
@@ -51,24 +52,45 @@ module Wovnrb
|
|
51
52
|
end
|
52
53
|
|
53
54
|
def prepare_request(body)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
if @store.compress_api_requests?
|
56
|
+
gzip_request(body)
|
57
|
+
else
|
58
|
+
json_request(body)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def gzip_request(html_body)
|
63
|
+
api_params = build_api_params(html_body)
|
64
|
+
compressed_body = compress_request_data(api_params)
|
65
|
+
request = Net::HTTP::Post.new(request_path(html_body), {
|
66
|
+
'Accept-Encoding' => 'gzip',
|
67
|
+
'Content-Type' => 'application/octet-stream',
|
68
|
+
'Content-Encoding' => 'gzip',
|
69
|
+
'Content-Length' => compressed_body.bytesize.to_s,
|
70
|
+
'X-Request-Id' => @uuid
|
71
|
+
})
|
72
|
+
request.body = compressed_body
|
73
|
+
|
74
|
+
request
|
75
|
+
end
|
61
76
|
|
62
|
-
|
77
|
+
def json_request(html_body)
|
78
|
+
api_params = build_api_params(html_body)
|
79
|
+
request = Net::HTTP::Post.new(request_path(html_body), {
|
80
|
+
'Accept-Encoding' => 'gzip',
|
81
|
+
'Content-Type' => 'application/json',
|
82
|
+
'X-Request-Id' => @uuid
|
83
|
+
})
|
84
|
+
request.body = api_params.to_json
|
63
85
|
|
64
86
|
request
|
65
87
|
end
|
66
88
|
|
67
|
-
def
|
68
|
-
"#{api_uri.path
|
89
|
+
def request_path(body)
|
90
|
+
"#{api_uri.path}/translation?cache_key=#{cache_key(body)}"
|
69
91
|
end
|
70
92
|
|
71
|
-
def
|
93
|
+
def cache_key(body)
|
72
94
|
cache_key_components = {
|
73
95
|
'token' => token,
|
74
96
|
'settings_hash' => settings_hash,
|
@@ -81,8 +103,8 @@ module Wovnrb
|
|
81
103
|
CGI.escape("(#{cache_key_components})")
|
82
104
|
end
|
83
105
|
|
84
|
-
def
|
85
|
-
|
106
|
+
def build_api_params(body)
|
107
|
+
result = {
|
86
108
|
'url' => page_url,
|
87
109
|
'token' => token,
|
88
110
|
'lang_code' => lang_code,
|
@@ -93,9 +115,9 @@ module Wovnrb
|
|
93
115
|
'body' => body
|
94
116
|
}
|
95
117
|
|
96
|
-
|
118
|
+
result['custom_lang_aliases'] = JSON.dump(custom_lang_aliases) unless custom_lang_aliases.empty?
|
97
119
|
|
98
|
-
|
120
|
+
result
|
99
121
|
end
|
100
122
|
|
101
123
|
def compress_request_data(data_hash)
|
@@ -109,7 +131,7 @@ module Wovnrb
|
|
109
131
|
end
|
110
132
|
|
111
133
|
def api_uri
|
112
|
-
Addressable::URI.parse(@store.settings['api_url']
|
134
|
+
Addressable::URI.parse("#{@store.settings['api_url']}/v0")
|
113
135
|
end
|
114
136
|
|
115
137
|
def api_timeout
|
data/lib/wovnrb/headers.rb
CHANGED
@@ -1,17 +1,10 @@
|
|
1
1
|
module Wovnrb
|
2
2
|
class Headers
|
3
|
-
attr_reader :unmasked_url
|
4
|
-
attr_reader :url
|
5
|
-
attr_reader :protocol
|
6
|
-
attr_reader :unmasked_host
|
7
|
-
attr_reader :host
|
8
|
-
attr_reader :unmasked_pathname
|
9
|
-
attr_reader :pathname
|
10
|
-
attr_reader :pathname_with_trailing_slash_if_present
|
3
|
+
attr_reader :unmasked_url, :url, :protocol, :unmasked_host, :host, :unmasked_pathname, :pathname, :pathname_with_trailing_slash_if_present
|
11
4
|
|
12
5
|
# Generates new instance of Wovnrb::Headers.
|
13
6
|
# Its parameters are set by parsing env variable.
|
14
|
-
|
7
|
+
|
15
8
|
def initialize(env, settings)
|
16
9
|
request = Rack::Request.new(env)
|
17
10
|
|
@@ -42,21 +35,21 @@ module Wovnrb
|
|
42
35
|
@pathname, @query = @env['REQUEST_URI'].split('?')
|
43
36
|
@pathname = settings['url_pattern'] == 'path' ? remove_lang(@pathname, lang_code) : @pathname
|
44
37
|
@query ||= ''
|
45
|
-
@url = "#{@host}#{@pathname}#{(
|
46
|
-
if
|
38
|
+
@url = "#{@host}#{@pathname}#{(@query.empty? ? '' : '?') + remove_lang(@query, lang_code)}"
|
39
|
+
if settings['query'].empty?
|
40
|
+
@query = ''
|
41
|
+
else
|
47
42
|
query_vals = []
|
48
43
|
settings['query'].each do |qv|
|
49
44
|
rx = Regexp.new("(^|&)(?<query_val>#{qv}[^&]+)(&|$)")
|
50
45
|
m = @query.match(rx)
|
51
46
|
query_vals.push(m[:query_val]) if m && m[:query_val]
|
52
47
|
end
|
53
|
-
@query = if
|
54
|
-
"?#{query_vals.sort.join('&')}"
|
55
|
-
else
|
48
|
+
@query = if query_vals.empty?
|
56
49
|
''
|
50
|
+
else
|
51
|
+
"?#{query_vals.sort.join('&')}"
|
57
52
|
end
|
58
|
-
else
|
59
|
-
@query = ''
|
60
53
|
end
|
61
54
|
@query = remove_lang(@query, lang_code)
|
62
55
|
@pathname_with_trailing_slash_if_present = @pathname
|
@@ -115,11 +108,11 @@ module Wovnrb
|
|
115
108
|
case @settings['url_pattern']
|
116
109
|
when 'query'
|
117
110
|
lang_param_name = @settings['lang_param_name']
|
118
|
-
if location
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
111
|
+
location = if location =~ /\?/
|
112
|
+
"#{location}&#{lang_param_name}=#{lang_code}"
|
113
|
+
else
|
114
|
+
"#{location}?#{lang_param_name}=#{lang_code}"
|
115
|
+
end
|
123
116
|
when 'subdomain'
|
124
117
|
location = "#{lang_code.downcase}.#{location}"
|
125
118
|
# when 'path'
|
@@ -173,7 +166,7 @@ module Wovnrb
|
|
173
166
|
lang_param_name = @settings['lang_param_name']
|
174
167
|
uri.sub(/(^|\?|&)#{lang_param_name}=#{lang_code}(&|$)/, '\1').gsub(/(\?|&)$/, '')
|
175
168
|
when 'subdomain'
|
176
|
-
rp = Regexp.new(
|
169
|
+
rp = Regexp.new("(^|(//))#{lang_code}\\.", 'i')
|
177
170
|
uri.sub(rp, '\1')
|
178
171
|
# when 'path'
|
179
172
|
else
|
@@ -182,24 +175,22 @@ module Wovnrb
|
|
182
175
|
end
|
183
176
|
|
184
177
|
def out(headers)
|
185
|
-
r = Regexp.new(
|
178
|
+
r = Regexp.new("//#{@host}")
|
186
179
|
lang_code = Store.instance.settings['custom_lang_aliases'][self.lang_code] || self.lang_code
|
187
|
-
if lang_code != @settings['default_lang'] && headers.key?('Location') && headers['Location'] =~ r
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
headers['Location'] = headers['Location'].sub(/(\/\/[^\/]+)/, '\1/' + lang_code)
|
202
|
-
end
|
180
|
+
if lang_code != @settings['default_lang'] && headers.key?('Location') && headers['Location'] =~ r && !@settings['ignore_globs'].ignore?(headers['Location'])
|
181
|
+
case @settings['url_pattern']
|
182
|
+
when 'query'
|
183
|
+
headers['Location'] += if headers['Location'] =~ /\?/
|
184
|
+
'&'
|
185
|
+
else
|
186
|
+
'?'
|
187
|
+
end
|
188
|
+
headers['Location'] += "#{@settings['lang_param_name']}=#{lang_code}"
|
189
|
+
when 'subdomain'
|
190
|
+
headers['Location'] = headers['Location'].sub(/\/\/([^.]+)/, "//#{lang_code}.\\1")
|
191
|
+
# when 'path'
|
192
|
+
else
|
193
|
+
headers['Location'] = headers['Location'].sub(/(\/\/[^\/]+)/, "\\1/#{lang_code}")
|
203
194
|
end
|
204
195
|
end
|
205
196
|
headers
|
@@ -2,15 +2,13 @@ module Wovnrb
|
|
2
2
|
module Helpers
|
3
3
|
module NokogumboHelper
|
4
4
|
def parse_html(html_string, encoding = 'UTF-8')
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
dom
|
5
|
+
if html_string.strip[0..999] =~ /<html/i
|
6
|
+
d = Nokogiri::HTML5(html_string)
|
7
|
+
d.encoding = encoding
|
8
|
+
d
|
9
|
+
else
|
10
|
+
parse_fragment(html_string, encoding)
|
11
|
+
end
|
14
12
|
end
|
15
13
|
|
16
14
|
# https://www.rubydoc.info/gems/nokogumbo/Nokogiri/HTML5#fragment-class_method
|