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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96cb0661f30c5d9d729ef90a5ba9f95626bbf181
4
- data.tar.gz: 1b00e8ad4532cc33c438ae0b1ee4f9918f651f1b
3
+ metadata.gz: 45354cf98daaf36ab8ae980daffdaf7ffcc35793
4
+ data.tar.gz: 6501b2e1794d28b18693e60f3ee155ad87bb2168
5
5
  SHA512:
6
- metadata.gz: 49ab51000689c2ae47c0ec43e24cabeabda3f1328ba0022b0c9bd4cdf72d9ead044da2479346d9f17df6930c87ed3082532933c77692043f2c8317c4aa96c936
7
- data.tar.gz: 924a6e1e977c3ac5ed8f6c96437601da5c3dc921e34247f8291bd0a02bd70b835eea77f8d7dba1225354fb9e820c3c277c0a63aaada475224c4a7d98ae8fac79
6
+ metadata.gz: 2433d0dda3c14751a40a09f04ce8d57b51879ffe4ce81c8f7db364df7b00c4777da320dfc182a1c7b7dbb333acc76c8f08b3a3e3d598941957c877abbbd1e247
7
+ data.tar.gz: 9292166526e3bcc7c508b69d11755e90f8ac469b11e1f2cf9fc291b92adb9707dfee472d215ac9eae06e2f9e61fac024968fd67d9bf7cb03aa26c6cf8c858d83
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ require 'rake/testtask'
4
4
 
5
5
  Rake::TestTask.new do |t|
6
6
  t.libs << 'test'
7
- t.test_files = FileList['test/*/*.rb']
7
+ t.test_files = FileList['test/*/*.rb'] | FileList['test/*/*/*.rb']
8
8
  t.options = '-p'
9
9
  end
10
10
 
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'] || ''
@@ -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::LANG[match[: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::LANG[match[: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::LANG[l]
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
@@ -66,5 +66,10 @@ module Wovnrb
66
66
  return nil
67
67
  end
68
68
 
69
+ def self.get_lang(lang)
70
+ lang_code = get_code(lang)
71
+ return LANG[lang_code]
72
+ end
73
+
69
74
  end
70
75
  end
@@ -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, 80)
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
@@ -1,3 +1,3 @@
1
1
  module Wovnrb
2
- VERSION = "0.1.54"
2
+ VERSION = "0.1.55"
3
3
  end
@@ -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
@@ -0,0 +1,9 @@
1
+ require 'wovnrb/services/url'
2
+
3
+ class URLTest < Minitest::Test
4
+
5
+ def test_prepend_path
6
+ assert_equal('http://google.com/new_dir/test', Wovnrb::URL.prepend_path('http://google.com/test', 'new_dir'))
7
+ end
8
+
9
+ 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.54
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-09 00:00:00.000000000 Z
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