wovnrb 0.2.12 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3fc52fb60a465751418467b657248cce6527730a
4
- data.tar.gz: de3eccb1b4e2c8382652cf7675cf50971ea7196f
3
+ metadata.gz: b7a5d23716e7d22fccb8f9d0b06fff9dc8294971
4
+ data.tar.gz: 4cc426edd9f14e9d9a279341511624b0de5f0814
5
5
  SHA512:
6
- metadata.gz: 876f71f5dc7db5453ef567389f94bd8ad3d9aa90f918b406dac1f87cb220b48b5782c1a5d2b19a4f5ebc3e3097b11158c5c0f9e1e1b852dc1a512b4618016a42
7
- data.tar.gz: 1ee33b277b6517dfdd6bbb0bcdc00996905a46af903402f5eceff30cf690d28c7ec55bbe45a0b2739e3c4b3767739deef4956ae750eb9a1ed049ecd1174b5686
6
+ metadata.gz: b2a3c450d18e28a21cce41b283bbab25f6ddb47b15cf176fb7338b14d3f4219c39b34d5764a7bb58f16e19eb64ec1a867369f8069f0aeb4e2b498153793a1a41
7
+ data.tar.gz: a890117992550bcd36f389771e6ebff1fbc387e80af682ef6720744825784a07da6106f20a57e209e33e29d1f7f1bd5988f35bb6cb433cbfba351c4024ef7056
@@ -0,0 +1,27 @@
1
+ module Wovnrb
2
+ class InputReplacer < ReplacerBase
3
+ def initialize(text_index)
4
+ @text_index = text_index
5
+ end
6
+
7
+ def replace(dom, lang)
8
+ dom.xpath('//input').select { |node|
9
+ next if wovn_ignore?(node)
10
+ (node.get_attribute('value') &&
11
+ node.get_attribute('value') != '' &&
12
+ node.get_attribute('type') &&
13
+ node.get_attribute('type') != 'text' &&
14
+ node.get_attribute('type') != 'hidden' &&
15
+ node.get_attribute('type') != 'password' &&
16
+ node.get_attribute('type') != 'url' &&
17
+ node.get_attribute('type') != 'search')
18
+ }.each do |node|
19
+ node_value = node.get_attribute('value').strip
20
+ # shouldn't need size check, but for now...
21
+ if @text_index[node_value] && @text_index[node_value][lang.lang_code] && @text_index[node_value][lang.lang_code].size > 0
22
+ node.set_attribute('value', replace_text(node.get_attribute('value'), @text_index[node_value][lang.lang_code][0]['data']))
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
data/lib/wovnrb/lang.rb CHANGED
@@ -20,6 +20,7 @@ module Wovnrb
20
20
  'ja' => {name: '日本語', code: 'ja', en: 'Japanese'},
21
21
  'ko' => {name: '한국어', code: 'ko', en: 'Korean'},
22
22
  'ms' => {name: 'Bahasa Melayu', code: 'ms', en: 'Malay'},
23
+ 'my' => { name: 'ဗမာစာ', code: 'my', en: 'Burmese' },
23
24
  'no' => {name: 'Norsk', code: 'no', en: 'Norwegian'},
24
25
  'pl' => {name: 'Polski', code: 'pl', en: 'Polish'},
25
26
  'pt' => {name: 'Português', code: 'pt', en: 'Portuguese'},
@@ -175,6 +176,7 @@ module Wovnrb
175
176
 
176
177
  replacers << TextReplacer.new(text_index)
177
178
  replacers << MetaReplacer.new(text_index)
179
+ replacers << InputReplacer.new(text_index)
178
180
  replacers << ImageReplacer.new(url, text_index, src_index, img_src_prefix)
179
181
  replacers << ScriptReplacer.new(store)
180
182
 
@@ -1,3 +1,3 @@
1
1
  module Wovnrb
2
- VERSION = "0.2.12"
2
+ VERSION = "0.2.13"
3
3
  end
data/lib/wovnrb.rb CHANGED
@@ -10,6 +10,7 @@ require 'wovnrb/html_replacers/replacer_base'
10
10
  require 'wovnrb/html_replacers/link_replacer'
