subdomain_locale 1.0.beta2 → 1.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/subdomain_locale/controller.rb +4 -2
- data/lib/subdomain_locale/mapping.rb +8 -0
- data/lib/subdomain_locale/railtie.rb +2 -1
- data/subdomain_locale.gemspec +1 -1
- data/test/dummy/config.ru +4 -0
- data/test/mapping_test.rb +1 -4
- data/test/rails_test.rb +11 -12
- data/test/test_helper.rb +7 -0
- data/test/url_for_test.rb +1 -4
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e922108abe3424f50377edcecfb7e50859500e0
|
4
|
+
data.tar.gz: 398d5cc593c29b115b2d64f60e9ae910e5edda8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bce28543d5379b27d6e86b050a642dd331d804f0b310e0986f89f166490f6fb49274481ba0db02bf9730d02a86be91eb507f834fc4e9541b8bdaaaf5527f2ad4
|
7
|
+
data.tar.gz: 8b763460ecc07a8f1aa178c656a8e2a81ffc3e2fad73beea839a669390ba68754a6cb9ff287d985d3f5a3d69a1faa34b0fb296eb794b564002030357f5bcea61
|
@@ -1,13 +1,15 @@
|
|
1
1
|
module SubdomainLocale
|
2
2
|
module Controller
|
3
3
|
def self.included(base)
|
4
|
-
base.
|
4
|
+
base.around_filter :set_locale
|
5
5
|
end
|
6
6
|
|
7
7
|
private
|
8
8
|
|
9
9
|
def set_locale
|
10
|
-
|
10
|
+
locale = SubdomainLocale.mapping.locale_for(request.subdomain)
|
11
|
+
locale = SubdomainLocale.default_fallback(locale)
|
12
|
+
I18n.with_locale(locale) { yield }
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -3,11 +3,12 @@ require "rails/railtie"
|
|
3
3
|
module SubdomainLocale
|
4
4
|
class Railtie < ::Rails::Railtie
|
5
5
|
config.subdomain_locale = {}
|
6
|
+
config.subdomain_default = "" # or "www"
|
6
7
|
|
7
8
|
# Execute after all application initializers, I18n is often configured there.
|
8
9
|
config.after_initialize do |app|
|
9
10
|
require "subdomain_locale/mapping"
|
10
|
-
default = {
|
11
|
+
default = { app.config.subdomain_default => I18n.default_locale }
|
11
12
|
mapping = default.merge(app.config.subdomain_locale)
|
12
13
|
SubdomainLocale.mapping = Mapping.new(mapping)
|
13
14
|
end
|
data/subdomain_locale.gemspec
CHANGED
data/test/mapping_test.rb
CHANGED
data/test/rails_test.rb
CHANGED
@@ -1,11 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
|
3
|
-
|
4
|
-
require "isolate/now"
|
5
|
-
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
6
|
-
require "minitest/autorun"
|
7
|
-
require "rails/test_help"
|
8
|
-
Rails.backtrace_cleaner.remove_silencers!
|
2
|
+
require_relative "test_helper"
|
9
3
|
|
10
4
|
class HelloControllerTest < ActionController::TestCase
|
11
5
|
def test_links
|
@@ -13,13 +7,13 @@ class HelloControllerTest < ActionController::TestCase
|
|
13
7
|
get :world
|
14
8
|
menu = css_select("menu a")
|
15
9
|
assert_equal "/", menu[0]["href"]
|
16
|
-
assert_equal "http://
|
10
|
+
assert_equal "http://example.com/", menu[1]["href"]
|
17
11
|
assert_equal "http://ru.example.com/", menu[2]["href"]
|
18
12
|
assert_equal "http://ua.example.com/", menu[3]["href"]
|
19
13
|
end
|
20
14
|
|
21
15
|
def test_default
|
22
|
-
@request.host = "
|
16
|
+
@request.host = "example.com"
|
23
17
|
get :world
|
24
18
|
assert_response :ok
|
25
19
|
assert_select "p", "Hello"
|
@@ -39,11 +33,16 @@ class HelloControllerTest < ActionController::TestCase
|
|
39
33
|
assert_select "p", "Привіт"
|
40
34
|
end
|
41
35
|
|
36
|
+
def test_locale_after_action
|
37
|
+
@request.host = "ru.example.com"
|
38
|
+
get :world
|
39
|
+
assert_equal :en, I18n.locale
|
40
|
+
end
|
41
|
+
|
42
42
|
def test_other
|
43
43
|
@request.host = "wtf.example.com"
|
44
|
-
|
45
|
-
|
46
|
-
end
|
44
|
+
get :world
|
45
|
+
assert_select "p", "Hello"
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
data/test/test_helper.rb
ADDED
data/test/url_for_test.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subdomain_locale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Semyon Perepelitsa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- test/dummy/app/views/hello/world.html.erb
|
48
48
|
- test/dummy/app/views/hello_mailer/world.text.erb
|
49
49
|
- test/dummy/app/views/layouts/application.html.erb
|
50
|
+
- test/dummy/config.ru
|
50
51
|
- test/dummy/config/application.rb
|
51
52
|
- test/dummy/config/environment.rb
|
52
53
|
- test/dummy/config/environments/test.rb
|
@@ -55,6 +56,7 @@ files:
|
|
55
56
|
- test/dummy/config/routes.rb
|
56
57
|
- test/mapping_test.rb
|
57
58
|
- test/rails_test.rb
|
59
|
+
- test/test_helper.rb
|
58
60
|
- test/url_for_test.rb
|
59
61
|
homepage: https://github.com/semaperepelitsa/subdomain_locale
|
60
62
|
licenses:
|
@@ -76,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
78
|
version: 1.3.1
|
77
79
|
requirements: []
|
78
80
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.2.
|
81
|
+
rubygems_version: 2.2.2
|
80
82
|
signing_key:
|
81
83
|
specification_version: 4
|
82
84
|
summary: Set I18n locale based on subdomain
|
@@ -87,6 +89,7 @@ test_files:
|
|
87
89
|
- test/dummy/app/views/hello/world.html.erb
|
88
90
|
- test/dummy/app/views/hello_mailer/world.text.erb
|
89
91
|
- test/dummy/app/views/layouts/application.html.erb
|
92
|
+
- test/dummy/config.ru
|
90
93
|
- test/dummy/config/application.rb
|
91
94
|
- test/dummy/config/environment.rb
|
92
95
|
- test/dummy/config/environments/test.rb
|
@@ -95,4 +98,5 @@ test_files:
|
|
95
98
|
- test/dummy/config/routes.rb
|
96
99
|
- test/mapping_test.rb
|
97
100
|
- test/rails_test.rb
|
101
|
+
- test/test_helper.rb
|
98
102
|
- test/url_for_test.rb
|