wovnrb 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +1 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +308 -0
- data/Rakefile +13 -14
- data/lib/wovnrb.rb +43 -98
- data/lib/wovnrb/api_translator.rb +143 -0
- data/lib/wovnrb/headers.rb +78 -92
- data/lib/wovnrb/helpers/nokogumbo_helper.rb +1 -1
- data/lib/wovnrb/lang.rb +93 -125
- data/lib/wovnrb/railtie.rb +5 -7
- data/lib/wovnrb/services/glob.rb +3 -3
- data/lib/wovnrb/services/html_converter.rb +192 -0
- data/lib/wovnrb/services/html_replace_marker.rb +38 -0
- data/lib/wovnrb/services/wovn_logger.rb +8 -4
- data/lib/wovnrb/settings.rb +5 -3
- data/lib/wovnrb/store.rb +35 -26
- data/lib/wovnrb/text_caches/cache_base.rb +3 -2
- data/lib/wovnrb/text_caches/memory_cache.rb +2 -2
- data/lib/wovnrb/version.rb +1 -1
- data/test/fixtures/html/test.html +8 -0
- data/test/fixtures/html/test_translated.html +8 -0
- data/test/lib/api_translator_test.rb +109 -0
- data/test/lib/headers_test.rb +84 -55
- data/test/lib/lang_test.rb +157 -357
- data/test/lib/services/glob_test.rb +1 -1
- data/test/lib/services/html_converter_test.rb +166 -0
- data/test/lib/services/html_replace_marker_test.rb +75 -0
- data/test/lib/services/wovn_logger_test.rb +6 -6
- data/test/lib/store_test.rb +25 -69
- data/test/lib/text_caches/cache_base_test.rb +1 -1
- data/test/lib/text_caches/memory_cache_test.rb +10 -11
- data/test/lib/wovnrb_test.rb +77 -310
- data/test/test_helper.rb +22 -32
- data/wovnrb.gemspec +35 -44
- metadata +86 -205
- data/ext/dom/Makefile +0 -239
- data/lib/wovnrb/api_data.rb +0 -59
- data/lib/wovnrb/html_replacers/image_replacer.rb +0 -69
- data/lib/wovnrb/html_replacers/input_replacer.rb +0 -38
- data/lib/wovnrb/html_replacers/link_replacer.rb +0 -78
- data/lib/wovnrb/html_replacers/meta_replacer.rb +0 -28
- data/lib/wovnrb/html_replacers/replacer_base.rb +0 -49
- data/lib/wovnrb/html_replacers/script_replacer.rb +0 -39
- data/lib/wovnrb/html_replacers/text_replacer.rb +0 -21
- data/lib/wovnrb/html_replacers/unified_values/dst_swapping_targets_creator.rb +0 -76
- data/lib/wovnrb/html_replacers/unified_values/element_category.rb +0 -242
- data/lib/wovnrb/html_replacers/unified_values/node_swapping_targets_creator.rb +0 -134
- data/lib/wovnrb/html_replacers/unified_values/text_replacer.rb +0 -35
- data/lib/wovnrb/html_replacers/unified_values/text_scraper.rb +0 -152
- data/lib/wovnrb/html_replacers/unified_values/values_stack.rb +0 -65
- data/lib/wovnrb/services/url.rb +0 -12
- data/lib/wovnrb/services/value_agent.rb +0 -9
- data/test/fixtures/unified_values/site_html/simple_actual.html +0 -96
- data/test/fixtures/unified_values/site_html/simple_expected.json +0 -251
- data/test/fixtures/unified_values/site_html/wovn.io_actual.html +0 -686
- data/test/fixtures/unified_values/site_html/wovn.io_expected.json +0 -543
- data/test/fixtures/unified_values/site_html/www.yahoo.co.jp_actual.html +0 -1024
- data/test/fixtures/unified_values/site_html/www.yahoo.co.jp_expected.json +0 -3345
- data/test/fixtures/unified_values/small_html/block_inside_inline_actual.html +0 -12
- data/test/fixtures/unified_values/small_html/block_inside_inline_expected.json +0 -22
- data/test/fixtures/unified_values/small_html/br_tag_actual.html +0 -10
- data/test/fixtures/unified_values/small_html/br_tag_expected.json +0 -12
- data/test/fixtures/unified_values/small_html/comment_tag_actual.html +0 -12
- data/test/fixtures/unified_values/small_html/comment_tag_expected.json +0 -10
- data/test/fixtures/unified_values/small_html/complex_text_with_html_entity_actual.html +0 -7
- data/test/fixtures/unified_values/small_html/complex_text_with_html_entity_expected.json +0 -11
- data/test/fixtures/unified_values/small_html/deep_nested_block_actual.html +0 -14
- data/test/fixtures/unified_values/small_html/deep_nested_block_expected.json +0 -8
- data/test/fixtures/unified_values/small_html/deep_nested_inline_actual.html +0 -20
- data/test/fixtures/unified_values/small_html/deep_nested_inline_expected.json +0 -20
- data/test/fixtures/unified_values/small_html/empty_tag_actual.html +0 -10
- data/test/fixtures/unified_values/small_html/empty_tag_expected.json +0 -12
- data/test/fixtures/unified_values/small_html/empty_text_actual.html +0 -12
- data/test/fixtures/unified_values/small_html/empty_text_expected.json +0 -1
- data/test/fixtures/unified_values/small_html/ignore_tag_actual.html +0 -12
- data/test/fixtures/unified_values/small_html/ignore_tag_expected.json +0 -16
- data/test/fixtures/unified_values/small_html/ignored_class_actual.html +0 -10
- data/test/fixtures/unified_values/small_html/ignored_class_expected.json +0 -13
- data/test/fixtures/unified_values/small_html/img_actual.html +0 -12
- data/test/fixtures/unified_values/small_html/img_expected.json +0 -23
- data/test/fixtures/unified_values/small_html/nested_and_complex_wovn_ignore_actual.html +0 -10
- data/test/fixtures/unified_values/small_html/nested_and_complex_wovn_ignore_expected.json +0 -16
- data/test/fixtures/unified_values/small_html/nested_text_value_actual.html +0 -10
- data/test/fixtures/unified_values/small_html/nested_text_value_expected.json +0 -12
- data/test/fixtures/unified_values/small_html/nested_text_value_mixed_plan_text_actual.html +0 -10
- data/test/fixtures/unified_values/small_html/nested_text_value_mixed_plan_text_expected.json +0 -14
- data/test/fixtures/unified_values/small_html/option_tag_actual.html +0 -9
- data/test/fixtures/unified_values/small_html/option_tag_expected.json +0 -13
- data/test/fixtures/unified_values/small_html/text_different_inline_each_other_actual.html +0 -10
- data/test/fixtures/unified_values/small_html/text_different_inline_each_other_expected.json +0 -22
- data/test/fixtures/unified_values/small_html/text_in_svg_actual.html +0 -9
- data/test/fixtures/unified_values/small_html/text_in_svg_expected.json +0 -8
- data/test/fixtures/unified_values/small_html/text_with_html_entity_actual.html +0 -6
- data/test/fixtures/unified_values/small_html/text_with_html_entity_expected.json +0 -8
- data/test/fixtures/unified_values/small_html/unknown_or_custom_tag_actual.html +0 -12
- data/test/fixtures/unified_values/small_html/unknown_or_custom_tag_expected.json +0 -24
- data/test/fixtures/unified_values/small_html/unnecessay_top_end_tag_actual.html +0 -12
- data/test/fixtures/unified_values/small_html/unnecessay_top_end_tag_expected.json +0 -14
- data/test/fixtures/unified_values/small_html/wovn_ignore_actual.html +0 -10
- data/test/fixtures/unified_values/small_html/wovn_ignore_expected.json +0 -13
- data/test/lib/api_data_test.rb +0 -83
- data/test/lib/html_replacers/image_replacer_test.rb +0 -165
- data/test/lib/html_replacers/input_replacer_test.rb +0 -140
- data/test/lib/html_replacers/link_replacer_test.rb +0 -328
- data/test/lib/html_replacers/meta_replacer_test.rb +0 -157
- data/test/lib/html_replacers/replacer_base_test.rb +0 -128
- data/test/lib/html_replacers/script_replacer_test.rb +0 -139
- data/test/lib/html_replacers/text_replacer_test.rb +0 -99
- data/test/lib/html_replacers/unified_values/dst_swapping_targets_creator_test.rb +0 -137
- data/test/lib/html_replacers/unified_values/element_category_test.rb +0 -49
- data/test/lib/html_replacers/unified_values/node_swapping_targets_creator_test.rb +0 -137
- data/test/lib/html_replacers/unified_values/text_replacer_test.rb +0 -270
- data/test/lib/html_replacers/unified_values/text_scraper_test.rb +0 -121
- data/test/lib/html_replacers/unified_values/values_stack_test.rb +0 -122
- data/test/lib/services/url_test.rb +0 -9
- data/test/lib/services/value_agent_test.rb +0 -32
- data/test/services/url_test.rb +0 -163
- data/values/values +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 548c84031681d4273db42c24a7ccfd8faaad9b31
|
4
|
+
data.tar.gz: 6c82fab859281f1b946f4199a1737daaa5112842
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd388862202899e8d3acbe2d5aa8fe8a55bc5c89684beec438df56da6d7c366bcd71bd72fcb049767586de4bd34f56cfdd275ba7cb1710f22e04dcf27f94c5b3
|
7
|
+
data.tar.gz: abee33fc5f353e531363d59001a258bed0b07ae4809b07560d10a0889371b4435e19b53ad00d3796157cbf96b87ae9859abe0baa33eafeaf48277b65d4310a1f
|
data/.circleci/config.yml
CHANGED
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,308 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2018-11-02 18:52:46 +0900 using RuboCop version 0.60.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 1
|
10
|
+
# Cop supports --auto-correct.
|
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'
|
20
|
+
|
21
|
+
# Offense count: 11
|
22
|
+
# Cop supports --auto-correct.
|
23
|
+
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
|
24
|
+
Layout/ExtraSpacing:
|
25
|
+
Exclude:
|
26
|
+
- 'lib/wovnrb/lang.rb'
|
27
|
+
|
28
|
+
# Offense count: 1
|
29
|
+
# Cop supports --auto-correct.
|
30
|
+
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
31
|
+
# SupportedStyles: special_inside_parentheses, consistent, align_braces
|
32
|
+
Layout/IndentHash:
|
33
|
+
Exclude:
|
34
|
+
- 'lib/wovnrb/text_caches/cache_base.rb'
|
35
|
+
|
36
|
+
# Offense count: 4
|
37
|
+
# Cop supports --auto-correct.
|
38
|
+
# Configuration parameters: EnforcedStyle.
|
39
|
+
# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
|
40
|
+
Layout/IndentHeredoc:
|
41
|
+
Exclude:
|
42
|
+
- 'test/lib/lang_test.rb'
|
43
|
+
- 'test/lib/wovnrb_test.rb'
|
44
|
+
|
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
|
+
# Offense count: 3
|
53
|
+
# Configuration parameters: AllowSafeAssignment.
|
54
|
+
Lint/AssignmentInCondition:
|
55
|
+
Exclude:
|
56
|
+
- 'lib/wovnrb/helpers/nokogumbo_helper.rb'
|
57
|
+
|
58
|
+
# Offense count: 1
|
59
|
+
Lint/DuplicateMethods:
|
60
|
+
Exclude:
|
61
|
+
- 'test/lib/headers_test.rb'
|
62
|
+
|
63
|
+
# Offense count: 1
|
64
|
+
Lint/ElseLayout:
|
65
|
+
Exclude:
|
66
|
+
- 'lib/wovnrb/headers.rb'
|
67
|
+
|
68
|
+
# Offense count: 1
|
69
|
+
Lint/ImplicitStringConcatenation:
|
70
|
+
Exclude:
|
71
|
+
- 'test/lib/lang_test.rb'
|
72
|
+
|
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
|
+
# Offense count: 5
|
81
|
+
Lint/UselessAssignment:
|
82
|
+
Exclude:
|
83
|
+
- 'test/lib/store_test.rb'
|
84
|
+
|
85
|
+
# Offense count: 22
|
86
|
+
Metrics/AbcSize:
|
87
|
+
Max: 100
|
88
|
+
|
89
|
+
# Offense count: 1
|
90
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
91
|
+
# ExcludedMethods: refine
|
92
|
+
Metrics/BlockLength:
|
93
|
+
Max: 40
|
94
|
+
|
95
|
+
# Offense count: 2
|
96
|
+
# Configuration parameters: CountBlocks.
|
97
|
+
Metrics/BlockNesting:
|
98
|
+
Max: 4
|
99
|
+
|
100
|
+
# Offense count: 10
|
101
|
+
# Configuration parameters: CountComments.
|
102
|
+
Metrics/ClassLength:
|
103
|
+
Max: 4997
|
104
|
+
|
105
|
+
# Offense count: 14
|
106
|
+
Metrics/CyclomaticComplexity:
|
107
|
+
Max: 22
|
108
|
+
|
109
|
+
# Offense count: 45
|
110
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
111
|
+
Metrics/MethodLength:
|
112
|
+
Max: 95
|
113
|
+
|
114
|
+
# Offense count: 12
|
115
|
+
Metrics/PerceivedComplexity:
|
116
|
+
Max: 22
|
117
|
+
|
118
|
+
# Offense count: 3
|
119
|
+
Naming/AccessorMethodName:
|
120
|
+
Exclude:
|
121
|
+
- 'lib/wovnrb/services/wovn_logger.rb'
|
122
|
+
- 'lib/wovnrb/text_caches/cache_base.rb'
|
123
|
+
|
124
|
+
# Offense count: 120
|
125
|
+
# Configuration parameters: .
|
126
|
+
# SupportedStyles: snake_case, camelCase
|
127
|
+
Naming/MethodName:
|
128
|
+
EnforcedStyle: snake_case
|
129
|
+
Exclude:
|
130
|
+
- 'test/lib/headers_test.rb'
|
131
|
+
|
132
|
+
# Offense count: 5
|
133
|
+
# Cop supports --auto-correct.
|
134
|
+
# Configuration parameters: EnforcedStyle.
|
135
|
+
# SupportedStyles: always, conditionals
|
136
|
+
Style/AndOr:
|
137
|
+
Exclude:
|
138
|
+
- 'Rakefile'
|
139
|
+
- 'lib/wovnrb/helpers/nokogumbo_helper.rb'
|
140
|
+
|
141
|
+
# Offense count: 1
|
142
|
+
Style/CaseEquality:
|
143
|
+
Exclude:
|
144
|
+
- 'lib/wovnrb/lang.rb'
|
145
|
+
|
146
|
+
# Offense count: 5
|
147
|
+
# Cop supports --auto-correct.
|
148
|
+
# Configuration parameters: EnforcedStyle.
|
149
|
+
# SupportedStyles: is_a?, kind_of?
|
150
|
+
Style/ClassCheck:
|
151
|
+
Exclude:
|
152
|
+
- 'lib/wovnrb/store.rb'
|
153
|
+
|
154
|
+
# Offense count: 6
|
155
|
+
Style/ClassVars:
|
156
|
+
Exclude:
|
157
|
+
- 'lib/wovnrb/text_caches/cache_base.rb'
|
158
|
+
- 'lib/wovnrb/text_caches/memory_cache.rb'
|
159
|
+
|
160
|
+
# Offense count: 1
|
161
|
+
# Cop supports --auto-correct.
|
162
|
+
# Configuration parameters: Keywords.
|
163
|
+
# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW
|
164
|
+
Style/CommentAnnotation:
|
165
|
+
Exclude:
|
166
|
+
- 'lib/wovnrb/headers.rb'
|
167
|
+
|
168
|
+
# Offense count: 13
|
169
|
+
Style/Documentation:
|
170
|
+
Exclude:
|
171
|
+
- 'spec/**/*'
|
172
|
+
- 'test/**/*'
|
173
|
+
- 'lib/wovnrb.rb'
|
174
|
+
- 'lib/wovnrb/api_translator.rb'
|
175
|
+
- 'lib/wovnrb/headers.rb'
|
176
|
+
- 'lib/wovnrb/helpers/nokogumbo_helper.rb'
|
177
|
+
- 'lib/wovnrb/lang.rb'
|
178
|
+
- 'lib/wovnrb/railtie.rb'
|
179
|
+
- 'lib/wovnrb/services/html_converter.rb'
|
180
|
+
- 'lib/wovnrb/services/html_replace_marker.rb'
|
181
|
+
- 'lib/wovnrb/services/wovn_logger.rb'
|
182
|
+
- 'lib/wovnrb/settings.rb'
|
183
|
+
- 'lib/wovnrb/store.rb'
|
184
|
+
- 'lib/wovnrb/text_caches/cache_base.rb'
|
185
|
+
- 'lib/wovnrb/text_caches/memory_cache.rb'
|
186
|
+
|
187
|
+
# Offense count: 2
|
188
|
+
Style/DoubleNegation:
|
189
|
+
Exclude:
|
190
|
+
- 'lib/wovnrb.rb'
|
191
|
+
- 'lib/wovnrb/services/html_converter.rb'
|
192
|
+
|
193
|
+
# Offense count: 3
|
194
|
+
# Cop supports --auto-correct.
|
195
|
+
# Configuration parameters: EnforcedStyle.
|
196
|
+
# SupportedStyles: each, for
|
197
|
+
Style/For:
|
198
|
+
Exclude:
|
199
|
+
- 'test/lib/headers_test.rb'
|
200
|
+
|
201
|
+
# Offense count: 4
|
202
|
+
# Configuration parameters: MinBodyLength.
|
203
|
+
Style/GuardClause:
|
204
|
+
Exclude:
|
205
|
+
- 'lib/wovnrb/services/html_converter.rb'
|
206
|
+
- 'lib/wovnrb/store.rb'
|
207
|
+
- 'test/lib/api_translator_test.rb'
|
208
|
+
|
209
|
+
# Offense count: 1
|
210
|
+
# Cop supports --auto-correct.
|
211
|
+
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
|
212
|
+
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
|
213
|
+
Style/HashSyntax:
|
214
|
+
Exclude:
|
215
|
+
- 'Rakefile'
|
216
|
+
|
217
|
+
# Offense count: 13
|
218
|
+
# Cop supports --auto-correct.
|
219
|
+
Style/IfUnlessModifier:
|
220
|
+
Exclude:
|
221
|
+
- 'Gemfile'
|
222
|
+
- 'Rakefile'
|
223
|
+
- 'lib/wovnrb/helpers/nokogumbo_helper.rb'
|
224
|
+
- 'lib/wovnrb/store.rb'
|
225
|
+
- 'lib/wovnrb/text_caches/memory_cache.rb'
|
226
|
+
|
227
|
+
# Offense count: 1
|
228
|
+
# Cop supports --auto-correct.
|
229
|
+
# Configuration parameters: EnforcedStyle.
|
230
|
+
# SupportedStyles: both, prefix, postfix
|
231
|
+
Style/NegatedIf:
|
232
|
+
Exclude:
|
233
|
+
- 'lib/wovnrb/store.rb'
|
234
|
+
|
235
|
+
# Offense count: 2
|
236
|
+
# Cop supports --auto-correct.
|
237
|
+
# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
|
238
|
+
# SupportedStyles: predicate, comparison
|
239
|
+
Style/NumericPredicate:
|
240
|
+
Exclude:
|
241
|
+
- 'spec/**/*'
|
242
|
+
- 'lib/wovnrb/store.rb'
|
243
|
+
|
244
|
+
# Offense count: 9
|
245
|
+
# Cop supports --auto-correct.
|
246
|
+
# Configuration parameters: EnforcedStyle.
|
247
|
+
# SupportedStyles: short, verbose
|
248
|
+
Style/PreferredHashMethods:
|
249
|
+
Exclude:
|
250
|
+
- 'lib/wovnrb/store.rb'
|
251
|
+
- 'lib/wovnrb/text_caches/memory_cache.rb'
|
252
|
+
|
253
|
+
# Offense count: 2
|
254
|
+
# Cop supports --auto-correct.
|
255
|
+
# Configuration parameters: .
|
256
|
+
# SupportedStyles: compact, exploded
|
257
|
+
Style/RaiseArgs:
|
258
|
+
EnforcedStyle: compact
|
259
|
+
|
260
|
+
# Offense count: 22
|
261
|
+
# Cop supports --auto-correct.
|
262
|
+
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
|
263
|
+
# SupportedStyles: slashes, percent_r, mixed
|
264
|
+
Style/RegexpLiteral:
|
265
|
+
Exclude:
|
266
|
+
- 'lib/wovnrb/api_translator.rb'
|
267
|
+
- 'lib/wovnrb/headers.rb'
|
268
|
+
- 'lib/wovnrb/lang.rb'
|
269
|
+
- 'lib/wovnrb/services/html_converter.rb'
|
270
|
+
|
271
|
+
# Offense count: 4
|
272
|
+
# Cop supports --auto-correct.
|
273
|
+
# Configuration parameters: EnforcedStyle.
|
274
|
+
# SupportedStyles: implicit, explicit
|
275
|
+
Style/RescueStandardError:
|
276
|
+
Exclude:
|
277
|
+
- 'lib/wovnrb/api_translator.rb'
|
278
|
+
- 'lib/wovnrb/lang.rb'
|
279
|
+
- 'lib/wovnrb/services/wovn_logger.rb'
|
280
|
+
|
281
|
+
# Offense count: 1
|
282
|
+
# Cop supports --auto-correct.
|
283
|
+
Style/StderrPuts:
|
284
|
+
Exclude:
|
285
|
+
- 'lib/wovnrb/services/wovn_logger.rb'
|
286
|
+
|
287
|
+
# Offense count: 4
|
288
|
+
# Cop supports --auto-correct.
|
289
|
+
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
|
290
|
+
# SupportedStyles: single_quotes, double_quotes
|
291
|
+
Style/StringLiterals:
|
292
|
+
Exclude:
|
293
|
+
- 'Rakefile'
|
294
|
+
- 'lib/wovnrb/store.rb'
|
295
|
+
|
296
|
+
# Offense count: 7
|
297
|
+
# Cop supports --auto-correct.
|
298
|
+
Style/ZeroLengthPredicate:
|
299
|
+
Exclude:
|
300
|
+
- 'Rakefile'
|
301
|
+
- 'lib/wovnrb/helpers/nokogumbo_helper.rb'
|
302
|
+
- 'lib/wovnrb/store.rb'
|
303
|
+
|
304
|
+
# Offense count: 1436
|
305
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
306
|
+
# URISchemes: http, https
|
307
|
+
Metrics/LineLength:
|
308
|
+
Max: 1424
|
data/Rakefile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#require "bundler/gem_tasks"
|
2
|
-
#require 'rake/extensiontask'
|
1
|
+
# require "bundler/gem_tasks"
|
2
|
+
# require 'rake/extensiontask'
|
3
3
|
require 'rake/testtask'
|
4
4
|
require 'pry'
|
5
5
|
|
@@ -24,18 +24,17 @@ end
|
|
24
24
|
desc 'Run tests'
|
25
25
|
task :default => :test
|
26
26
|
|
27
|
-
#Rake::ExtensionTask.new 'dom' do |ext|
|
27
|
+
# Rake::ExtensionTask.new 'dom' do |ext|
|
28
28
|
# ext.lib_dir = 'lib/wovnrb'
|
29
|
-
#end
|
29
|
+
# end
|
30
30
|
|
31
|
-
#gemspec = Gem::Specification.load('wovnrb.gemspec')
|
32
|
-
#Rake::ExtensionTask.new do |ext|
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#end
|
31
|
+
# gemspec = Gem::Specification.load('wovnrb.gemspec')
|
32
|
+
# Rake::ExtensionTask.new do |ext|
|
33
|
+
# ext.name = 'dom'
|
34
|
+
# ext.source_pattern = "*.{cpp,h}"
|
35
|
+
# ext.ext_dir = 'ext/wovnrb'
|
36
|
+
# ext.lib_dir = 'lib/wovnrb'
|
37
|
+
# ext.gem_spec = gemspec
|
38
|
+
# end
|
39
39
|
#
|
40
|
-
#task :default => [:compile]
|
41
|
-
|
40
|
+
# task :default => [:compile]
|
data/lib/wovnrb.rb
CHANGED
@@ -1,135 +1,88 @@
|
|
1
1
|
require 'rack'
|
2
|
-
require 'wovnrb/
|
2
|
+
require 'wovnrb/api_translator'
|
3
3
|
require 'wovnrb/headers'
|
4
|
+
require 'wovnrb/store'
|
4
5
|
require 'wovnrb/lang'
|
6
|
+
require 'wovnrb/services/html_converter'
|
7
|
+
require 'wovnrb/services/html_replace_marker'
|
5
8
|
require 'nokogumbo'
|
6
9
|
require 'active_support'
|
7
|
-
#require 'dom'
|
8
10
|
require 'json'
|
9
11
|
require 'wovnrb/helpers/nokogumbo_helper'
|
10
|
-
require 'wovnrb/api_data'
|
11
12
|
require 'wovnrb/text_caches/cache_base'
|
12
|
-
require 'wovnrb/html_replacers/replacer_base'
|
13
|
-
require 'wovnrb/html_replacers/link_replacer'
|
14
|
-
require 'wovnrb/html_replacers/text_replacer'
|
15
|
-
require 'wovnrb/html_replacers/meta_replacer'
|
16
|
-
require 'wovnrb/html_replacers/input_replacer'
|
17
|
-
require 'wovnrb/html_replacers/image_replacer'
|
18
|
-
require 'wovnrb/html_replacers/script_replacer'
|
19
|
-
require 'wovnrb/html_replacers/unified_values/text_replacer'
|
20
|
-
require 'wovnrb/html_replacers/unified_values/text_scraper'
|
21
|
-
require 'wovnrb/html_replacers/unified_values/values_stack'
|
22
|
-
require 'wovnrb/html_replacers/unified_values/element_category'
|
23
|
-
require 'wovnrb/html_replacers/unified_values/dst_swapping_targets_creator'
|
24
|
-
require 'wovnrb/html_replacers/unified_values/node_swapping_targets_creator'
|
25
13
|
require 'wovnrb/railtie' if defined?(Rails)
|
26
14
|
require 'wovnrb/version'
|
27
15
|
|
28
16
|
module Wovnrb
|
29
17
|
class Interceptor
|
30
|
-
def initialize(app, opts={})
|
18
|
+
def initialize(app, opts = {})
|
31
19
|
@app = app
|
32
20
|
@store = Store.instance
|
33
|
-
opts = opts.each_with_object({}){|(k,v),memo| memo[k.to_s]=v}
|
21
|
+
opts = opts.each_with_object({}) { |(k, v), memo| memo[k.to_s] = v }
|
34
22
|
@store.update_settings(opts)
|
35
23
|
CacheBase.set_single(@store.settings)
|
36
24
|
end
|
37
25
|
|
38
26
|
def call(env)
|
39
27
|
@store.settings.clear_dynamic_settings!
|
40
|
-
unless Store.instance.valid_settings?
|
41
|
-
|
42
|
-
end
|
28
|
+
return @app.call(env) unless Store.instance.valid_settings?
|
29
|
+
|
43
30
|
@env = env
|
44
31
|
headers = Headers.new(env, @store.settings)
|
45
|
-
if @store.settings['test_mode'] && @store.settings['test_url'] != headers.url
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
if (headers.path_lang == @store.settings['default_lang'])
|
32
|
+
return @app.call(env) if @store.settings['test_mode'] && @store.settings['test_url'] != headers.url
|
33
|
+
|
34
|
+
# redirect if the path is set to the default language (for SEO purposes)
|
35
|
+
if headers.path_lang == @store.settings['default_lang']
|
50
36
|
redirect_headers = headers.redirect(@store.settings['default_lang'])
|
51
37
|
return [307, redirect_headers, ['']]
|
52
38
|
end
|
53
|
-
lang = headers.lang_code
|
54
39
|
|
55
40
|
# pass to application
|
56
41
|
status, res_headers, body = @app.call(headers.request_out)
|
57
42
|
|
58
|
-
unless res_headers[
|
59
|
-
return output(headers, status, res_headers, body)
|
60
|
-
end
|
43
|
+
return output(headers, status, res_headers, body) unless res_headers['Content-Type'] =~ /html/
|
61
44
|
|
62
45
|
request = Rack::Request.new(env)
|
63
46
|
|
64
|
-
if request.params['wovn_disable'] == true
|
65
|
-
return output(headers, status, res_headers, body)
|
66
|
-
end
|
47
|
+
return output(headers, status, res_headers, body) if request.params['wovn_disable'] == true
|
67
48
|
|
68
49
|
@store.settings.update_dynamic_settings!(request.params)
|
69
|
-
if @store.settings['ignore_globs'].any?{|g| g.match?(headers.pathname)}
|
70
|
-
return output(headers, status, res_headers, body)
|
71
|
-
end
|
50
|
+
return output(headers, status, res_headers, body) if @store.settings['ignore_globs'].any? { |g| g.match?(headers.pathname) }
|
72
51
|
|
73
|
-
|
74
|
-
# Because some server not allow multi thread. (env['async.callback'] is not supported at all Server).
|
75
|
-
api_data = ApiData.new(headers.redis_url, @store)
|
76
|
-
values = api_data.get_data
|
77
|
-
|
78
|
-
url = {
|
79
|
-
:protocol => headers.protocol,
|
80
|
-
:host => headers.host,
|
81
|
-
:pathname => headers.pathname
|
82
|
-
}
|
83
|
-
body = switch_lang(body, values, url, lang, headers) unless status.to_s =~ /^1|302/
|
52
|
+
body = switch_lang(headers, body) unless status.to_s =~ /^1|302/
|
84
53
|
|
85
54
|
content_length = 0
|
86
55
|
body.each { |b| content_length += b.respond_to?(:bytesize) ? b.bytesize : 0 }
|
87
|
-
res_headers[
|
56
|
+
res_headers['Content-Length'] = content_length.to_s
|
88
57
|
|
89
58
|
output(headers, status, res_headers, body)
|
90
59
|
end
|
91
60
|
|
92
|
-
def switch_lang(
|
93
|
-
|
94
|
-
ignore_all = false
|
95
|
-
new_body = []
|
96
|
-
|
97
|
-
# generate full_body to intercept
|
98
|
-
full_body = ''
|
99
|
-
body.each { |b| full_body += b }
|
100
|
-
|
101
|
-
[full_body].each do |b|
|
102
|
-
# temporarily remove noscripts
|
103
|
-
noscripts = []
|
104
|
-
b_without_noscripts = b
|
105
|
-
b.scan /<noscript.*?>.*?<\/noscript>/m do |match|
|
106
|
-
noscript_identifier = "<noscript wovn-id=\"#{noscripts.count}\"></noscript>"
|
107
|
-
noscripts << match
|
108
|
-
b_without_noscripts = b_without_noscripts.sub(match, noscript_identifier)
|
109
|
-
end
|
61
|
+
def switch_lang(headers, body)
|
62
|
+
translated_body = []
|
110
63
|
|
111
|
-
|
64
|
+
# Must use `.each` for to support multiple-chunks in Sinatra
|
65
|
+
string_body = ''
|
66
|
+
body.each { |chunk| string_body += chunk }
|
67
|
+
html_body = Helpers::NokogumboHelper.parse_html(string_body)
|
112
68
|
|
113
|
-
|
114
|
-
|
115
|
-
ignore_all = true
|
116
|
-
output = d.to_html(save_with: 0).gsub(/href="([^"]*)"/) { |m| "href=\"#{URI.decode($1)}\"" }
|
117
|
-
put_back_noscripts!(output, noscripts)
|
118
|
-
new_body.push(output)
|
119
|
-
next
|
120
|
-
end
|
69
|
+
if !wovn_ignored?(html_body) && !amp_page?(html_body)
|
70
|
+
html_converter = HtmlConverter.new(html_body, @store, headers)
|
121
71
|
|
122
|
-
if
|
123
|
-
|
72
|
+
if needs_api?(html_body, headers)
|
73
|
+
converted_html, marker = html_converter.build_api_compatible_html
|
74
|
+
translated_content = ApiTranslator.new(@store, headers).translate(converted_html)
|
75
|
+
translated_body.push(marker.revert(translated_content))
|
124
76
|
else
|
125
|
-
|
126
|
-
|
77
|
+
string_body = html_converter.build if html_body.html?
|
78
|
+
translated_body.push(string_body)
|
127
79
|
end
|
128
|
-
|
129
|
-
|
80
|
+
else
|
81
|
+
translated_body.push(string_body)
|
130
82
|
end
|
83
|
+
|
131
84
|
body.close if body.respond_to?(:close)
|
132
|
-
|
85
|
+
translated_body
|
133
86
|
end
|
134
87
|
|
135
88
|
private
|
@@ -139,21 +92,13 @@ module Wovnrb
|
|
139
92
|
[status, res_headers, body]
|
140
93
|
end
|
141
94
|
|
142
|
-
def
|
143
|
-
|
144
|
-
|
145
|
-
can_translate && have_data?(values)
|
146
|
-
end
|
147
|
-
|
148
|
-
def have_data?(values)
|
149
|
-
values.count > 0
|
95
|
+
def needs_api?(html_body, headers)
|
96
|
+
headers.lang_code != @store.settings['default_lang'] &&
|
97
|
+
(html_body.html? || @store.settings['translate_fragment'])
|
150
98
|
end
|
151
99
|
|
152
|
-
def
|
153
|
-
|
154
|
-
noscript_identifier = "<noscript wovn-id=\"#{index}\"></noscript>"
|
155
|
-
output.sub!(noscript_identifier, noscript)
|
156
|
-
end
|
100
|
+
def wovn_ignored?(html_body)
|
101
|
+
!html_body.xpath('//html[@wovn-ignore]').empty?
|
157
102
|
end
|
158
103
|
|
159
104
|
# Checks if a given HTML body is an Accelerated Mobile Page (AMP).
|
@@ -163,10 +108,10 @@ module Wovnrb
|
|
163
108
|
# @param {Nokogiri::HTML5::Document} body The HTML body to check.
|
164
109
|
#
|
165
110
|
# @returns {Boolean} True is the HTML body is an AMP, false otherwise.
|
166
|
-
def
|
167
|
-
html_attributes =
|
111
|
+
def amp_page?(html_body)
|
112
|
+
html_attributes = html_body.xpath('//html')[0].try(:attributes) || {}
|
168
113
|
|
169
|
-
html_attributes['amp'] || html_attributes["\u26A1"]
|
114
|
+
!!(html_attributes['amp'] || html_attributes["\u26A1"])
|
170
115
|
end
|
171
116
|
end
|
172
117
|
end
|