11
11
  require 'wovnrb/html_replacers/text_replacer'
12
12
  require 'wovnrb/html_replacers/meta_replacer'
13
+ require 'wovnrb/html_replacers/input_replacer'
13
14
  require 'wovnrb/html_replacers/image_replacer'
14
15
  require 'wovnrb/html_replacers/script_replacer'
15
16
  require 'wovnrb/railtie' if defined?(Rails)
@@ -5917,7 +5917,7 @@ class HeadersTest < Minitest::Test
5917
5917
  h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings)
5918
5918
 
5919
5919
  keys = Wovnrb::Lang::LANG.keys
5920
- assert_equal(28, keys.size)
5920
+ assert_equal(29, keys.size)
5921
5921
 
5922
5922
  for key in keys
5923
5923
  uri_without_scheme = h.remove_lang("wovn.io/#{key}", key)
@@ -5952,7 +5952,7 @@ class HeadersTest < Minitest::Test
5952
5952
  h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings('url_pattern' => 'query'))
5953
5953
 
5954
5954
  keys = Wovnrb::Lang::LANG.keys
5955
- assert_equal(28, keys.size)
5955
+ assert_equal(29, keys.size)
5956
5956
 
5957
5957
  for key in keys
5958
5958
  uri_without_scheme = h.remove_lang("wovn.io/?wovn=#{key}", key)
@@ -5987,7 +5987,7 @@ class HeadersTest < Minitest::Test
5987
5987
  h = Wovnrb::Headers.new(Wovnrb.get_env, Wovnrb.get_settings('url_pattern' => 'subdomain'))
5988
5988
 
5989
5989
  keys = Wovnrb::Lang::LANG.keys
5990
- assert_equal(28, keys.size)
5990
+ assert_equal(29, keys.size)
5991
5991
 
5992
5992
  for key in keys
5993
5993
  uri_without_scheme = h.remove_lang("#{key.downcase}.wovn.io/", key)
@@ -45,7 +45,7 @@ module Wovnrb
45
45
 
46
46
  img = dom.xpath('//img')[0]
47
47
  assert_equal('http://test.com/ttt.img', img.get_attribute('src'))
48
- assert_equal(nil, img.previous)
48
+ assert_nil(img.previous)
49
49
  end
50
50
 
51
51
  def test_replace_root_path
@@ -65,7 +65,7 @@ module Wovnrb
65
65
 
66
66
  img = dom.xpath('//img')[0]
67
67
  assert_equal('http://test.com/ttt.img', img.get_attribute('src'))
68
- assert_equal(nil, img.previous)
68
+ assert_nil(img.previous)
69
69
  end
70
70
 
71
71
  def test_replace_absolute_path
@@ -85,7 +85,7 @@ module Wovnrb
85
85
 
86
86
  img = dom.xpath('//img')[0]
87
87
  assert_equal('http://test.com/ttt.img', img.get_attribute('src'))
88
- assert_equal(nil, img.previous)
88
+ assert_nil(img.previous)
89
89
  end
90
90
  end
91
91
  end
