wovnrb 1.0.6 → 1.0.7
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 +5 -5
- data/.circleci/config.yml +17 -0
- data/README.md +5 -0
- data/lib/wovnrb/html_replacers/image_replacer.rb +2 -1
- data/lib/wovnrb/html_replacers/input_replacer.rb +2 -1
- data/lib/wovnrb/html_replacers/link_replacer.rb +2 -1
- data/lib/wovnrb/html_replacers/meta_replacer.rb +2 -1
- data/lib/wovnrb/html_replacers/replacer_base.rb +15 -0
- data/lib/wovnrb/html_replacers/script_replacer.rb +1 -1
- data/lib/wovnrb/html_replacers/text_replacer.rb +2 -1
- data/lib/wovnrb/lang.rb +5 -5
- data/lib/wovnrb/store.rb +5 -0
- data/lib/wovnrb/version.rb +1 -1
- data/test/lib/html_replacers/image_replacer_test.rb +16 -11
- data/test/lib/html_replacers/input_replacer_test.rb +18 -9
- data/test/lib/html_replacers/link_replacer_test.rb +40 -20
- data/test/lib/html_replacers/meta_replacer_test.rb +17 -9
- data/test/lib/html_replacers/replacer_base_test.rb +43 -7
- data/test/lib/html_replacers/text_replacer_test.rb +6 -3
- data/test/lib/wovnrb_test.rb +1 -1
- metadata +4 -4
- data/circle.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d57533c589ec6dfd2171967b855c3cf7dac3b5da
|
4
|
+
data.tar.gz: 4697b8fbd091071187d742bd3bbcb34a71ac7c1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c970c7c8772d0ed103b9b6700abf632c2d6834ce2343ad0b06c94fe0ae1e53a4d124a1a759d5c089ac0916f068d81f2f36c89161d59c06fd1218ef1818c3784
|
7
|
+
data.tar.gz: e927ee8669e85fbd1c516773c896f8bc2e78378121cf1240555d12e99ae7a84deb8118bc767979d704e8ad70a9dc70d2e486d9d1c4ecae61f5518f6b31ad3ff7
|
@@ -0,0 +1,17 @@
|
|
1
|
+
version: 2
|
2
|
+
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
docker:
|
6
|
+
- image: circleci/ruby:2.3-jessie
|
7
|
+
steps:
|
8
|
+
- checkout
|
9
|
+
- restore_cache:
|
10
|
+
keys:
|
11
|
+
- bundler-
|
12
|
+
- run: bundle install --path vendor/bundle --jobs=4
|
13
|
+
- save_cache:
|
14
|
+
key: bundler-{{ checksum "Gemfile.lock" }}
|
15
|
+
paths:
|
16
|
+
- vendor/bundle
|
17
|
+
- run: bundle exec rake test
|
data/README.md
CHANGED
@@ -72,6 +72,7 @@ project_token | yes | ''
|
|
72
72
|
url_pattern | yes | 'path'
|
73
73
|
query | | []
|
74
74
|
default_lang | yes | 'en'
|
75
|
+
ignore_class | | []
|
75
76
|
|
76
77
|
### 2.1. project_token
|
77
78
|
|
@@ -119,6 +120,10 @@ The library will redirect to the following URL.
|
|
119
120
|
|
120
121
|
https://wovn.io/contact
|
121
122
|
|
123
|
+
### 2.5 ignore_class
|
124
|
+
|
125
|
+
This sets "Ignore class" which prevent WOVN translating HTML elements that have one of the array.
|
126
|
+
|
122
127
|
## 3. Contributing
|
123
128
|
|
124
129
|
1. Fork it ( https://github.com/WOVNio/wovnrb/fork )
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Wovnrb
|
2
2
|
class ImageReplacer < ReplacerBase
|
3
|
-
def initialize(url, text_index, src_index, img_src_prefix, host_aliases)
|
3
|
+
def initialize(store, url, text_index, src_index, img_src_prefix, host_aliases)
|
4
|
+
super(store)
|
4
5
|
@url = url
|
5
6
|
@text_index = text_index
|
6
7
|
@src_index = src_index
|
@@ -7,7 +7,8 @@ module Wovnrb
|
|
7
7
|
DOC_FILES = 'zip|tar|ez|aw|atom(cat|svc)?|(cc)?xa?ml|cdmi(a|c|d|o|q)?|epub|g(ml|px|xf)|jar|js|ser|class|json(ml)?|do(c|t)m?|xps|pp(a|tx?|s)m?|potm?|sldm|mp(p|t)|bin|dms|lrf|mar|so|dist|distz|m?pkg|bpk|dump|rtf|tfi|pdf|pgp|apk|o(t|d)(b|c|ft?|g|h|i|p|s|t)'
|
8
8
|
end
|
9
9
|
|
10
|
-
def initialize(pattern, headers)
|
10
|
+
def initialize(store, pattern, headers)
|
11
|
+
super(store)
|
11
12
|
@pattern = pattern
|
12
13
|
@headers = headers
|
13
14
|
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module Wovnrb
|
2
2
|
class ReplacerBase
|
3
|
+
def initialize(store)
|
4
|
+
@store = store
|
5
|
+
end
|
6
|
+
|
3
7
|
def replace(dom, lang)
|
4
8
|
raise NotImplementedError.new('replace is not defined')
|
5
9
|
end
|
@@ -11,6 +15,17 @@ module Wovnrb
|
|
11
15
|
elsif node.name === 'html'
|
12
16
|
return false
|
13
17
|
end
|
18
|
+
|
19
|
+
node_class = node.get_attribute('class')
|
20
|
+
if node_class
|
21
|
+
classes = node_class.split
|
22
|
+
@store.settings['ignore_class'].each do |ignore_class|
|
23
|
+
if classes.include?(ignore_class)
|
24
|
+
return true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
14
29
|
wovn_ignore?(node.parent)
|
15
30
|
end
|
16
31
|
|
data/lib/wovnrb/lang.rb
CHANGED
@@ -209,13 +209,13 @@ module Wovnrb
|
|
209
209
|
# add lang code to anchors href if not default lang
|
210
210
|
if @lang_code != store.settings['default_lang']
|
211
211
|
pattern = store.settings['url_pattern']
|
212
|
-
replacers << LinkReplacer.new(pattern, headers)
|
212
|
+
replacers << LinkReplacer.new(store, pattern, headers)
|
213
213
|
end
|
214
214
|
|
215
|
-
replacers << TextReplacer.new(text_index)
|
216
|
-
replacers << MetaReplacer.new(text_index, pattern, headers)
|
217
|
-
replacers << InputReplacer.new(text_index)
|
218
|
-
replacers << ImageReplacer.new(url, text_index, src_index, img_src_prefix, host_aliases)
|
215
|
+
replacers << TextReplacer.new(store, text_index)
|
216
|
+
replacers << MetaReplacer.new(store, text_index, pattern, headers)
|
217
|
+
replacers << InputReplacer.new(store, text_index)
|
218
|
+
replacers << ImageReplacer.new(store, url, text_index, src_index, img_src_prefix, host_aliases)
|
219
219
|
replacers << ScriptReplacer.new(store)
|
220
220
|
|
221
221
|
replacers.each do |replacer|
|
data/lib/wovnrb/store.rb
CHANGED
@@ -20,6 +20,7 @@ module Wovnrb
|
|
20
20
|
'url_pattern' => 'path',
|
21
21
|
'url_pattern_reg' => "/(?<lang>[^/.?]+)",
|
22
22
|
'query' => [],
|
23
|
+
'ignore_class' => [],
|
23
24
|
'api_url' => 'https://api.wovn.io/v0/values',
|
24
25
|
'api_timeout_seconds' => 0.5,
|
25
26
|
'default_lang' => 'en',
|
@@ -79,6 +80,10 @@ module Wovnrb
|
|
79
80
|
valid = false
|
80
81
|
errors.push("query config #{settings['query']} is not valid.")
|
81
82
|
end
|
83
|
+
if !settings.has_key?('ignore_class') || !settings['ignore_class'].kind_of?(Array)
|
84
|
+
valid = false
|
85
|
+
errors.push("ignore_class config #{settings['ignore_class']} should be Array.")
|
86
|
+
end
|
82
87
|
if !settings.has_key?('api_url') || settings['api_url'].length == 0
|
83
88
|
valid = false
|
84
89
|
errors.push("API URL is not configured.")
|
data/lib/wovnrb/version.rb
CHANGED
@@ -5,6 +5,7 @@ require 'webmock/minitest'
|
|
5
5
|
module Wovnrb
|
6
6
|
class ImageReplacerTest < WovnMiniTest
|
7
7
|
def test_replace
|
8
|
+
store = Store.instance
|
8
9
|
url = {
|
9
10
|
:protocol => 'http',
|
10
11
|
:host => 'www.example.com',
|
@@ -17,7 +18,7 @@ module Wovnrb
|
|
17
18
|
'http://www.example.com/test.img' => {'ja' => [{'data' => 'http://test.com/ttt.img'}]}
|
18
19
|
}
|
19
20
|
img_src_prefix = 'prefix::'
|
20
|
-
replacer = ImageReplacer.new(url, text_index, src_index, img_src_prefix, [])
|
21
|
+
replacer = ImageReplacer.new(store, url, text_index, src_index, img_src_prefix, [])
|
21
22
|
|
22
23
|
dom = Wovnrb.get_dom('<img src="http://www.example.com/test.img" alt="Hello"')
|
23
24
|
replacer.replace(dom, Lang.new('ja'))
|
@@ -29,6 +30,7 @@ module Wovnrb
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def test_replace_relative_path
|
33
|
+
store = Store.instance
|
32
34
|
url = {
|
33
35
|
:protocol => 'http',
|
34
36
|
:host => 'www.example.com',
|
@@ -38,7 +40,7 @@ module Wovnrb
|
|
38
40
|
src_index = {
|
39
41
|
'http://www.example.com/hello/test.img' => {'ja' => [{'data' => 'http://test.com/ttt.img'}]}
|
40
42
|
}
|
41
|
-
replacer = ImageReplacer.new(url, text_index, src_index, '', [])
|
43
|
+
replacer = ImageReplacer.new(store, url, text_index, src_index, '', [])
|
42
44
|
|
43
45
|
dom = Wovnrb.get_dom('<img src="test.img"')
|
44
46
|
replacer.replace(dom, Lang.new('ja'))
|
@@ -49,6 +51,7 @@ module Wovnrb
|
|
49
51
|
end
|
50
52
|
|
51
53
|
def test_replace_root_path
|
54
|
+
store = Store.instance
|
52
55
|
url = {
|
53
56
|
:protocol => 'http',
|
54
57
|
:host => 'www.example.com',
|
@@ -58,7 +61,7 @@ module Wovnrb
|
|
58
61
|
src_index = {
|
59
62
|
'http://www.example.com/test.img' => {'ja' => [{'data' => 'http://test.com/ttt.img'}]}
|
60
63
|
}
|
61
|
-
replacer = ImageReplacer.new(url, text_index, src_index, '', [])
|
64
|
+
replacer = ImageReplacer.new(store, url, text_index, src_index, '', [])
|
62
65
|
|
63
66
|
dom = Wovnrb.get_dom('<img src="/test.img"')
|
64
67
|
replacer.replace(dom, Lang.new('ja'))
|
@@ -82,6 +85,7 @@ module Wovnrb
|
|
82
85
|
|
83
86
|
private
|
84
87
|
def img_test_helper path
|
88
|
+
store = Store.instance
|
85
89
|
url = {
|
86
90
|
protocol: 'http',
|
87
91
|
host: 'www.example.com',
|
@@ -91,13 +95,14 @@ module Wovnrb
|
|
91
95
|
src_index = {
|
92
96
|
'http://www.test.com/test.img' => {'ja' => [{'data' => 'http://test.com/ttt.img'}]}
|
93
97
|
}
|
94
|
-
replacer = ImageReplacer.new(url, text_index, src_index, '', [])
|
98
|
+
replacer = ImageReplacer.new(store, url, text_index, src_index, '', [])
|
95
99
|
dom = Wovnrb.get_dom('<img src="http://www.test.com/test.img"')
|
96
100
|
replacer.replace(dom, Lang.new('ja'))
|
97
101
|
dom.xpath('//img')[0]
|
98
102
|
end
|
99
103
|
|
100
104
|
def test_replace_host_alias
|
105
|
+
store = Store.instance
|
101
106
|
url = {
|
102
107
|
:protocol => 'http',
|
103
108
|
:host => 'www.example.com',
|
@@ -109,24 +114,24 @@ module Wovnrb
|
|
109
114
|
path = '/test.img'
|
110
115
|
|
111
116
|
# no replace image if not exist host alias
|
112
|
-
img = img_dom_helper(url, src_index, path, [])
|
117
|
+
img = img_dom_helper(store, url, src_index, path, [])
|
113
118
|
assert_equal('/test.img', img.get_attribute('src'))
|
114
|
-
img = img_dom_helper(url, src_index, path, ['www.test.com'])
|
119
|
+
img = img_dom_helper(store, url, src_index, path, ['www.test.com'])
|
115
120
|
assert_equal('/test.img', img.get_attribute('src'))
|
116
|
-
img = img_dom_helper(url, src_index, path, ['www.example.com'])
|
121
|
+
img = img_dom_helper(store, url, src_index, path, ['www.example.com'])
|
117
122
|
assert_equal('/test.img', img.get_attribute('src'))
|
118
|
-
img = img_dom_helper(url, src_index, path, ['www.test.com', 'www.wrong.com'])
|
123
|
+
img = img_dom_helper(store, url, src_index, path, ['www.test.com', 'www.wrong.com'])
|
119
124
|
assert_equal('/test.img', img.get_attribute('src'))
|
120
125
|
|
121
126
|
# replace image if exist host alias
|
122
|
-
img = img_dom_helper(url, src_index, path, ['www.test.com', 'www.example.com'])
|
127
|
+
img = img_dom_helper(store, url, src_index, path, ['www.test.com', 'www.example.com'])
|
123
128
|
assert_equal('http://test.com/ttt.img', img.get_attribute('src'))
|
124
129
|
end
|
125
130
|
|
126
131
|
private
|
127
|
-
def img_dom_helper(url, src_index, path, host_aliases)
|
132
|
+
def img_dom_helper(store, url, src_index, path, host_aliases)
|
128
133
|
text_index = {}
|
129
|
-
replacer = ImageReplacer.new(url, text_index, src_index, '', host_aliases)
|
134
|
+
replacer = ImageReplacer.new(store, url, text_index, src_index, '', host_aliases)
|
130
135
|
dom = Wovnrb.get_dom('<img src="' + path + '"')
|
131
136
|
replacer.replace(dom, Lang.new('ja'))
|
132
137
|
dom.xpath('//img')[0]
|
@@ -5,7 +5,8 @@ require 'webmock/minitest'
|
|
5
5
|
module Wovnrb
|
6
6
|
class InputReplacerTest < WovnMiniTest
|
7
7
|
def test_replace_submit_value
|
8
|
-
|
8
|
+
store = Store.instance
|
9
|
+
replacer = InputReplacer.new(store, {
|
9
10
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
|
10
11
|
})
|
11
12
|
|
@@ -17,7 +18,8 @@ module Wovnrb
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def test_dont_replace_empty_submit_value
|
20
|
-
|
21
|
+
store = Store.instance
|
22
|
+
replacer = InputReplacer.new(store, {
|
21
23
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
|
22
24
|
})
|
23
25
|
|
@@ -29,7 +31,8 @@ module Wovnrb
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def test_dont_replace_type_text_value
|
32
|
-
|
34
|
+
store = Store.instance
|
35
|
+
replacer = InputReplacer.new(store, {
|
33
36
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
|
34
37
|
})
|
35
38
|
|
@@ -41,7 +44,8 @@ module Wovnrb
|
|
41
44
|
end
|
42
45
|
|
43
46
|
def test_dont_replace_type_search_value
|
44
|
-
|
47
|
+
store = Store.instance
|
48
|
+
replacer = InputReplacer.new(store, {
|
45
49
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
|
46
50
|
})
|
47
51
|
|
@@ -53,7 +57,8 @@ module Wovnrb
|
|
53
57
|
end
|
54
58
|
|
55
59
|
def test_dont_replace_type_hidden_value
|
56
|
-
|
60
|
+
store = Store.instance
|
61
|
+
replacer = InputReplacer.new(store, {
|
57
62
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
|
58
63
|
})
|
59
64
|
|
@@ -65,7 +70,8 @@ module Wovnrb
|
|
65
70
|
end
|
66
71
|
|
67
72
|
def test_dont_replace_type_password_value
|
68
|
-
|
73
|
+
store = Store.instance
|
74
|
+
replacer = InputReplacer.new(store, {
|
69
75
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
|
70
76
|
})
|
71
77
|
|
@@ -77,7 +83,8 @@ module Wovnrb
|
|
77
83
|
end
|
78
84
|
|
79
85
|
def test_replace_type_password_placeholder
|
80
|
-
|
86
|
+
store = Store.instance
|
87
|
+
replacer = InputReplacer.new(store, {
|
81
88
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]},
|
82
89
|
'Hi' => {'ja' => [{'data' => 'やぁ'}]},
|
83
90
|
})
|
@@ -92,7 +99,8 @@ module Wovnrb
|
|
92
99
|
end
|
93
100
|
|
94
101
|
def test_dont_replace_type_url_value
|
95
|
-
|
102
|
+
store = Store.instance
|
103
|
+
replacer = InputReplacer.new(store, {
|
96
104
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
|
97
105
|
})
|
98
106
|
|
@@ -104,7 +112,8 @@ module Wovnrb
|
|
104
112
|
end
|
105
113
|
|
106
114
|
def test_dont_replace_no_type_value
|
107
|
-
|
115
|
+
store = Store.instance
|
116
|
+
replacer = InputReplacer.new(store, {
|
108
117
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
|
109
118
|
})
|
110
119
|
|
@@ -4,7 +4,8 @@ require 'webmock/minitest'
|
|
4
4
|
module Wovnrb
|
5
5
|
class ReplacerBaseTest < WovnMiniTest
|
6
6
|
def test_replace
|
7
|
-
|
7
|
+
store = Store.instance
|
8
|
+
replacer = LinkReplacer.new(store, 'query', get_header)
|
8
9
|
dom = Wovnrb.get_dom('<a href="/index.html">link text</a>')
|
9
10
|
replacer.replace(dom, Lang.new('en'))
|
10
11
|
|
@@ -13,7 +14,8 @@ module Wovnrb
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def test_replace_multiple
|
16
|
-
|
17
|
+
store = Store.instance
|
18
|
+
replacer = LinkReplacer.new(store, 'query', get_header)
|
17
19
|
dom = Wovnrb.get_dom('<a href="/index.html">link text</a><div>aaa</div><a href="/index2.html">link text</a>')
|
18
20
|
replacer.replace(dom, Lang.new('en'))
|
19
21
|
|
@@ -25,7 +27,8 @@ module Wovnrb
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def test_replace_ignore
|
28
|
-
|
30
|
+
store = Store.instance
|
31
|
+
replacer = LinkReplacer.new(store, 'query', get_header)
|
29
32
|
dom = Wovnrb.get_dom('<a wovn-ignore href="/index.html">link text</a>')
|
30
33
|
replacer.replace(dom, Lang.new('en'))
|
31
34
|
|
@@ -34,7 +37,8 @@ module Wovnrb
|
|
34
37
|
end
|
35
38
|
|
36
39
|
def test_replace_empty_javascript_link_query
|
37
|
-
|
40
|
+
store = Store.instance
|
41
|
+
replacer = LinkReplacer.new(store, 'query', get_header)
|
38
42
|
dom = Wovnrb.get_dom('<a href="javascript:void(0);">link text</a>')
|
39
43
|
replacer.replace(dom, Lang.new('en'))
|
40
44
|
|
@@ -43,7 +47,8 @@ module Wovnrb
|
|
43
47
|
end
|
44
48
|
|
45
49
|
def test_replace_javascript_code_link_query
|
46
|
-
|
50
|
+
store = Store.instance
|
51
|
+
replacer = LinkReplacer.new(store, 'query', get_header)
|
47
52
|
dom = Wovnrb.get_dom('<a href="javascript:onclick($(\'.any\').slideToggle());">link text</a>')
|
48
53
|
replacer.replace(dom, Lang.new('en'))
|
49
54
|
|
@@ -52,7 +57,8 @@ module Wovnrb
|
|
52
57
|
end
|
53
58
|
|
54
59
|
def test_replace_uppercased_javascript_code_link_query
|
55
|
-
|
60
|
+
store = Store.instance
|
61
|
+
replacer = LinkReplacer.new(store, 'query', get_header)
|
56
62
|
dom = Wovnrb.get_dom('<a href="JAVASCRIPT:onclick($(\'.any\').slideToggle());">link text</a>')
|
57
63
|
replacer.replace(dom, Lang.new('en'))
|
58
64
|
|
@@ -61,7 +67,8 @@ module Wovnrb
|
|
61
67
|
end
|
62
68
|
|
63
69
|
def test_replace_empty_javascript_link_path
|
64
|
-
|
70
|
+
store = Store.instance
|
71
|
+
replacer = LinkReplacer.new(store, 'path', get_header)
|
65
72
|
dom = Wovnrb.get_dom('<a href="javascript:void(0);">link text</a>')
|
66
73
|
replacer.replace(dom, Lang.new('en'))
|
67
74
|
|
@@ -70,7 +77,8 @@ module Wovnrb
|
|
70
77
|
end
|
71
78
|
|
72
79
|
def test_replace_javascript_code_link_path
|
73
|
-
|
80
|
+
store = Store.instance
|
81
|
+
replacer = LinkReplacer.new(store, 'path', get_header)
|
74
82
|
dom = Wovnrb.get_dom('<a href="javascript:onclick($(\'.any\').slideToggle());">link text</a>')
|
75
83
|
replacer.replace(dom, Lang.new('en'))
|
76
84
|
|
@@ -79,7 +87,8 @@ module Wovnrb
|
|
79
87
|
end
|
80
88
|
|
81
89
|
def test_replace_uppercased_javascript_code_link_path
|
82
|
-
|
90
|
+
store = Store.instance
|
91
|
+
replacer = LinkReplacer.new(store, 'path', get_header)
|
83
92
|
dom = Wovnrb.get_dom('<a href="JAVASCRIPT:onclick($(\'.any\').slideToggle());">link text</a>')
|
84
93
|
replacer.replace(dom, Lang.new('en'))
|
85
94
|
|
@@ -88,7 +97,8 @@ module Wovnrb
|
|
88
97
|
end
|
89
98
|
|
90
99
|
def test_replace_link_path
|
91
|
-
|
100
|
+
store = Store.instance
|
101
|
+
replacer = LinkReplacer.new(store, 'path', get_header)
|
92
102
|
dom = Wovnrb.get_dom('<a href="/index.html">link text</a>')
|
93
103
|
replacer.replace(dom, Lang.new('en'))
|
94
104
|
|
@@ -97,7 +107,8 @@ module Wovnrb
|
|
97
107
|
end
|
98
108
|
|
99
109
|
def test_replace_img_link_path
|
100
|
-
|
110
|
+
store = Store.instance
|
111
|
+
replacer = LinkReplacer.new(store, 'path', get_header)
|
101
112
|
dom = Wovnrb.get_dom('<a href="http://favy.tips/index.jpg">link text</a>')
|
102
113
|
replacer.replace(dom, Lang.new('ja'))
|
103
114
|
|
@@ -106,7 +117,8 @@ module Wovnrb
|
|
106
117
|
end
|
107
118
|
|
108
119
|
def test_replace_img_link_path_with_query_or_hash
|
109
|
-
|
120
|
+
store = Store.instance
|
121
|
+
replacer = LinkReplacer.new(store, 'path', get_header)
|
110
122
|
dom = Wovnrb.get_dom('<a href="http://favy.tips/index.jpg?test=1">link text</a>')
|
111
123
|
replacer.replace(dom, Lang.new('ja'))
|
112
124
|
|
@@ -121,7 +133,8 @@ module Wovnrb
|
|
121
133
|
end
|
122
134
|
|
123
135
|
def test_replace_audio_link_path
|
124
|
-
|
136
|
+
store = Store.instance
|
137
|
+
replacer = LinkReplacer.new(store, 'path', get_header)
|
125
138
|
dom = Wovnrb.get_dom('<a href="/index.mp3">link text</a>')
|
126
139
|
replacer.replace(dom, Lang.new('ja'))
|
127
140
|
|
@@ -130,7 +143,8 @@ module Wovnrb
|
|
130
143
|
end
|
131
144
|
|
132
145
|
def test_replace_audio_link_path_with_query_or_hash
|
133
|
-
|
146
|
+
store = Store.instance
|
147
|
+
replacer = LinkReplacer.new(store, 'path', get_header)
|
134
148
|
dom = Wovnrb.get_dom('<a href="/index.mp3?test=1">link text</a>')
|
135
149
|
replacer.replace(dom, Lang.new('ja'))
|
136
150
|
|
@@ -145,7 +159,8 @@ module Wovnrb
|
|
145
159
|
end
|
146
160
|
|
147
161
|
def test_replace_video_link_path
|
148
|
-
|
162
|
+
store = Store.instance
|
163
|
+
replacer = LinkReplacer.new(store, 'path', get_header)
|
149
164
|
dom = Wovnrb.get_dom('<a href="/index.mpeg">link text</a>')
|
150
165
|
replacer.replace(dom, Lang.new('ja'))
|
151
166
|
|
@@ -154,7 +169,8 @@ module Wovnrb
|
|
154
169
|
end
|
155
170
|
|
156
171
|
def test_replace_video_link_path_with_query_or_hash
|
157
|
-
|
172
|
+
store = Store.instance
|
173
|
+
replacer = LinkReplacer.new(store, 'path', get_header)
|
158
174
|
dom = Wovnrb.get_dom('<a href="/index.mp4?test=1">link text</a>')
|
159
175
|
replacer.replace(dom, Lang.new('ja'))
|
160
176
|
|
@@ -169,7 +185,8 @@ module Wovnrb
|
|
169
185
|
end
|
170
186
|
|
171
187
|
def test_replace_doc_link_path
|
172
|
-
|
188
|
+
store = Store.instance
|
189
|
+
replacer = LinkReplacer.new(store, 'path', get_header)
|
173
190
|
dom = Wovnrb.get_dom('<a href="/index.pptx">link text</a>')
|
174
191
|
replacer.replace(dom, Lang.new('ja'))
|
175
192
|
|
@@ -178,7 +195,8 @@ module Wovnrb
|
|
178
195
|
end
|
179
196
|
|
180
197
|
def test_replace_doc_link_path_with_query_or_hash
|
181
|
-
|
198
|
+
store = Store.instance
|
199
|
+
replacer = LinkReplacer.new(store, 'path', get_header)
|
182
200
|
dom = Wovnrb.get_dom('<a href="/index.pptx?test=1">link text</a>')
|
183
201
|
replacer.replace(dom, Lang.new('ja'))
|
184
202
|
|
@@ -193,7 +211,8 @@ module Wovnrb
|
|
193
211
|
end
|
194
212
|
|
195
213
|
def test_replace_javascript_link_subdomain
|
196
|
-
|
214
|
+
store = Store.instance
|
215
|
+
replacer = LinkReplacer.new(store, 'subdomain', get_header)
|
197
216
|
dom = Wovnrb.get_dom('<a href="javascript:void(0);">link text</a>')
|
198
217
|
replacer.replace(dom, Lang.new('en'))
|
199
218
|
|
@@ -202,7 +221,8 @@ module Wovnrb
|
|
202
221
|
end
|
203
222
|
|
204
223
|
def test_replace_mustache
|
205
|
-
|
224
|
+
store = Store.instance
|
225
|
+
replacer = LinkReplacer.new(store, 'query', get_header)
|
206
226
|
dom = Wovnrb.get_dom('<a href="{{hello}}">link text</a>')
|
207
227
|
replacer.replace(dom, Lang.new('en'))
|
208
228
|
|
@@ -5,7 +5,8 @@ require 'webmock/minitest'
|
|
5
5
|
module Wovnrb
|
6
6
|
class MetaReplacerTest < WovnMiniTest
|
7
7
|
def test_replace_description
|
8
|
-
|
8
|
+
store = Store.instance
|
9
|
+
replacer = MetaReplacer.new(store, {
|
9
10
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
|
10
11
|
})
|
11
12
|
|
@@ -17,7 +18,8 @@ module Wovnrb
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def test_replace_og_description
|
20
|
-
|
21
|
+
store = Store.instance
|
22
|
+
replacer = MetaReplacer.new(store, {
|
21
23
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
|
22
24
|
})
|
23
25
|
|
@@ -29,7 +31,8 @@ module Wovnrb
|
|
29
31
|
end
|
30
32
|
|
31
33
|
def test_replace_og_title
|
32
|
-
|
34
|
+
store = Store.instance
|
35
|
+
replacer = MetaReplacer.new(store, {
|
33
36
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
|
34
37
|
})
|
35
38
|
|
@@ -41,7 +44,8 @@ module Wovnrb
|
|
41
44
|
end
|
42
45
|
|
43
46
|
def test_replace_twitter_title
|
44
|
-
|
47
|
+
store = Store.instance
|
48
|
+
replacer = MetaReplacer.new(store, {
|
45
49
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
|
46
50
|
})
|
47
51
|
|
@@ -53,7 +57,8 @@ module Wovnrb
|
|
53
57
|
end
|
54
58
|
|
55
59
|
def test_replace_twitter_description
|
56
|
-
|
60
|
+
store = Store.instance
|
61
|
+
replacer = MetaReplacer.new(store, {
|
57
62
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
|
58
63
|
})
|
59
64
|
|
@@ -65,7 +70,8 @@ module Wovnrb
|
|
65
70
|
end
|
66
71
|
|
67
72
|
def test_replace_multi
|
68
|
-
|
73
|
+
store = Store.instance
|
74
|
+
replacer = MetaReplacer.new(store, {
|
69
75
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]},
|
70
76
|
'Bye' => {'ja' => [{'data' => 'さようなら'}]}
|
71
77
|
})
|
@@ -80,7 +86,8 @@ module Wovnrb
|
|
80
86
|
end
|
81
87
|
|
82
88
|
def test_replace_wovn_ignore
|
83
|
-
|
89
|
+
store = Store.instance
|
90
|
+
replacer = MetaReplacer.new(store, {
|
84
91
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]},
|
85
92
|
})
|
86
93
|
|
@@ -91,9 +98,10 @@ module Wovnrb
|
|
91
98
|
assert_equal('Hello', content)
|
92
99
|
end
|
93
100
|
|
94
|
-
def
|
101
|
+
def test_replace_wovn_ignore_og
|
102
|
+
store = Store.instance
|
95
103
|
headers = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'https://test.com'), Wovnrb.get_settings)
|
96
|
-
replacer = MetaReplacer.new({
|
104
|
+
replacer = MetaReplacer.new(store, {
|
97
105
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]},
|
98
106
|
}, 'path', headers)
|
99
107
|
|
@@ -5,7 +5,8 @@ require 'webmock/minitest'
|
|
5
5
|
module Wovnrb
|
6
6
|
class ReplacerBaseTest < WovnMiniTest
|
7
7
|
def test_wovn_ignore
|
8
|
-
|
8
|
+
store = Store.instance
|
9
|
+
replacer = ReplacerBase.new(store)
|
9
10
|
dom = Wovnrb.to_dom('<html><body><div wovn-ignore></div></body></html>')
|
10
11
|
actual = replacer.send(:wovn_ignore?, dom.xpath('//div')[0])
|
11
12
|
|
@@ -13,7 +14,8 @@ module Wovnrb
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def test_wovn_ignore_parent
|
16
|
-
|
17
|
+
store = Store.instance
|
18
|
+
replacer = ReplacerBase.new(store)
|
17
19
|
dom = Wovnrb.to_dom('<html wovn-ignore><body><div wovn-ignore></div></body></html>')
|
18
20
|
actual = replacer.send(:wovn_ignore?, dom.xpath('//div')[0])
|
19
21
|
|
@@ -21,33 +23,67 @@ module Wovnrb
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def test_wovn_ignore_without_attribute
|
24
|
-
|
26
|
+
store = Store.instance
|
27
|
+
replacer = ReplacerBase.new(store)
|
25
28
|
dom = Wovnrb.to_dom('<html><body><div></div></body></html>')
|
26
29
|
actual = replacer.send(:wovn_ignore?, dom.xpath('//div')[0])
|
27
30
|
|
28
31
|
assert_equal(false, actual)
|
29
32
|
end
|
30
33
|
|
34
|
+
def test_wovn_ignore_class
|
35
|
+
store = Store.instance
|
36
|
+
store.settings('ignore_class' => ['base_ignore'])
|
37
|
+
replacer = ReplacerBase.new(store)
|
38
|
+
dom = Wovnrb.to_dom('<html><body><div class="base_ignore"></div></body></html>')
|
39
|
+
actual = replacer.send(:wovn_ignore?, dom.xpath('//div')[0])
|
40
|
+
|
41
|
+
assert(actual)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_wovn_ignore_multiple_classes
|
45
|
+
store = Store.instance
|
46
|
+
store.settings('ignore_class' => ['base_ignore', 'base_ignore2'])
|
47
|
+
replacer = ReplacerBase.new(store)
|
48
|
+
html = <<HTML
|
49
|
+
<html>
|
50
|
+
<body>
|
51
|
+
<div class="base_ignore"></div>
|
52
|
+
<span class="base_ignore2"></span>
|
53
|
+
<p class="base_ignore_liar"></p>
|
54
|
+
</body>
|
55
|
+
</html>
|
56
|
+
HTML
|
57
|
+
dom = Wovnrb.to_dom(html)
|
58
|
+
assert(replacer.send(:wovn_ignore?, dom.xpath('//div')[0]))
|
59
|
+
assert(replacer.send(:wovn_ignore?, dom.xpath('//span')[0]))
|
60
|
+
assert_equal(false, replacer.send(:wovn_ignore?, dom.xpath('//p')[0]))
|
61
|
+
end
|
62
|
+
|
31
63
|
def test_replace_text
|
32
|
-
|
64
|
+
store = Store.instance
|
65
|
+
replacer = ReplacerBase.new(store)
|
33
66
|
actual = replacer.send(:replace_text, 'Hello', 'こんにちは')
|
34
67
|
assert_equal('こんにちは', actual)
|
35
68
|
end
|
36
69
|
|
37
70
|
def test_replace_text_with_space
|
38
|
-
|
71
|
+
store = Store.instance
|
72
|
+
replacer = ReplacerBase.new(store)
|
39
73
|
actual = replacer.send(:replace_text, ' Hello ', 'こんにちは')
|
40
74
|
assert_equal(' こんにちは ', actual)
|
41
75
|
end
|
42
76
|
|
43
77
|
def test_replace_text_with_line_break
|
44
|
-
|
78
|
+
store = Store.instance
|
79
|
+
replacer = ReplacerBase.new(store)
|
45
80
|
actual = replacer.send(:replace_text, " Hello \n Hello ", 'こんにちは')
|
46
81
|
assert_equal(' こんにちは ', actual)
|
47
82
|
end
|
48
83
|
|
49
84
|
def test_add_comment_node
|
50
|
-
|
85
|
+
store = Store.instance
|
86
|
+
replacer = ReplacerBase.new(store)
|
51
87
|
html = Nokogiri::HTML5('<html><body><h1 id="test-node">Test Content</h1></body></html>')
|
52
88
|
h1 = html.xpath("//h1[@id='test-node']")[0]
|
53
89
|
|
@@ -5,7 +5,8 @@ require 'webmock/minitest'
|
|
5
5
|
module Wovnrb
|
6
6
|
class TextReplacerTest < WovnMiniTest
|
7
7
|
def test_replace
|
8
|
-
|
8
|
+
store = Store.instance
|
9
|
+
replacer = TextReplacer.new(store,{
|
9
10
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
|
10
11
|
})
|
11
12
|
|
@@ -18,7 +19,8 @@ module Wovnrb
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def test_replace_multiple
|
21
|
-
|
22
|
+
store = Store.instance
|
23
|
+
replacer = TextReplacer.new(store, {
|
22
24
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]},
|
23
25
|
'Bye' => {'ja' => [{'data' => 'さようなら'}]}
|
24
26
|
})
|
@@ -35,7 +37,8 @@ module Wovnrb
|
|
35
37
|
end
|
36
38
|
|
37
39
|
def test_replace_wovn_ignore
|
38
|
-
|
40
|
+
store = Store.instance
|
41
|
+
replacer = TextReplacer.new(store, {
|
39
42
|
'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
|
40
43
|
})
|
41
44
|
|
data/test/lib/wovnrb_test.rb
CHANGED
@@ -159,7 +159,7 @@ class WovnrbTest < Minitest::Test
|
|
159
159
|
expected_body = "<html>
|
160
160
|
<head>
|
161
161
|
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">
|
162
|
-
<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&langCodeAliases={}&version
|
162
|
+
<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&langCodeAliases={}&version=#{Wovnrb::VERSION}\"> </script>
|
163
163
|
</head>
|
164
164
|
<body>
|
165
165
|
<h1>Mr. Belvedere Fan Club</h1>
|
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: 1.0.
|
4
|
+
version: 1.0.7
|
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: 2018-
|
12
|
+
date: 2018-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogumbo
|
@@ -340,6 +340,7 @@ executables: []
|
|
340
340
|
extensions: []
|
341
341
|
extra_rdoc_files: []
|
342
342
|
files:
|
343
|
+
- ".circleci/config.yml"
|
343
344
|
- ".gitignore"
|
344
345
|
- ".travis.yml"
|
345
346
|
- Gemfile
|
@@ -347,7 +348,6 @@ files:
|
|
347
348
|
- PULL_REQUEST_TEMPLATE
|
348
349
|
- README.md
|
349
350
|
- Rakefile
|
350
|
-
- circle.yml
|
351
351
|
- ext/dom/Makefile
|
352
352
|
- lib/wovnrb.rb
|
353
353
|
- lib/wovnrb/api_data.rb
|
@@ -412,7 +412,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
412
412
|
version: '0'
|
413
413
|
requirements: []
|
414
414
|
rubyforge_project:
|
415
|
-
rubygems_version: 2.
|
415
|
+
rubygems_version: 2.5.2
|
416
416
|
signing_key:
|
417
417
|
specification_version: 4
|
418
418
|
summary: Gem for WOVN.io
|