wovnrb 0.2.16 → 0.2.17
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/script_replacer.rb +1 -1
- data/lib/wovnrb/store.rb +40 -20
- data/lib/wovnrb/version.rb +1 -1
- data/test/lib/html_replacers/script_replacer_test.rb +21 -0
- data/test/lib/store_test.rb +44 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7348fe530bd3a1abe6f31aa1013a8262beca4153
|
4
|
+
data.tar.gz: facf8da674510feed09ef64b53ea50a769f9fb40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 388bf3245e438c050b83f28c5417a7b275a7892318319e048b1c7d3c21e302bbd57b393c650a1134bc85658c2a4216201830554e34404bb8a8005b28cefc247a
|
7
|
+
data.tar.gz: 1b6632a9627cc7ff68fee160e1c91e12389eaec80f606748355751111beed03984c122f0f4f40f8ebfcba5b411e76b285c7de2f2c4f93d4829e2b0cee57d0e47
|
@@ -23,7 +23,7 @@ module Wovnrb
|
|
23
23
|
|
24
24
|
# INSERT BACKEND WIDGET
|
25
25
|
insert_node = Nokogiri::XML::Node.new('script', dom)
|
26
|
-
insert_node['src'] =
|
26
|
+
insert_node['src'] = "//j.#{@store.wovn_host}/1"
|
27
27
|
insert_node['async'] = true
|
28
28
|
version = defined?(VERSION) ? VERSION : ''
|
29
29
|
insert_node['data-wovnio'] = "key=#{@store.settings['user_token']}&backend=true¤tLang=#{lang.lang_code}&defaultLang=#{@store.settings['default_lang']}&urlPattern=#{@store.settings['url_pattern']}&langCodeAliases=#{JSON.dump(@store.settings['custom_lang_aliases'])}&version=#{version}"
|
data/lib/wovnrb/store.rb
CHANGED
@@ -11,6 +11,29 @@ module Wovnrb
|
|
11
11
|
class Store
|
12
12
|
include Singleton
|
13
13
|
|
14
|
+
def self.default_settings
|
15
|
+
{
|
16
|
+
'user_token' => '',
|
17
|
+
'log_path' => 'log/wovn_error.log',
|
18
|
+
'ignore_paths' => [],
|
19
|
+
'ignore_globs' => [],
|
20
|
+
'url_pattern' => 'path',
|
21
|
+
'url_pattern_reg' => "/(?<lang>[^/.?]+)",
|
22
|
+
'query' => [],
|
23
|
+
'api_url' => 'https://api.wovn.io/v0/values',
|
24
|
+
'api_timeout_seconds' => 0.5,
|
25
|
+
'default_lang' => 'en',
|
26
|
+
'supported_langs' => ['en'],
|
27
|
+
'test_mode' => false,
|
28
|
+
'test_url' => '',
|
29
|
+
'cache_megabytes' => nil,
|
30
|
+
'ttl_seconds' => nil,
|
31
|
+
'use_proxy' => false, # use env['HTTP_X_FORWARDED_HOST'] instead of env['HTTP_HOST'] and env['SERVER_NAME'] when this setting is true.
|
32
|
+
'custom_lang_aliases' => {},
|
33
|
+
'wovn_dev_mode' => false
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
14
37
|
def initialize
|
15
38
|
@settings = {}
|
16
39
|
@config_loaded = false
|
@@ -21,26 +44,7 @@ module Wovnrb
|
|
21
44
|
#
|
22
45
|
# @return [nil]
|
23
46
|
def reset
|
24
|
-
@settings =
|
25
|
-
{
|
26
|
-
'user_token' => '',
|
27
|
-
'log_path' => 'log/wovn_error.log',
|
28
|
-
'ignore_paths' => [],
|
29
|
-
'ignore_globs' => [],
|
30
|
-
'url_pattern' => 'path',
|
31
|
-
'url_pattern_reg' => "/(?<lang>[^/.?]+)",
|
32
|
-
'query' => [],
|
33
|
-
'api_url' => 'https://api.wovn.io/v0/values',
|
34
|
-
'api_timeout_seconds' => 0.5,
|
35
|
-
'default_lang' => 'en',
|
36
|
-
'supported_langs' => ['en'],
|
37
|
-
'test_mode' => false,
|
38
|
-
'test_url' => '',
|
39
|
-
'cache_megabytes' => nil,
|
40
|
-
'ttl_seconds' => nil,
|
41
|
-
'use_proxy' => false, # use env['HTTP_X_FORWARDED_HOST'] instead of env['HTTP_HOST'] and env['SERVER_NAME'] when this setting is true.
|
42
|
-
'custom_lang_aliases' => {}
|
43
|
-
}
|
47
|
+
@settings = Store.default_settings
|
44
48
|
# When Store is initialized, the Rails.configuration object is not yet initialized
|
45
49
|
@config_loaded = false
|
46
50
|
end
|
@@ -148,10 +152,26 @@ module Wovnrb
|
|
148
152
|
@settings['custom_lang_aliases'].stringify_keys!
|
149
153
|
end
|
150
154
|
|
155
|
+
if wovn_dev_mode? && @settings['api_url'] == Store.default_settings['api_url']
|
156
|
+
@settings['api_url'] = "#{wovn_protocol}://api.#{wovn_host}/v0/values"
|
157
|
+
end
|
158
|
+
|
151
159
|
@config_loaded = true
|
152
160
|
@settings
|
153
161
|
end
|
154
162
|
|
163
|
+
def wovn_dev_mode?
|
164
|
+
@settings['wovn_dev_mode']
|
165
|
+
end
|
166
|
+
|
167
|
+
def wovn_protocol
|
168
|
+
wovn_dev_mode? ? 'http' : 'https'
|
169
|
+
end
|
170
|
+
|
171
|
+
def wovn_host
|
172
|
+
wovn_dev_mode? ? 'dev-wovn.io:3000' : 'wovn.io'
|
173
|
+
end
|
174
|
+
|
155
175
|
private
|
156
176
|
def cleanSettings
|
157
177
|
@settings['ignore_globs'] = []
|
data/lib/wovnrb/version.rb
CHANGED
@@ -23,6 +23,27 @@ module Wovnrb
|
|
23
23
|
assert_equal('test/test.js', other_script.get_attribute('src'))
|
24
24
|
end
|
25
25
|
|
26
|
+
def test_replace_with_wovn_dev_mode_on
|
27
|
+
store = Store.instance
|
28
|
+
store.settings['user_token'] = 'test_token'
|
29
|
+
store.settings['default_lang'] = 'en'
|
30
|
+
store.settings['url_pattern'] = 'domain'
|
31
|
+
store.settings['wovn_dev_mode'] = true
|
32
|
+
|
33
|
+
replacer = ScriptReplacer.new(store)
|
34
|
+
dom = to_head_dom('<script src="test/test.js"></script>')
|
35
|
+
replacer.replace(dom, Lang.new('ja'))
|
36
|
+
|
37
|
+
scripts = dom.xpath('//script')
|
38
|
+
assert_equal(2, scripts.length)
|
39
|
+
|
40
|
+
wovn_script = scripts[0]
|
41
|
+
other_script = scripts[1]
|
42
|
+
|
43
|
+
assert_equal('//j.dev-wovn.io:3000/1', wovn_script.get_attribute('src'))
|
44
|
+
assert_equal('test/test.js', other_script.get_attribute('src'))
|
45
|
+
end
|
46
|
+
|
26
47
|
def test_with_embed_wovn
|
27
48
|
store = Store.instance
|
28
49
|
store.settings['user_token'] = 'test_token'
|
data/test/lib/store_test.rb
CHANGED
@@ -111,5 +111,49 @@ module Wovnrb
|
|
111
111
|
|
112
112
|
assert_equal({'ja' => 'staging-ja', 'en' => 'staging-en'}, s.settings['custom_lang_aliases'])
|
113
113
|
end
|
114
|
+
|
115
|
+
def test_wovn_dev_mode_on
|
116
|
+
s = Wovnrb::Store.instance
|
117
|
+
s.settings({'wovn_dev_mode' => true})
|
118
|
+
|
119
|
+
assert(s.settings['wovn_dev_mode'])
|
120
|
+
assert(s.wovn_dev_mode?)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_wovn_dev_mode_off_by_default
|
124
|
+
s = Wovnrb::Store.instance
|
125
|
+
s.settings({})
|
126
|
+
|
127
|
+
assert(!s.settings['wovn_dev_mode'])
|
128
|
+
assert(!s.wovn_dev_mode?)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_default_api_url_with_wovn_dev_mode_on
|
132
|
+
s = Wovnrb::Store.instance
|
133
|
+
s.settings({'wovn_dev_mode' => true})
|
134
|
+
|
135
|
+
assert_equal('http://api.dev-wovn.io:3000/v0/values', s.settings['api_url'])
|
136
|
+
end
|
137
|
+
|
138
|
+
def test_default_api_url_with_wovn_dev_mode_off
|
139
|
+
s = Wovnrb::Store.instance
|
140
|
+
s.settings({'wovn_dev_mode' => false})
|
141
|
+
|
142
|
+
assert_equal('https://api.wovn.io/v0/values', s.settings['api_url'])
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_custom_api_url_not_changed_with_wovn_dev_mode_on
|
146
|
+
s = Wovnrb::Store.instance
|
147
|
+
s.settings({'api_url' => 'test-api.io', 'wovn_dev_mode' => true})
|
148
|
+
|
149
|
+
assert_equal('test-api.io', s.settings['api_url'])
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_custom_api_url_not_changed_with_wovn_dev_mode_off
|
153
|
+
s = Wovnrb::Store.instance
|
154
|
+
s.settings({'api_url' => 'test-api.io', 'wovn_dev_mode' => false})
|
155
|
+
|
156
|
+
assert_equal('test-api.io', s.settings['api_url'])
|
157
|
+
end
|
114
158
|
end
|
115
159
|
end
|