@@ -0,0 +1,103 @@
1
+ # -*- encoding: UTF-8 -*-
2
+ require 'test_helper'
3
+ require 'webmock/minitest'
4
+
5
+ module Wovnrb
6
+ class InputReplacerTest < WovnMiniTest
7
+ def test_replace_submit_value
8
+ replacer = InputReplacer.new({
9
+ 'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
10
+ })
11
+
12
+ dom = Wovnrb.get_dom('<input type="submit" value="Hello">')
13
+ replacer.replace(dom, Lang.new('ja'))
14
+
15
+ content = dom.xpath('//input')[0].get_attribute('value')
16
+ assert_equal('こんにちは', content)
17
+ end
18
+
19
+ def test_dont_replace_empty_submit_value
20
+ replacer = InputReplacer.new({
21
+ 'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
22
+ })
23
+
24
+ dom = Wovnrb.get_dom('<input type="submit" value="">')
25
+ replacer.replace(dom, Lang.new('ja'))
26
+
27
+ content = dom.xpath('//input')[0].get_attribute('value')
28
+ assert_equal('', content)
29
+ end
30
+
31
+ def test_dont_replace_type_text_value
32
+ replacer = InputReplacer.new({
33
+ 'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
34
+ })
35
+
36
+ dom = Wovnrb.get_dom('<input type="text" value="Hello">')
37
+ replacer.replace(dom, Lang.new('ja'))
38
+
39
+ content = dom.xpath('//input')[0].get_attribute('value')
40
+ assert_equal('Hello', content)
41
+ end
42
+
43
+ def test_dont_replace_type_search_value
44
+ replacer = InputReplacer.new({
45
+ 'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
46
+ })
47
+
48
+ dom = Wovnrb.get_dom('<input type="search" value="Hello">')
49
+ replacer.replace(dom, Lang.new('ja'))
50
+
51
+ content = dom.xpath('//input')[0].get_attribute('value')
52
+ assert_equal('Hello', content)
53
+ end
54
+
55
+ def test_dont_replace_type_hidden_value
56
+ replacer = InputReplacer.new({
57
+ 'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
58
+ })
59
+
60
+ dom = Wovnrb.get_dom('<input type="hidden" value="Hello">')
61
+ replacer.replace(dom, Lang.new('ja'))
62
+
63
+ content = dom.xpath('//input')[0].get_attribute('value')
64
+ assert_equal('Hello', content)
65
+ end
66
+
67
+ def test_dont_replace_type_password_value
68
+ replacer = InputReplacer.new({
69
+ 'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
70
+ })
71
+
72
+ dom = Wovnrb.get_dom('<input type="password" value="Hello">')
73
+ replacer.replace(dom, Lang.new('ja'))
74
+
75
+ content = dom.xpath('//input')[0].get_attribute('value')
76
+ assert_equal('Hello', content)
77
+ end
78
+
79
+ def test_dont_replace_type_url_value
80
+ replacer = InputReplacer.new({
81
+ 'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
82
+ })
83
+
84
+ dom = Wovnrb.get_dom('<input type="url" value="Hello">')
85
+ replacer.replace(dom, Lang.new('ja'))
86
+
87
+ content = dom.xpath('//input')[0].get_attribute('value')
88
+ assert_equal('Hello', content)
89
+ end
90
+
91
+ def test_dont_replace_no_type_value
92
+ replacer = InputReplacer.new({
93
+ 'Hello' => {'ja' => [{'data' => 'こんにちは'}]}
94
+ })
95
+
96
+ dom = Wovnrb.get_dom('<input value="Hello">')
97
+ replacer.replace(dom, Lang.new('ja'))
98
+
99
+ content = dom.xpath('//input')[0].get_attribute('value')
100
+ assert_equal('Hello', content)
101
+ end
102
+ end
103
+ end
@@ -44,7 +44,7 @@ module Wovnrb
44
44
 
45
45
  node = dom.xpath('//text()')[0]
46
46
  assert_equal('Hello', node.content)
47
- assert_equal(nil, node.previous)
47
+ assert_nil(node.previous)
48
48
  end
49
49
  end
50
50
  end
@@ -10,7 +10,7 @@ module Wovnrb
10
10
  end
11
11
 
12
12
  def test_langs_length
13
- assert_equal(28, Wovnrb::Lang::LANG.length)
13
+ assert_equal(29, Wovnrb::Lang::LANG.length)
14
14
  end
15
15
 
16
16
  def test_keys_exist
@@ -23,34 +23,35 @@ module Wovnrb
23
23
  end
24
24
 
25
25
  def test_iso_639_1_normalization
