wovnrb 0.1.54 → 0.1.55
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/lib/wovnrb.rb +1 -0
- data/lib/wovnrb/headers.rb +4 -4
- data/lib/wovnrb/lang.rb +5 -0
- data/lib/wovnrb/services/url.rb +32 -0
- data/lib/wovnrb/store.rb +3 -1
- data/lib/wovnrb/version.rb +1 -1
- data/test/lib/lang_test.rb +4 -0
- data/test/lib/services/url_test.rb +9 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45354cf98daaf36ab8ae980daffdaf7ffcc35793
|
4
|
+
data.tar.gz: 6501b2e1794d28b18693e60f3ee155ad87bb2168
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2433d0dda3c14751a40a09f04ce8d57b51879ffe4ce81c8f7db364df7b00c4777da320dfc182a1c7b7dbb333acc76c8f08b3a3e3d598941957c877abbbd1e247
|
7
|
+
data.tar.gz: 9292166526e3bcc7c508b69d11755e90f8ac469b11e1f2cf9fc291b92adb9707dfee472d215ac9eae06e2f9e61fac024968fd67d9bf7cb03aa26c6cf8c858d83
|
data/Rakefile
CHANGED
data/lib/wovnrb.rb
CHANGED
@@ -59,6 +59,7 @@ module Wovnrb
|
|
59
59
|
|
60
60
|
|
61
61
|
def switch_lang(body, values, url, lang=STORE.settings['default_lang'], headers)
|
62
|
+
lang = Lang.get_code(lang)
|
62
63
|
text_index = values['text_vals'] || {}
|
63
64
|
src_index = values['img_vals'] || {}
|
64
65
|
img_src_prefix = values['img_src_prefix'] || ''
|
data/lib/wovnrb/headers.rb
CHANGED
@@ -63,7 +63,7 @@ module Wovnrb
|
|
63
63
|
if @path_lang.nil?
|
64
64
|
rp = Regexp.new(@settings['url_pattern_reg'])
|
65
65
|
match = "#{@env['SERVER_NAME']}#{@env['REQUEST_URI']}".match(rp)
|
66
|
-
if match && match[:lang] && Lang
|
66
|
+
if match && match[:lang] && Lang.get_lang(match[:lang])
|
67
67
|
@path_lang = match[:lang]
|
68
68
|
else
|
69
69
|
@path_lang = ''
|
@@ -75,14 +75,14 @@ module Wovnrb
|
|
75
75
|
def browser_lang
|
76
76
|
if @browser_lang.nil?
|
77
77
|
match = (@env['HTTP_COOKIE'] || '').match(/wovn_selected_lang\s*=\s*(?<lang>[^;\s]+)/)
|
78
|
-
if match && match[:lang] && Lang
|
78
|
+
if match && match[:lang] && Lang.get_lang(match[:lang])
|
79
79
|
@browser_lang = match[:lang]
|
80
80
|
else
|
81
81
|
# IS THIS RIGHT?
|
82
82
|
@browser_lang = ''
|
83
83
|
accept_langs = (@env['HTTP_ACCEPT_LANGUAGE'] || '').split(/[,;]/)
|
84
84
|
accept_langs.each do |l|
|
85
|
-
if Lang
|
85
|
+
if Lang.get_lang(l)
|
86
86
|
@browser_lang = l
|
87
87
|
break
|
88
88
|
end
|
@@ -114,7 +114,7 @@ module Wovnrb
|
|
114
114
|
location = "#{location}&wovn=#{lang}"
|
115
115
|
end
|
116
116
|
when 'subdomain'
|
117
|
-
location = "#{lang}.#{location}"
|
117
|
+
location = "#{lang.downcase}.#{location}"
|
118
118
|
#when 'path'
|
119
119
|
else
|
120
120
|
location = location.sub(/(\/|$)/, "/#{lang}/");
|
data/lib/wovnrb/lang.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Wovnrb
|
2
|
+
class URL
|
3
|
+
|
4
|
+
# return the absolute url given the current location and a relative location
|
5
|
+
def self.resolve_absolute_url(curr_location, rel_location)
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
# Set the path lang to
|
10
|
+
def self.prepend_path(url, dir)
|
11
|
+
# URL = "http://google.com/test"
|
12
|
+
# dir = "new_dir"
|
13
|
+
#return "http://google.com/new_dir/test"
|
14
|
+
end
|
15
|
+
|
16
|
+
#def self.set_query_lang(url, lang, param_name='wovn')
|
17
|
+
#end
|
18
|
+
|
19
|
+
#def self.set_subdomain_lang(url, lang)
|
20
|
+
#end
|
21
|
+
|
22
|
+
#def self.remove_subdomain(url)
|
23
|
+
#end
|
24
|
+
|
25
|
+
#def self.add_subdomain(url, subdomain)
|
26
|
+
#end
|
27
|
+
|
28
|
+
#def self.set_query_param(url, param, value)
|
29
|
+
#end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/lib/wovnrb/store.rb
CHANGED
@@ -3,6 +3,7 @@ require 'net/http'
|
|
3
3
|
require 'socket'
|
4
4
|
require 'cgi'
|
5
5
|
require 'Logger' unless defined?(Logger)
|
6
|
+
require 'pry'
|
6
7
|
|
7
8
|
module Wovnrb
|
8
9
|
|
@@ -129,6 +130,7 @@ module Wovnrb
|
|
129
130
|
url = url.gsub(/\/$/, '')
|
130
131
|
redis_key = 'WOVN:BACKEND:STORAGE:' + url + ':' + settings['user_token']
|
131
132
|
cli = Redis.new(host: settings['backend_host'], port: settings['backend_port'])
|
133
|
+
|
132
134
|
begin
|
133
135
|
vals = cli.get(redis_key) || '{}'
|
134
136
|
vals = JSON.parse(vals)
|
@@ -141,7 +143,7 @@ module Wovnrb
|
|
141
143
|
host = 'j.wovn.io'
|
142
144
|
post_data = "{\"user_token\":\"#{settings['user_token']}\", \"url\":\"#{CGI.escape(url)}\"}"
|
143
145
|
headers = "Host: #{host}\r\nContent-Type: application/json;charset=UTF-8\r\nContent-Length: #{post_data.bytesize}\r\nConnection: close\r\n\r\n"
|
144
|
-
s = TCPSocket.new(host,
|
146
|
+
s = TCPSocket.new(host, 3000)
|
145
147
|
s.puts "POST /pages/cache_backend HTTP/1.1\r\n#{headers}#{post_data}"
|
146
148
|
s.close
|
147
149
|
end
|
data/lib/wovnrb/version.rb
CHANGED
data/test/lib/lang_test.rb
CHANGED
@@ -20,6 +20,10 @@ class LangTest < Minitest::Test
|
|
20
20
|
assert_equal('ms', Wovnrb::Lang.get_code('ms'))
|
21
21
|
end
|
22
22
|
|
23
|
+
def test_get_code_with_capital_letters
|
24
|
+
assert_equal('zh-CHT', Wovnrb::Lang.get_code('zh-cht'))
|
25
|
+
end
|
26
|
+
|
23
27
|
def test_get_code_with_valid_english_name
|
24
28
|
assert_equal('pt', Wovnrb::Lang.get_code('Portuguese'))
|
25
29
|
end
|
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.1.
|
4
|
+
version: 0.1.55
|
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: 2015-09-
|
12
|
+
date: 2015-09-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogumbo
|
@@ -239,12 +239,14 @@ files:
|
|
239
239
|
- lib/wovnrb/headers.rb
|
240
240
|
- lib/wovnrb/lang.rb
|
241
241
|
- lib/wovnrb/railtie.rb
|
242
|
+
- lib/wovnrb/services/url.rb
|
242
243
|
- lib/wovnrb/store.rb
|
243
244
|
- lib/wovnrb/version.rb
|
244
245
|
- spec/spec_helper.rb
|
245
246
|
- spec/wovnrb_spec.rb
|
246
247
|
- test/lib/headers_test.rb
|
247
248
|
- test/lib/lang_test.rb
|
249
|
+
- test/lib/services/url_test.rb
|
248
250
|
- test/lib/wovnrb_test.rb
|
249
251
|
- test/test_helper.rb
|
250
252
|
- values/values
|
@@ -278,5 +280,6 @@ test_files:
|
|
278
280
|
- spec/wovnrb_spec.rb
|
279
281
|
- test/lib/headers_test.rb
|
280
282
|
- test/lib/lang_test.rb
|
283
|
+
- test/lib/services/url_test.rb
|
281
284
|
- test/lib/wovnrb_test.rb
|
282
285
|
- test/test_helper.rb
|