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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d876d5f0c2e358943ce4c36ddfcf32540ada100
4
- data.tar.gz: a10f6871505cada6b31b354d97622fc8935e0b8f
3
+ metadata.gz: 7e922108abe3424f50377edcecfb7e50859500e0
4
+ data.tar.gz: 398d5cc593c29b115b2d64f60e9ae910e5edda8f
5
5
  SHA512:
6
- metadata.gz: 58f34c367ab4da79d17af2146b902af133eda0724701216dad5cb62d077d51d333b177b1a13754a844ccd26ea859e09a9b9b9219d987323ad0577fc532deb435
7
- data.tar.gz: 0987bcc9054604098dd5e15590679508f6b098bf6e41baac7d34004fadec25193e09a6846c5dac6dccaf35831b31298265d12188753a3b966f61229cc2249ce8
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.before_filter :set_locale
4
+ base.around_filter :set_locale
5
5
  end
6
6
 
7
7
  private
8
8
 
9
9
  def set_locale
10
- I18n.locale = SubdomainLocale.mapping.locale_for(request.subdomain)
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,6 +3,14 @@ module SubdomainLocale
3
3
  attr_accessor :mapping
4
4
  end
5
5
 
6
+ def self.default_fallback(locale)
7
+ if I18n.locale_available?(locale)
8
+ locale
9
+ else
10
+ I18n.default_locale
11
+ end
12
+ end
13
+
6
14
  class Mapping
7
15
  def initialize(mapping)
8
16
  @repository = {}
@@ -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 = { "" => I18n.default_locale, "www" => I18n.default_locale }
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "subdomain_locale"
5
- spec.version = "1.0.beta2"
5
+ spec.version = "1.0.beta3"
6
6
  spec.authors = ["Semyon Perepelitsa"]
7
7
  spec.email = ["sema@sema.in"]
8
8
  spec.summary = "Set I18n locale based on subdomain"
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
data/test/mapping_test.rb CHANGED
@@ -1,7 +1,4 @@
1
- require "isolate/now"
2
- require "minitest/autorun"
3
- require "subdomain_locale/mapping"
4
- require "active_support/core_ext"
1
+ require_relative "test_helper"
5
2
 
6
3
  class MappingTest < MiniTest::Unit::TestCase
7
4
  include SubdomainLocale
data/test/rails_test.rb CHANGED
@@ -1,11 +1,5 @@
1
1
  # encoding: UTF-8
2
- ENV["RAILS_ENV"] = "test"
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://www.example.com/", menu[1]["href"]
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 = "www.example.com"
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
- assert_raise(I18n::InvalidLocale) do
45
- get :world
46
- end
44
+ get :world
45
+ assert_select "p", "Hello"
47
46
  end
48
47
  end
49
48
 
@@ -0,0 +1,7 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+
3
+ require "isolate/now"
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "minitest/autorun"
6
+ require "rails/test_help"
7
+ Rails.backtrace_cleaner.remove_silencers!
data/test/url_for_test.rb CHANGED
@@ -1,7 +1,4 @@
1
- require "isolate/now"
2
- require "minitest/autorun"
3
- require "subdomain_locale"
4
- require "subdomain_locale/url_for"
1
+ require_relative "test_helper"
5
2
 
6
3
  class UrlForTest < MiniTest::Unit::TestCase
7
4
  module UrlFor
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.beta2
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-02-19 00:00:00.000000000 Z
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.0
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