26
- assert_equal('ar', Lang::iso_639_1_normalization('ar'));
27
- assert_equal('bg', Lang::iso_639_1_normalization('bg'));
28
- assert_equal('zh-Hans', Lang::iso_639_1_normalization('zh-CHS'));
29
- assert_equal('zh-Hant', Lang::iso_639_1_normalization('zh-CHT'));
30
- assert_equal('da', Lang::iso_639_1_normalization('da'));
31
- assert_equal('nl', Lang::iso_639_1_normalization('nl'));
32
- assert_equal('en', Lang::iso_639_1_normalization('en'));
33
- assert_equal('fi', Lang::iso_639_1_normalization('fi'));
34
- assert_equal('fr', Lang::iso_639_1_normalization('fr'));
35
- assert_equal('de', Lang::iso_639_1_normalization('de'));
36
- assert_equal('el', Lang::iso_639_1_normalization('el'));
37
- assert_equal('he', Lang::iso_639_1_normalization('he'));
38
- assert_equal('id', Lang::iso_639_1_normalization('id'));
39
- assert_equal('it', Lang::iso_639_1_normalization('it'));
40
- assert_equal('ja', Lang::iso_639_1_normalization('ja'));
41
- assert_equal('ko', Lang::iso_639_1_normalization('ko'));
42
- assert_equal('ms', Lang::iso_639_1_normalization('ms'));
43
- assert_equal('no', Lang::iso_639_1_normalization('no'));
44
- assert_equal('pl', Lang::iso_639_1_normalization('pl'));
45
- assert_equal('pt', Lang::iso_639_1_normalization('pt'));
46
- assert_equal('ru', Lang::iso_639_1_normalization('ru'));
47
- assert_equal('es', Lang::iso_639_1_normalization('es'));
48
- assert_equal('sv', Lang::iso_639_1_normalization('sv'));
49
- assert_equal('th', Lang::iso_639_1_normalization('th'));
50
- assert_equal('hi', Lang::iso_639_1_normalization('hi'));
51
- assert_equal('tr', Lang::iso_639_1_normalization('tr'));
52
- assert_equal('uk', Lang::iso_639_1_normalization('uk'));
53
- assert_equal('vi', Lang::iso_639_1_normalization('vi'));
26
+ assert_equal('ar', Lang::iso_639_1_normalization('ar'))
27
+ assert_equal('bg', Lang::iso_639_1_normalization('bg'))
28
+ assert_equal('zh-Hans', Lang::iso_639_1_normalization('zh-CHS'))
29
+ assert_equal('zh-Hant', Lang::iso_639_1_normalization('zh-CHT'))
30
+ assert_equal('da', Lang::iso_639_1_normalization('da'))
31
+ assert_equal('nl', Lang::iso_639_1_normalization('nl'))
32
+ assert_equal('en', Lang::iso_639_1_normalization('en'))
33
+ assert_equal('fi', Lang::iso_639_1_normalization('fi'))
34
+ assert_equal('fr', Lang::iso_639_1_normalization('fr'))
35
+ assert_equal('de', Lang::iso_639_1_normalization('de'))
36
+ assert_equal('el', Lang::iso_639_1_normalization('el'))
37
+ assert_equal('he', Lang::iso_639_1_normalization('he'))
38
+ assert_equal('id', Lang::iso_639_1_normalization('id'))
39
+ assert_equal('it', Lang::iso_639_1_normalization('it'))
40
+ assert_equal('ja', Lang::iso_639_1_normalization('ja'))
41
+ assert_equal('ko', Lang::iso_639_1_normalization('ko'))
42
+ assert_equal('ms', Lang::iso_639_1_normalization('ms'))
43
+ assert_equal('my', Lang::iso_639_1_normalization('my'))
44
+ assert_equal('no', Lang::iso_639_1_normalization('no'))
45
+ assert_equal('pl', Lang::iso_639_1_normalization('pl'))
46
+ assert_equal('pt', Lang::iso_639_1_normalization('pt'))
47
+ assert_equal('ru', Lang::iso_639_1_normalization('ru'))
48
+ assert_equal('es', Lang::iso_639_1_normalization('es'))
49
+ assert_equal('sv', Lang::iso_639_1_normalization('sv'))
50
+ assert_equal('th', Lang::iso_639_1_normalization('th'))
51
+ assert_equal('hi', Lang::iso_639_1_normalization('hi'))
52
+ assert_equal('tr', Lang::iso_639_1_normalization('tr'))
53
+ assert_equal('uk', Lang::iso_639_1_normalization('uk'))
54
+ assert_equal('vi', Lang::iso_639_1_normalization('vi'))
54
55
  end
55
56
 
56
57
  def test_get_code_with_valid_code
@@ -70,15 +71,15 @@ module Wovnrb
70
71
  end
71
72
 
