wovnrb 0.2.10 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wovnrb/html_replacers/image_replacer.rb +1 -0
- data/lib/wovnrb/html_replacers/link_replacer.rb +1 -0
- data/lib/wovnrb/html_replacers/replacer_base.rb +12 -0
- data/lib/wovnrb/html_replacers/text_replacer.rb +1 -0
- data/lib/wovnrb/version.rb +1 -1
- data/test/lib/html_replacers/image_replacer_test.rb +4 -0
- data/test/lib/html_replacers/link_replacer_test.rb +15 -0
- data/test/lib/html_replacers/text_replacer_test.rb +12 -8
- data/test/lib/lang_test.rb +7 -4
- data/test/lib/wovnrb_test.rb +18 -12
- data/wovnrb.gemspec +3 -1
- metadata +34 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1372d56b49f0c1760b2b4bdaf7041f014cb8d59
|
4
|
+
data.tar.gz: 41a174a792c2dd1d43d7efef0fda9be1165fa6eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d3a94f093c7829e0c5c19bf3a68e8e3ba646df5516bb8cd7bc45487b37cd6b52796d8e2c36a4fb46c7501b466b4d6986d60e5f216d382f92a005a0d74f3f6f9
|
7
|
+
data.tar.gz: e73d5a1d9a010a3b438aa6dd77cad5b03565184ccfedc0f95de2baf9713541c179edb658ac534b59e80402167ffae9c26d42b9f187e387b5d8bce286051677fa
|
@@ -35,6 +35,7 @@ module Wovnrb
|
|
35
35
|
if node.get_attribute('alt')
|
36
36
|
alt = node.get_attribute('alt').strip
|
37
37
|
if @text_index[alt] && @text_index[alt][lang.lang_code] && @text_index[alt][lang.lang_code].size > 0
|
38
|
+
add_comment_node(node, alt)
|
38
39
|
node.attribute('alt').value = replace_text(alt, @text_index[alt][lang.lang_code][0]['data'])
|
39
40
|
end
|
40
41
|
end
|
@@ -14,6 +14,18 @@ module Wovnrb
|
|
14
14
|
wovn_ignore?(node.parent)
|
15
15
|
end
|
16
16
|
|
17
|
+
# Add comment-node node to remember original src
|
18
|
+
# <title> may not contain other markup, so add comment-node to node's previous
|
19
|
+
# @see https://www.w3.org/TR/html401/struct/global.html#h-7.4.2
|
20
|
+
def add_comment_node(node, text)
|
21
|
+
comment_node = Nokogiri::XML::Comment.new(node, "wovn-src:#{text}")
|
22
|
+
if node.parent.name == 'title'
|
23
|
+
node.parent.add_previous_sibling(comment_node)
|
24
|
+
else
|
25
|
+
node.add_previous_sibling(comment_node)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
17
29
|
def replace_text(from, to)
|
18
30
|
from.gsub(/\A(\s*)[\S\s]*?(\s*)\Z/, '\1' + to + '\2')
|
19
31
|
end
|
@@ -11,6 +11,7 @@ module Wovnrb
|
|
11
11
|
node_text = node.content.strip
|
12
12
|
# shouldn't need size check, but for now...
|
13
13
|
if @text_index[node_text] && @text_index[node_text][lang.lang_code] && @text_index[node_text][lang.lang_code].size > 0
|
14
|
+
add_comment_node(node, node_text)
|
14
15
|
node.content = replace_text(node.content, @text_index[node_text][lang.lang_code][0]['data'])
|
15
16
|
end
|
16
17
|
end
|
data/lib/wovnrb/version.rb
CHANGED
@@ -25,6 +25,7 @@ module Wovnrb
|
|
25
25
|
img = dom.xpath('//img')[0]
|
26
26
|
assert_equal('prefix::http://test.com/ttt.img', img.get_attribute('src'))
|
27
27
|
assert_equal('こんにちは', img.get_attribute('alt'))
|
28
|
+
assert_equal('wovn-src:Hello', img.previous.content)
|
28
29
|
end
|
29
30
|
|
30
31
|
def test_replace_relative_path
|
@@ -44,6 +45,7 @@ module Wovnrb
|
|
44
45
|
|
45
46
|
img = dom.xpath('//img')[0]
|
46
47
|
assert_equal('http://test.com/ttt.img', img.get_attribute('src'))
|
48
|
+
assert_equal(nil, img.previous)
|
47
49
|
end
|
48
50
|
|
49
51
|
def test_replace_root_path
|
@@ -63,6 +65,7 @@ module Wovnrb
|
|
63
65
|
|
64
66
|
img = dom.xpath('//img')[0]
|
65
67
|
assert_equal('http://test.com/ttt.img', img.get_attribute('src'))
|
68
|
+
assert_equal(nil, img.previous)
|
66
69
|
end
|
67
70
|
|
68
71
|
def test_replace_absolute_path
|
@@ -82,6 +85,7 @@ module Wovnrb
|
|
82
85
|
|
83
86
|
img = dom.xpath('//img')[0]
|
84
87
|
assert_equal('http://test.com/ttt.img', img.get_attribute('src'))
|
88
|
+
assert_equal(nil, img.previous)
|
85
89
|
end
|
86
90
|
end
|
87
91
|
end
|
@@ -33,6 +33,21 @@ module Wovnrb
|
|
33
33
|
assert_equal('/index.html', link)
|
34
34
|
end
|
35
35
|
|
36
|
+
def test_replace_mustache
|
37
|
+
replacer = LinkReplacer.new('query', get_header)
|
38
|
+
dom = Wovnrb.get_dom('<a href="{{hello}}">link text</a>')
|
39
|
+
replacer.replace(dom, Lang.new('en'))
|
40
|
+
|
41
|
+
link = dom.xpath('//a')[0].get_attribute('href')
|
42
|
+
assert_equal('{{hello}}', link)
|
43
|
+
|
44
|
+
dom = Wovnrb.get_dom('<a href=" {{hello}} ">link text</a>')
|
45
|
+
replacer.replace(dom, Lang.new('en'))
|
46
|
+
|
47
|
+
link = dom.xpath('//a')[0].get_attribute('href')
|
48
|
+
assert_equal(' {{hello}} ', link)
|
49
|
+
end
|
50
|
+
|
36
51
|
|
37
52
|
|
38
53
|
def get_header
|
@@ -12,8 +12,9 @@ module Wovnrb
|
|
12
12
|
dom = Wovnrb.get_dom('Hello')
|
13
13
|
replacer.replace(dom, Lang.new('ja'))
|
14
14
|
|
15
|
-
|
16
|
-
assert_equal('こんにちは', content)
|
15
|
+
node = dom.xpath('//text()')[0]
|
16
|
+
assert_equal('こんにちは', node.content)
|
17
|
+
assert_equal('wovn-src:Hello', node.previous.content)
|
17
18
|
end
|
18
19
|
|
19
20
|
def test_replace_multiple
|
@@ -25,10 +26,12 @@ module Wovnrb
|
|
25
26
|
dom = Wovnrb.get_dom('<span>Hello</span><span>Bye</span>')
|
26
27
|
replacer.replace(dom, Lang.new('ja'))
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
assert_equal('こんにちは', content)
|
31
|
-
assert_equal('
|
29
|
+
node = dom.xpath('//text()')[0]
|
30
|
+
node2 = dom.xpath('//text()')[1]
|
31
|
+
assert_equal('こんにちは', node.content)
|
32
|
+
assert_equal('wovn-src:Hello', node.previous.content)
|
33
|
+
assert_equal('さようなら', node2.content)
|
34
|
+
assert_equal('wovn-src:Bye', node2.previous.content)
|
32
35
|
end
|
33
36
|
|
34
37
|
def test_replace_wovn_ignore
|
@@ -39,8 +42,9 @@ module Wovnrb
|
|
39
42
|
dom = Wovnrb.get_dom('<div wovn-ignore>Hello</div>')
|
40
43
|
replacer.replace(dom, Lang.new('ja'))
|
41
44
|
|
42
|
-
|
43
|
-
assert_equal('Hello', content)
|
45
|
+
node = dom.xpath('//text()')[0]
|
46
|
+
assert_equal('Hello', node.content)
|
47
|
+
assert_equal(nil, node.previous)
|
44
48
|
end
|
45
49
|
end
|
46
50
|
end
|
data/test/lib/lang_test.rb
CHANGED
@@ -325,7 +325,8 @@ module Wovnrb
|
|
325
325
|
<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.ignore-page.com/\">
|
326
326
|
</head>
|
327
327
|
<body>
|
328
|
-
<h1
|
328
|
+
<h1>
|
329
|
+
<!--wovn-src:Mr. Belvedere Fan Club-->ベルベデアさんファンクラブ</h1>
|
329
330
|
<div wovn-ignore=\"\"><p>Hello</p></div>
|
330
331
|
</body>
|
331
332
|
</html>
|
@@ -337,8 +338,9 @@ module Wovnrb
|
|
337
338
|
<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\">
|
338
339
|
</head>
|
339
340
|
<body>
|
340
|
-
<h1
|
341
|
-
|
341
|
+
<h1>
|
342
|
+
<!--wovn-src:Mr. Belvedere Fan Club-->ベルベデアさんファンクラブ</h1>
|
343
|
+
<div><p><!--wovn-src:Hello-->こんにちは</p></div>
|
342
344
|
</body>
|
343
345
|
</html>
|
344
346
|
"
|
@@ -375,7 +377,8 @@ module Wovnrb
|
|
375
377
|
when "value_double_quote_translated"
|
376
378
|
body = "<html lang=\"ja\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.ignore-page.com/\">\n</head>\n<body>\n<h1>Mr.BelvedereFanClub</h1>\n<div wovn-ignore=\"value\"><p>Hello</p></div>\n</body>\n</html>\n"
|
377
379
|
when "meta_img_alt_tags_translated"
|
378
|
-
body = "<html lang=\"ja\">\n<head>\n<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=#{Wovnrb::VERSION}\"> </script><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<meta name=\"description\" content=\"こんにちは\">\n<meta name=\"title\" content=\"こんにちは\">\n<meta property=\"og:title\" content=\"こんにちは\">\n<meta property=\"og:description\" content=\"こんにちは\">\n<meta property=\"twitter:title\" content=\"こんにちは\">\n<meta property=\"twitter:description\" content=\"こんにちは\">\n<link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\">\n</head>\n<body>\n<h1
|
380
|
+
body = "<html lang=\"ja\">\n<head>\n<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=#{Wovnrb::VERSION}\"> </script><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n<meta name=\"description\" content=\"こんにちは\">\n<meta name=\"title\" content=\"こんにちは\">\n<meta property=\"og:title\" content=\"こんにちは\">\n<meta property=\"og:description\" content=\"こんにちは\">\n<meta property=\"twitter:title\" content=\"こんにちは\">\n<meta property=\"twitter:description\" content=\"こんにちは\">\n<link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\">\n</head>\n<body>\n<h1>
|
381
|
+
<!--wovn-src:Mr. Belvedere Fan Club-->ベルベデアさんファンクラブ</h1>\n<div><p><!--wovn-src:Hello-->こんにちは</p></div>\n<!--wovn-src:Hello--><img src=\"http://example.com/photo.png\" alt=\"こんにちは\">\n</body>\n</html>\n"
|
379
382
|
when "meta_img_alt_tags"
|
380
383
|
body = "<html><head><meta name =\"description\" content=\"Hello\">\n<meta name=\"title\" content=\"Hello\">\n<meta property=\"og:title\" content=\"Hello\">\n<meta property=\"og:description\" content=\"Hello\">\n<meta property=\"twitter:title\" content=\"Hello\">\n<meta property=\"twitter:description\" content=\"Hello\"></head>
|
381
384
|
<body><h1>Mr. Belvedere Fan Club</h1>
|
data/test/lib/wovnrb_test.rb
CHANGED
@@ -66,8 +66,9 @@ class WovnrbTest < Minitest::Test
|
|
66
66
|
<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=#{Wovnrb::VERSION}\"> </script><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\">
|
67
67
|
</head>
|
68
68
|
<body>
|
69
|
-
<h1
|
70
|
-
|
69
|
+
<h1>
|
70
|
+
<!--wovn-src:Mr. Belvedere Fan Club-->ベルベデアさんファンクラブ</h1>
|
71
|
+
<div><p><!--wovn-src:Hello-->こんにちは</p></div>
|
71
72
|
</body>
|
72
73
|
</html>
|
73
74
|
"
|
@@ -91,8 +92,9 @@ class WovnrbTest < Minitest::Test
|
|
91
92
|
<link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\">
|
92
93
|
</head>
|
93
94
|
<body>
|
94
|
-
<h1
|
95
|
-
|
95
|
+
<h1>
|
96
|
+
<!--wovn-src:Mr. Belvedere Fan Club-->ベルベデアさんファンクラブ</h1>
|
97
|
+
<div><p><!--wovn-src:Hello-->こんにちは</p></div>
|
96
98
|
</body>
|
97
99
|
</html>
|
98
100
|
"
|
@@ -120,8 +122,9 @@ class WovnrbTest < Minitest::Test
|
|
120
122
|
<link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\">
|
121
123
|
</head>
|
122
124
|
<body>
|
123
|
-
<h1
|
124
|
-
|
125
|
+
<h1>
|
126
|
+
<!--wovn-src:Mr. Belvedere Fan Club-->ベルベデアさんファンクラブ</h1>
|
127
|
+
<div><p><!--wovn-src:Hello-->こんにちは</p></div>
|
125
128
|
</body>
|
126
129
|
</html>
|
127
130
|
"
|
@@ -147,8 +150,9 @@ class WovnrbTest < Minitest::Test
|
|
147
150
|
<link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\">
|
148
151
|
</head>
|
149
152
|
<body>
|
150
|
-
<h1
|
151
|
-
|
153
|
+
<h1>
|
154
|
+
<!--wovn-src:Mr. Belvedere Fan Club-->ベルベデアさんファンクラブ</h1>
|
155
|
+
<div><p><!--wovn-src:Hello-->こんにちは</p></div>
|
152
156
|
</body>
|
153
157
|
</html>
|
154
158
|
"
|
@@ -172,8 +176,9 @@ class WovnrbTest < Minitest::Test
|
|
172
176
|
<link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\">
|
173
177
|
</head>
|
174
178
|
<body>
|
175
|
-
<h1
|
176
|
-
|
179
|
+
<h1>
|
180
|
+
<!--wovn-src:Mr. Belvedere Fan Club-->ベルベデアさんファンクラブ</h1>
|
181
|
+
<div><p><!--wovn-src:Hello-->こんにちは</p></div>
|
177
182
|
</body>
|
178
183
|
</html>
|
179
184
|
"
|
@@ -196,8 +201,9 @@ class WovnrbTest < Minitest::Test
|
|
196
201
|
<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&version=#{Wovnrb::VERSION}\"> </script><!--<noscript><div>test</div></noscript>--><link rel=\"alternate\" hreflang=\"ja\" href=\"http://ja.page.com/\">
|
197
202
|
</head>
|
198
203
|
<body>
|
199
|
-
<h1
|
200
|
-
|
204
|
+
<h1>
|
205
|
+
<!--wovn-src:Mr. Belvedere Fan Club-->ベルベデアさんファンクラブ</h1>
|
206
|
+
<div><p><!--wovn-src:Hello-->こんにちは</p></div>
|
201
207
|
</body>
|
202
208
|
</html>
|
203
209
|
"
|
data/wovnrb.gemspec
CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
#spec.extensions = spec.files.grep(%r{/extconf\.rb$})
|
27
27
|
|
28
28
|
spec.add_dependency "nokogumbo", "1.3.0"
|
29
|
+
spec.add_dependency "nokogiri", "< 1.6.8.1"
|
29
30
|
spec.add_dependency "activesupport", "< 5"
|
30
31
|
spec.add_dependency "lz4-ruby"
|
31
32
|
|
@@ -48,7 +49,8 @@ Gem::Specification.new do |spec|
|
|
48
49
|
spec.add_development_dependency "rake-compiler"
|
49
50
|
spec.add_development_dependency "geminabox"
|
50
51
|
spec.add_development_dependency "timecop"
|
51
|
-
spec.add_development_dependency "webmock"
|
52
|
+
spec.add_development_dependency "webmock", '~> 2.1.0'
|
52
53
|
spec.add_development_dependency "simplecov"
|
54
|
+
spec.add_development_dependency "public_suffix", '~> 1.4.6'
|
53
55
|
end
|
54
56
|
|
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.11
|
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:
|
12
|
+
date: 2017-01-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogumbo
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - '='
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 1.3.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: nokogiri
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "<"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.6.8.1
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "<"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.6.8.1
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: activesupport
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -267,16 +281,16 @@ dependencies:
|
|
267
281
|
name: webmock
|
268
282
|
requirement: !ruby/object:Gem::Requirement
|
269
283
|
requirements:
|
270
|
-
- - "
|
284
|
+
- - "~>"
|
271
285
|
- !ruby/object:Gem::Version
|
272
|
-
version:
|
286
|
+
version: 2.1.0
|
273
287
|
type: :development
|
274
288
|
prerelease: false
|
275
289
|
version_requirements: !ruby/object:Gem::Requirement
|
276
290
|
requirements:
|
277
|
-
- - "
|
291
|
+
- - "~>"
|
278
292
|
- !ruby/object:Gem::Version
|
279
|
-
version:
|
293
|
+
version: 2.1.0
|
280
294
|
- !ruby/object:Gem::Dependency
|
281
295
|
name: simplecov
|
282
296
|
requirement: !ruby/object:Gem::Requirement
|
@@ -291,6 +305,20 @@ dependencies:
|
|
291
305
|
- - ">="
|
292
306
|
- !ruby/object:Gem::Version
|
293
307
|
version: '0'
|
308
|
+
- !ruby/object:Gem::Dependency
|
309
|
+
name: public_suffix
|
310
|
+
requirement: !ruby/object:Gem::Requirement
|
311
|
+
requirements:
|
312
|
+
- - "~>"
|
313
|
+
- !ruby/object:Gem::Version
|
314
|
+
version: 1.4.6
|
315
|
+
type: :development
|
316
|
+
prerelease: false
|
317
|
+
version_requirements: !ruby/object:Gem::Requirement
|
318
|
+
requirements:
|
319
|
+
- - "~>"
|
320
|
+
- !ruby/object:Gem::Version
|
321
|
+
version: 1.4.6
|
294
322
|
description: Ruby gem for WOVN backend on Rack.
|
295
323
|
email:
|
296
324
|
- jeff@wovn.io
|