wovnrb 2.2.1 → 2.6.0

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.
@@ -8,11 +8,11 @@ module Wovnrb
8
8
  end
9
9
 
10
10
  def test_add_comment_value_multiple_times
11
- maker = HtmlReplaceMarker.new
12
- assert_equal('<!-- __wovn-backend-ignored-key-0 -->', maker.add_comment_value('hello'))
13
- assert_equal('<!-- __wovn-backend-ignored-key-1 -->', maker.add_comment_value('hello'))
14
- assert_equal('<!-- __wovn-backend-ignored-key-2 -->', maker.add_comment_value('hello'))
15
- assert_equal('<!-- __wovn-backend-ignored-key-3 -->', maker.add_comment_value('hello'))
11
+ marker = HtmlReplaceMarker.new
12
+ assert_equal('<!-- __wovn-backend-ignored-key-0 -->', marker.add_comment_value('hello'))
13
+ assert_equal('<!-- __wovn-backend-ignored-key-1 -->', marker.add_comment_value('hello'))
14
+ assert_equal('<!-- __wovn-backend-ignored-key-2 -->', marker.add_comment_value('hello'))
15
+ assert_equal('<!-- __wovn-backend-ignored-key-3 -->', marker.add_comment_value('hello'))
16
16
  end
17
17
 
18
18
  def test_add_same_comment_value_multiple_times
@@ -23,6 +23,27 @@ module Wovnrb
23
23
  end
24
24
  end
25
25
 
26
+ def test_add_same_value_multiple_times
27
+ marker = HtmlReplaceMarker.new
28
+
29
+ 25.times do |i|
30
+ assert_equal("__wovn-backend-ignored-key-#{i}", marker.add_value('hello'))
31
+ end
32
+ end
33
+
34
+ def test_mixed_add_comment_value_and_add_value
35
+ marker = HtmlReplaceMarker.new
36
+
37
+ assert_equal('<!-- __wovn-backend-ignored-key-0 -->', marker.add_comment_value('hello'))
38
+ assert_equal('__wovn-backend-ignored-key-1', marker.add_value('hello'))
39
+ assert_equal('<!-- __wovn-backend-ignored-key-2 -->', marker.add_comment_value('hello'))
40
+ assert_equal('__wovn-backend-ignored-key-3', marker.add_value('hello'))
41
+ assert_equal('<!-- __wovn-backend-ignored-key-4 -->', marker.add_comment_value('hello'))
42
+ assert_equal('__wovn-backend-ignored-key-5', marker.add_value('hello'))
43
+ assert_equal('<!-- __wovn-backend-ignored-key-6 -->', marker.add_comment_value('hello'))
44
+ assert_equal('__wovn-backend-ignored-key-7', marker.add_value('hello'))
45
+ end
46
+
26
47
  def test_revert
27
48
  marker = HtmlReplaceMarker.new
28
49
  original_html = '<html><body>hello<a> replacement </a>world </body></html>'
@@ -32,6 +53,42 @@ module Wovnrb
32
53
  assert_equal(original_html, marker.revert(new_html))
33
54
  end
34
55
 
56
+ def test_revert_input_value
57
+ marker = HtmlReplaceMarker.new
58
+ original_html = '<html><body><input type="hidden" value="please-revert"></body></html>'
59
+ key = marker.add_value('please-revert')
60
+ new_html = original_html.sub('please-revert', key)
61
+ assert_equal("<html><body><input type=\"hidden\" value=\"#{key}\"></body></html>", new_html)
62
+ assert_equal(original_html, marker.revert(new_html))
63
+ end
64
+
65
+ def test_revert_input_empty_value
66
+ marker = HtmlReplaceMarker.new
67
+ original_html = '<html><body><input type="hidden" value=""></body></html>'
68
+ key = marker.add_value('')
69
+ new_html = original_html.sub('value=""', "value=\"#{key}\"")
70
+ assert_equal("<html><body><input type=\"hidden\" value=\"#{key}\"></body></html>", new_html)
71
+ assert_equal(original_html, marker.revert(new_html))
72
+ end
73
+
74
+ def test_revert_multiple_input
75
+ marker = HtmlReplaceMarker.new
76
+ original_html = [
77
+ '<html><body>',
78
+ '<input type="hidden" value="please_revert1"></body></html>',
79
+ '<input type="hidden" value="please_revert2"></body></html>',
80
+ '<input type="hidden" value=""></body></html>'
81
+ ].join
82
+ new_html = [
83
+ '<html><body>',
84
+ "<input type=\"hidden\" value=\"#{marker.add_value('please_revert1')}\"></body></html>",
85
+ "<input type=\"hidden\" value=\"#{marker.add_value('please_revert2')}\"></body></html>",
86
+ "<input type=\"hidden\" value=\"#{marker.add_value('')}\">",
87
+ '</body></html>'
88
+ ].join
89
+ assert_equal(original_html, marker.revert(new_html))
90
+ end
91
+
35
92
  def test_revert_multiple_values