72
73
  def test_get_code_with_invalid_name
73
- assert_equal(nil, Wovnrb::Lang.get_code('WOVN4LYFE'))
74
+ assert_nil(Wovnrb::Lang.get_code('WOVN4LYFE'))
74
75
  end
75
76
 
76
77
  def test_get_code_with_empty_string
77
- assert_equal(nil, Wovnrb::Lang.get_code(''))
78
+ assert_nil(Wovnrb::Lang.get_code(''))
78
79
  end
79
80
 
80
81
  def test_get_code_with_nil
81
- assert_equal(nil, Wovnrb::Lang.get_code(nil))
82
+ assert_nil(Wovnrb::Lang.get_code(nil))
82
83
  end
83
84
 
84
85
  def test_add_lang_code
@@ -204,7 +205,7 @@ module Wovnrb
204
205
  def test_add_lang_code_nil_href
205
206
  lang = Lang.new('en')
206
207
  h = Wovnrb::Headers.new(Wovnrb.get_env('url' => 'http://favy.tips'), Wovnrb.get_settings)
207
- assert_equal(nil, lang.add_lang_code(nil,'path', h))
208
+ assert_nil(lang.add_lang_code(nil,'path', h))
208
209
  end
209
210
  def test_add_lang_code_absolute_different_host
210
211
  lang = Lang.new('fr')
@@ -62,7 +62,7 @@ class MemoryCacheTest < Minitest::Test
62
62
 
63
63
  def test_get_without_cache
64
64
  memory = Wovnrb::MemoryCache.new({})
65
- assert_equal(nil, memory.get('a'))
65
+ assert_nil(memory.get('a'))
66
66
 
67
67
  end
68
68
 
@@ -70,7 +70,7 @@ class MemoryCacheTest < Minitest::Test
70
70
  memory = Wovnrb::MemoryCache.new({})
71
71
  memory.put('a', 'b')
72
72
  Timecop.travel(1.day.since)
73
- assert_equal(nil, memory.get('a'))
73
+ assert_nil(memory.get('a'))
74
74
  end
75
75
 
76
76
  def test_get_with_over_memory
@@ -80,7 +80,7 @@ class MemoryCacheTest < Minitest::Test
80
80
  })
81
81
  memory.put('a', 'c')
82
82
  memory.put('b', 'd')
83
- assert_equal(nil, memory.get('a'))
83
+ assert_nil(memory.get('a'))
84
84
  assert_equal('d', memory.get('b'))
85
85
  end
86
86
 
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.12
4
+ version: 0.2.13
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: 2017-02-23 00:00:00.000000000 Z
12
+ date: 2017-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogumbo
@@ -338,6 +338,7 @@ files:
338
338
  - lib/wovnrb/api_data.rb
339
339
  - lib/wovnrb/headers.rb
340
340
  - lib/wovnrb/html_replacers/image_replacer.rb
341
+ - lib/wovnrb/html_replacers/input_replacer.rb
341
342
  - lib/wovnrb/html_replacers/link_replacer.rb
342
343
  - lib/wovnrb/html_replacers/meta_replacer.rb
343
344
  - lib/wovnrb/html_replacers/replacer_base.rb
@@ -357,6 +358,7 @@ files:
357
358
  - test/lib/api_data_test.rb
358
359
  - test/lib/headers_test.rb
359
360
  - test/lib/html_replacers/image_replacer_test.rb
361
+ - test/lib/html_replacers/input_replacer_test.rb
360
362
  - test/lib/html_replacers/link_replacer_test.rb
361
363
  - test/lib/html_replacers/meta_replacer_test.rb
362
364
  - test/lib/html_replacers/replacer_base_test.rb
@@ -404,6 +406,7 @@ test_files:
404
406
  - test/lib/api_data_test.rb
405
407
  - test/lib/headers_test.rb
406
408
  - test/lib/html_replacers/image_replacer_test.rb
409
+ - test/lib/html_replacers/input_replacer_test.rb
407
410
  - test/lib/html_replacers/link_replacer_test.rb
408
411
  - test/lib/html_replacers/meta_replacer_test.rb
409
412
  - test/lib/html_replacers/replacer_base_test.rb