36
93
  marker = HtmlReplaceMarker.new
37
94
  original_html = '<html><body>hello<a> replacement </a>world </body></html>'
@@ -71,5 +128,24 @@ module Wovnrb
71
128
  new_html = "<html><body>#{key1}<a>#{key2}</a>#{key3}</body></html>"
72
129
  assert_equal(original_html, marker.revert(new_html))
73
130
  end
131
+
132
+ def test_revert_mixed_values
133
+ marker = HtmlReplaceMarker.new
134
+ original_html = [
135
+ '<html><body>',
136
+ '<span>hello</span>',
137
+ '<input type="hidden" value="please_revert">',
138
+ '</body></html>'
139
+ ].join
140
+ key1 = marker.add_comment_value('hello')
141
+ key2 = marker.add_value('please_revert')
142
+ new_html = [
143
+ '<html><body>',
144
+ "<span>#{key1}</span>",
145
+ "<input type=\"hidden\" value=\"#{key2}\">",
146
+ '</body></html>'
147
+ ].join
148
+ assert_equal(original_html, marker.revert(new_html))
149
+ end
74
150
  end
75
151
  end
@@ -132,7 +132,8 @@ module Wovnrb
132
132
  store.update_settings('wovn_dev_mode' => true)
133
133
 
134
134
  assert(store.dev_mode?)
135
- assert_equal('http://dev-wovn.io:3001/v0/', store.settings['api_url'])
135
+ assert_equal('dev-wovn.io', store.wovn_host)
136
+ assert_equal('http://dev-wovn.io:3001', store.settings['api_url'])
136
137
  assert_equal(3, store.settings['api_timeout_seconds'])
137
138
  end
138
139
 
@@ -27,6 +27,34 @@ class WovnrbTest < Minitest::Test
27
27
  assert_switch_lang('en', 'ja', body, expected_body, true)
28
28
  end
29
29
 
30
+ def test_switch_lang_with_input_tags
31
+ body = [
32
+ '<html lang="ja">',
33
+ '<body>',
34
+ '<input type="hidden" value="test1">',
35
+ '<input type="hidden" value="test2">',
36
+ '<input type="hidden" value="">',
37
+ '<input value="test3">',
38
+ '</body></html>'
39
+ ].join
40
+
41
+ expected_body = [
42
+ '<html lang="ja"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">',
43
+ "<script src=\"//j.wovn.io/1\" async=\"true\" data-wovnio=\"key=&backend=true&currentLang=ja&defaultLang=en&urlPattern=path&langCodeAliases={}&version=#{Wovnrb::VERSION}\"> </script>",
44
+ '<link rel="alternate" hreflang="ja" href="http://ja.page.com/">',
45
+ '<link rel="alternate" hreflang="en" href="http://page.com/"></head>',
46
+ '<body>',
47
+ '<input type="hidden" value="test1">',
48
+ '<input type="hidden" value="test2">',
49
+ '<input type="hidden" value="">',
50
+ '<input value="test3">',
51
+ '<p><!--wovn-src:Hello-->こんにちは</p>',
52
+ '</body></html>'
53
+ ].join
54
+
55
+ assert_switch_lang('en', 'ja', body, expected_body, true)
56
+ end
57
+
30
58
  def test_switch_lang_of_html_fragment_with_japanese_translations
31
59
  bodies = ['<span>Hello</span>'].join
32
60
  expected_bodies = ['<span><!--wovn-src:Hello-->こんにちは</span>'].join
data/wovnrb.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency 'activesupport'
23
23
  spec.add_dependency 'addressable'
24
24
  spec.add_dependency 'lz4-ruby'
25
- spec.add_dependency 'nokogiri', '~> 1.8.1'
25
+ spec.add_dependency 'nokogiri', '>= 1.8.1'
26
26
  spec.add_dependency 'nokogumbo', '>= 1.4.0', '< 2.0.0'
27
27
  spec.add_dependency 'rack'
28
28
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wovnrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Sandford
8
8
  - Antoine David
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-10-31 00:00:00.000000000 Z
12
+ date: 2021-04-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -57,14 +57,14 @@ dependencies:
57
57
  name: nokogiri
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - "~>"
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: 1.8.1
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - "~>"
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: 1.8.1
70
70
  - !ruby/object:Gem::Dependency
@@ -410,6 +410,8 @@ files:
410
410
  - Gemfile
411
411
  - LICENSE.txt
412
412
  - PULL_REQUEST_TEMPLATE
413
+ - README.en.md
414
+ - README.ja.md
413
415
  - README.md
414
416
  - Rakefile
415
417
  - lib/wovnrb.rb
@@ -446,7 +448,7 @@ homepage: ''
446
448
  licenses:
447
449
  - MIT
448
450
  metadata: {}
449
- post_install_message:
451
+ post_install_message:
450
452
  rdoc_options: []
451
453
  require_paths:
452
454
  - lib
@@ -461,8 +463,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
461
463
  - !ruby/object:Gem::Version
462
464
  version: '0'
463
465
  requirements: []
464
- rubygems_version: 3.0.3
465
- signing_key:
466
+ rubyforge_project:
467
+ rubygems_version: 2.7.6.2
468
+ signing_key:
466
469
  specification_version: 4
467
470
  summary: Gem for WOVN.io
468
471
  test_files:
data/README.md DELETED
@@ -1,182 +0,0 @@
1
- # WOVN.io Ruby Library
2
-
3
- The WOVN.io Ruby library is a library that uses WOVN.io in order to provide translations. The WOVN.io Ruby Library is packaged as Rack Middleware.
4
-
5
- This document explains the process of installing WOVN.io Ruby, as well as set up and configuration process.
6
-
7
- ## 1. Install
8
-
9
- ### 1.1. Creating a WOVN.io account.
10
-
11
- In order to use the WOVN.io Ruby Library, you need a WOVN.io account. If you do not have an account, please first sign up for one at WOVN.io.
12
-
13
- ### 1.2. Adding a Page
14
-
15
- After logging into WOVN.io, add a page that you would like translated.
16
-
17
- ### 1.3. Ruby Application Settings
18
-
19
- To use the WOVN.io Ruby Library, insert the following line into your Ruby Application's Gemfile. WOVN.io currently supports version 2.0.1 and up.
20
-
21
- ```ruby
22
- gem 'wovnrb', '>= 2.0.1'
23
- ```
24
-
25
- After setting the above, execute the following command to install the WOVN.io Ruby Library.
26
-
27
- ```bash
28
- bundle install
29
- ```
30
-
31
- After installing the library, insert the following into your Ruby Application's settings file.
32
-
33
- * If you're using Ruby on Rails
34
-
35
- Insert the following into either config/application.rb or config/environments/.
36
-
37
- ```ruby
38
- ...
39
-
40
- config.wovnrb = {
41
- :project_token => 'EnS!t3',
42
- :default_lang => 'en',
43
- :supported_langs => ['en'],
44
- :url_pattern => 'path'
45
- }
46
-
47
- ...
48
- ```
49
-
50
- * If you're using Sinatra
51
-
52
- Insert the following into either the Application File or config.ru.
53
-
54
- ```ruby
55
- ...
56
-
57
- require 'wovnrb'
58
-
59
- use Wovnrb::Interceptor, {
60
- :project_token => 'EnS!t3',
61
- :default_lang => 'en',
62
- :supported_langs => ['en'],
63
- :url_pattern => 'path'
64
- }
65
-
66
- ...
67
- ```
68
-
69
- After completing setup, start the Ruby Application, and make sure the WOVN.io library is working correctly.
70
-
71
- ## 2. Parameter Setting
72
-
73
- The following is a list of the WOVN.io Ruby Library's valid parameters.
74
-
75
- Parameter Name | Required | Default Setting
76
- ------------------ | -------- | ----------------
77
- project_token | yes | ''
78
- default_lang | yes | 'en'
79
- supported_langs | yes | ['en']
80
- url_pattern | yes | 'path'
81
- lang_param_name | | 'wovn'
82
- query | | []
83
- ignore_class | | []
84
- translate_fragment | | true
85
- ignore_paths | | []
86
-
87
- ### 2.1. project_token
88
-
89
- Set your WOVN.io Account's Project token. This parameter is required.
90
-
91
- ### 2.2. default_lang
92
-
93
- This sets the Ruby application's default language. The default value is English ('en').
94
-
95
- If, for a requested page, the default language parameter is included in the URL, the request is redirected before translating. The default_lang parameter is used for this purpose.
96
-
97
- If the default_lang is set to 'en', when receiving a request for the following URL,
98
-
99
- https://wovn.io/en/contact
100
-
101
- Then the library will redirect to the following URL.
102
-
103
- https://wovn.io/contact
104
-
105
- ### 2.3. supported_langs
106
- This tells the library which languages are being used on the website (including
107
- the original language). This setting allows for inserting metadata necessary for
108
- SEO (Search Engine Optimization).
109
-
110
- If your website is in English and you are using WOVN.io to localize it in
111
- Japanese, then you should use the following setting:
112
- ```
113
- :supported_langs => ['en', 'ja']
114
- ```
115
- **Note:** The order of the languages in the list does not matter.
116
-
117
- ### 2.4. url_pattern
118
-
119
- The Library works in the Ruby Application by adding new URLs to be translated. You can set the type of url with the `url_pattern` parameter. There are 3 types that can be set.
120
-
121
- parameters | Translated page's URL | Notes
122
- ----------- | ------------------------------- | -------
123
- 'path' | https://wovn.io/ja/contact | Default Value. If no settings have been set, url_pattern defaults to this value.
124
- 'subdomain' | https://ja.wovn.io/contact | DNS settings must be set.
125
- 'query' | https://wovn.io/contact?wovn=ja | The least amount of changes to the application required to complete setup.
126
-
127
- ※ The following is an example of a URL that has been translated by the library using the above URLs.
128
-
129
- https://wovn.io/contact
130
-
131
- ### 2.5 lang_param_name
132
- This parameter is only valid for when `url_pattern_name` is set to `'query'`.
133
-
134
- It allows you to set the query parameter name for declaring the language of the
135
- page. The default value for this setting is `'wovn'`, such that a page URL in
136
- translated language English has the form
137
- `https://my-website.com/index.php?wovn=en`. If you instead set the value to
138
- `'lang'`, then the later URL example would have the form
139
- `https://my-website.com/index.php?lang=en`.
140
-
141
- ### 2.6. query
142
-
143
- WOVN.io ignores query parameters when searching a translated page. If you want to add a query parameter to translated page's URL, you should configure the `query` parameter. (You need to configure WOVN.io too)
144
-
145
- https://wovn.io/ja/contact?os=mac&keyboard=us
146
-
147
- If the `default_lang` is 'en', and the query is set to '', the above URL will be modified into the following URL to search for the page's translation.
148
-
149
- https://wovn.io/contact
150
-
151
- If the `default_lang` is 'en', and the query is set to 'os', the above URL will be modified into the following URL to search for the page's translation.
152
-
153
- https://wovn.io/contact?os=mac
154
-
155
- ### 2.7. ignore_class
156
-
157
- This sets "Ignore class" which prevents WOVN from translating HTML elements that have a class contained in this array.
158
-
159
- ### 2.8. translate_fragment
160
-
161
- This option allows to disable translating partial HTML content. By default,
162
- partial HTML content is translated but no widget snippet is added. Set
163
- `translate_fragment` to `false` to prevent translating partial HTML content.
164
-
165
- ### 2.9 ignore_paths
166
-
167
- This parameter tells WOVN.rb to not localize content withing given directories.
168
-
169
- The directories given will only be matched against the beginning of the URL path.
170
-
171
- For instance, if you want to not localize the admin directory of your website, you should add the following to you WOVN.rb configuration.
172
- ```
173
- 'ignore_paths' => ['/admin/']
174
- ```
175
-
176
- ## 3. Contributing
177
-
178
- 1. Fork it ( https://github.com/WOVNio/wovnrb/fork )
179
- 2. Create your feature branch (`git checkout -b my-new-feature`)
180
- 3. Commit your changes (`git commit -am 'Add some feature'`)
181
- 4. Push to the branch (`git push origin my-new-feature`)
182
- 5. Create a new Pull Request