muck-engine 0.1.31 → 0.1.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/app/helpers/muck_engine_helper.rb +16 -8
- data/app/models/language.rb +17 -2
- data/muck-engine.gemspec +9 -1
- data/test/rails_root/db/migrate/20090402234137_create_languages.rb +18 -0
- data/test/rails_root/db/migrate/20090426041056_create_countries.rb +15 -0
- data/test/rails_root/db/migrate/20090426041103_create_states.rb +18 -0
- data/test/rails_root/test/test_helper.rb +1 -0
- data/test/rails_root/test/unit/muck_engine_helper_test.rb +113 -0
- metadata +9 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.32
|
@@ -80,16 +80,24 @@ module MuckEngineHelper
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def locale_link(name, locale)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
83
|
+
parts = request.host.split('.')
|
84
|
+
first_subdomain = parts.first
|
85
|
+
request_uri = request.request_uri
|
86
|
+
if first_subdomain == 'www' or Language.supported_locale?(first_subdomain)
|
87
|
+
link_to name, request.protocol + (locale == I18n.default_locale.to_s ? 'www' : locale) + '.' + parts[1..-1].join('.') + request.port_string + request_uri
|
88
|
+
elsif /^localhost/.match( request.host ) or /^(\d{1,3}\.){3}\d{1,3}$/.match( request.host )
|
89
|
+
if request_uri.include?('?')
|
90
|
+
if request_uri.include?('locale')
|
91
|
+
link_to name, request.protocol + request.host_with_port + request_uri.sub(/locale=.*/, 'locale=' + locale)
|
92
|
+
else
|
93
|
+
link_to name, request.protocol + request.host_with_port + request_uri + '&locale=' + locale
|
94
|
+
end
|
95
|
+
else
|
96
|
+
link_to name, request.protocol + request.host_with_port + request_uri + '?locale=' + locale
|
97
|
+
end
|
89
98
|
else
|
90
|
-
|
99
|
+
link_to name, request.protocol + (locale == I18n.default_locale.to_s ? 'www' : locale) + '.' + request.host_with_port + request_uri
|
91
100
|
end
|
92
|
-
link_to name, new_domain
|
93
101
|
end
|
94
102
|
|
95
103
|
# Generate parameters for a url that refer to a given object as parent. Useful
|
data/app/models/language.rb
CHANGED
@@ -12,10 +12,25 @@
|
|
12
12
|
|
13
13
|
class Language < ActiveRecord::Base
|
14
14
|
|
15
|
+
@@locale_ids = nil
|
16
|
+
|
15
17
|
def self.locale_id
|
16
|
-
|
17
|
-
@@locale_ids ||= Hash[*languages.collect {|v|[v.locale.to_sym, v.id]}.flatten]
|
18
|
+
cache_locale_ids
|
18
19
|
@@locale_ids[I18n.locale]
|
19
20
|
end
|
21
|
+
|
22
|
+
def self.supported_locale? locale
|
23
|
+
cache_locale_ids
|
24
|
+
@@locale_ids[locale.to_sym] != nil
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def self.cache_locale_ids
|
30
|
+
if !@@locale_ids
|
31
|
+
languages = Language.find(:all, :select => 'id, locale', :conditions => ['languages.supported = ?', true])
|
32
|
+
@@locale_ids = Hash[*languages.collect {|v|[v.locale.to_sym, v.id]}.flatten]
|
33
|
+
end
|
34
|
+
end
|
20
35
|
|
21
36
|
end
|
data/muck-engine.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{muck-engine}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.32"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Justin Ball"]
|
@@ -376,6 +376,9 @@ Gem::Specification.new do |s|
|
|
376
376
|
"test/rails_root/config/routes.rb",
|
377
377
|
"test/rails_root/db/.keep",
|
378
378
|
"test/rails_root/db/migrate/20090320174818_create_muck_permissions_and_roles.rb",
|
379
|
+
"test/rails_root/db/migrate/20090402234137_create_languages.rb",
|
380
|
+
"test/rails_root/db/migrate/20090426041056_create_countries.rb",
|
381
|
+
"test/rails_root/db/migrate/20090426041103_create_states.rb",
|
379
382
|
"test/rails_root/db/migrate/20090602041838_create_users.rb",
|
380
383
|
"test/rails_root/features/step_definitions/webrat_steps.rb",
|
381
384
|
"test/rails_root/features/support/env.rb",
|
@@ -549,6 +552,7 @@ Gem::Specification.new do |s|
|
|
549
552
|
"test/rails_root/test/test_helper.rb",
|
550
553
|
"test/rails_root/test/unit/.keep",
|
551
554
|
"test/rails_root/test/unit/basic_mailer_test.rb",
|
555
|
+
"test/rails_root/test/unit/muck_engine_helper_test.rb",
|
552
556
|
"test/rails_root/vendor/plugins/ssl_requirement/README",
|
553
557
|
"test/rails_root/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb",
|
554
558
|
"test/rails_root/vendor/plugins/ssl_requirement/test/ssl_requirement_test.rb",
|
@@ -585,6 +589,9 @@ Gem::Specification.new do |s|
|
|
585
589
|
"test/rails_root/config/initializers/session_store.rb",
|
586
590
|
"test/rails_root/config/routes.rb",
|
587
591
|
"test/rails_root/db/migrate/20090320174818_create_muck_permissions_and_roles.rb",
|
592
|
+
"test/rails_root/db/migrate/20090402234137_create_languages.rb",
|
593
|
+
"test/rails_root/db/migrate/20090426041056_create_countries.rb",
|
594
|
+
"test/rails_root/db/migrate/20090426041103_create_states.rb",
|
588
595
|
"test/rails_root/db/migrate/20090602041838_create_users.rb",
|
589
596
|
"test/rails_root/features/step_definitions/webrat_steps.rb",
|
590
597
|
"test/rails_root/features/support/env.rb",
|
@@ -600,6 +607,7 @@ Gem::Specification.new do |s|
|
|
600
607
|
"test/rails_root/test/shoulda_macros/plugins.rb",
|
601
608
|
"test/rails_root/test/test_helper.rb",
|
602
609
|
"test/rails_root/test/unit/basic_mailer_test.rb",
|
610
|
+
"test/rails_root/test/unit/muck_engine_helper_test.rb",
|
603
611
|
"test/rails_root/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb",
|
604
612
|
"test/rails_root/vendor/plugins/ssl_requirement/test/ssl_requirement_test.rb",
|
605
613
|
"test/rails_root/vendor/plugins/validation_reflection/init.rb",
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateLanguages < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :languages, :force => true do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :english_name
|
6
|
+
t.string :locale
|
7
|
+
t.boolean :supported, :default => true
|
8
|
+
t.integer :is_default, :default => false
|
9
|
+
end
|
10
|
+
add_index :languages, :name
|
11
|
+
add_index :languages, :locale
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.down
|
15
|
+
drop_table :languages
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateCountries < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :countries, :force => true do |t|
|
4
|
+
t.string "name", :limit => 128, :default => "", :null => false
|
5
|
+
t.string "abbreviation", :limit => 3, :default => "", :null => false
|
6
|
+
t.integer "sort", :default => 1000, :null => false
|
7
|
+
end
|
8
|
+
add_index :countries, :name
|
9
|
+
add_index :countries, :abbreviation
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
drop_table :countries
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateStates < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :states, :force => true do |t|
|
4
|
+
t.string "name", :limit => 128, :default => "", :null => false
|
5
|
+
t.string "abbreviation", :limit => 3, :default => "", :null => false
|
6
|
+
t.integer "country_id", :limit => 8, :null => false
|
7
|
+
end
|
8
|
+
|
9
|
+
add_index :states, :country_id
|
10
|
+
add_index :states, :name
|
11
|
+
add_index :states, :abbreviation
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
drop_table :states
|
17
|
+
end
|
18
|
+
end
|
@@ -5,6 +5,7 @@ require 'test_help'
|
|
5
5
|
gem 'thoughtbot-factory_girl' # from github
|
6
6
|
require 'factory_girl'
|
7
7
|
require 'mocha'
|
8
|
+
require 'ruby-debug'
|
8
9
|
require 'redgreen' rescue LoadError
|
9
10
|
require File.expand_path(File.dirname(__FILE__) + '/factories')
|
10
11
|
require File.join(File.dirname(__FILE__), 'shoulda_macros', 'controller')
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class MuckEngineLocaleHelper
|
4
|
+
|
5
|
+
include ERB::Util
|
6
|
+
include ActionView::Helpers::TagHelper
|
7
|
+
include ActionView::Helpers::UrlHelper
|
8
|
+
include MuckEngineHelper
|
9
|
+
|
10
|
+
attr_accessor :request
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
class MuckEngineHelperTest < ActiveSupport::TestCase
|
15
|
+
|
16
|
+
context "locale_link" do
|
17
|
+
|
18
|
+
setup do
|
19
|
+
@lh = MuckEngineLocaleHelper.new
|
20
|
+
@lh.request = ActionController::TestRequest.new
|
21
|
+
end
|
22
|
+
|
23
|
+
should "prepend the locale to a domain without a subdomain" do
|
24
|
+
@lh.request.host = 'folksemantic.com'
|
25
|
+
assert_equal '<a href="http://es.folksemantic.com/">Espanol</a>', @lh.locale_link('Espanol','es')
|
26
|
+
end
|
27
|
+
|
28
|
+
should "use www as the subdomain when switching to english" do
|
29
|
+
@lh.request.host = 'es.folksemantic.com'
|
30
|
+
assert_equal '<a href="http://www.folksemantic.com/">English</a>', @lh.locale_link('English','en')
|
31
|
+
end
|
32
|
+
|
33
|
+
should "leave the path alone when prepending a locale subdomain" do
|
34
|
+
@lh.request.host = 'folksemantic.com'
|
35
|
+
@lh.request.request_uri = '/login'
|
36
|
+
assert_equal '<a href="http://es.folksemantic.com/login">Espanol</a>', @lh.locale_link('Espanol','es')
|
37
|
+
end
|
38
|
+
|
39
|
+
should "replace the www subdomain with the specified locale" do
|
40
|
+
@lh.request.host = 'www.folksemantic.com'
|
41
|
+
assert_equal '<a href="http://es.folksemantic.com/">Espanol</a>', @lh.locale_link('Espanol','es')
|
42
|
+
end
|
43
|
+
|
44
|
+
should "replace locale subdomains with the specified locale" do
|
45
|
+
@lh.request.host = 'fr.folksemantic.com'
|
46
|
+
assert_equal '<a href="http://es.folksemantic.com/">Espanol</a>', @lh.locale_link('Espanol','es')
|
47
|
+
end
|
48
|
+
|
49
|
+
should "specify the locale in the query string when the domain is localhost" do
|
50
|
+
@lh.request.host = 'localhost'
|
51
|
+
assert_equal '<a href="http://localhost/?locale=es">Espanol</a>', @lh.locale_link('Espanol','es')
|
52
|
+
end
|
53
|
+
|
54
|
+
should "leave the port alone when doing a locale rewrite" do
|
55
|
+
@lh.request.host = 'localhost'
|
56
|
+
@lh.request.port = '3000'
|
57
|
+
assert_equal '<a href="http://localhost:3000/?locale=es">Espanol</a>', @lh.locale_link('Espanol','es')
|
58
|
+
end
|
59
|
+
|
60
|
+
should "leave the port alone when doing a locale rewrite on a request that includes a path" do
|
61
|
+
@lh.request.host = 'localhost'
|
62
|
+
@lh.request.port = '3000'
|
63
|
+
@lh.request.request_uri = '/users/admin'
|
64
|
+
assert_equal '<a href="http://localhost:3000/users/admin?locale=es">Espanol</a>', @lh.locale_link('Espanol','es')
|
65
|
+
end
|
66
|
+
|
67
|
+
should "leave the port alone when doing a locale rewrite on a request that includes a path and already specifies a locale" do
|
68
|
+
@lh.request.host = 'localhost'
|
69
|
+
@lh.request.port = '3000'
|
70
|
+
@lh.request.request_uri = '/users/admin?locale=fr'
|
71
|
+
@lh.request.env['query_string'] = 'locale=fr'
|
72
|
+
assert_equal '<a href="http://localhost:3000/users/admin?locale=es">Espanol</a>', @lh.locale_link('Espanol','es')
|
73
|
+
end
|
74
|
+
|
75
|
+
should "leave the rest of the query string alone when replacing the locale parameter" do
|
76
|
+
@lh.request.host = 'localhost'
|
77
|
+
@lh.request.port = '3000'
|
78
|
+
@lh.request.request_uri = '/users/admin?test=false&locale=fr'
|
79
|
+
assert_equal '<a href="http://localhost:3000/users/admin?test=false&locale=es">Espanol</a>', @lh.locale_link('Espanol','es')
|
80
|
+
end
|
81
|
+
|
82
|
+
should "append the locale parameter when other query string parameters are specified" do
|
83
|
+
@lh.request.host = 'localhost'
|
84
|
+
@lh.request.port = '3000'
|
85
|
+
@lh.request.request_uri = '/users/admin?test=false'
|
86
|
+
assert_equal '<a href="http://localhost:3000/users/admin?test=false&locale=es">Espanol</a>', @lh.locale_link('Espanol','es')
|
87
|
+
end
|
88
|
+
|
89
|
+
should "replace the locale query parameter when working from localhost if another locale is already specified" do
|
90
|
+
@lh.request.host = 'localhost'
|
91
|
+
@lh.request.request_uri = '/login'
|
92
|
+
@lh.request.env['query_string'] = 'locale=fr'
|
93
|
+
assert_equal '<a href="http://localhost/login?locale=es">Espanol</a>', @lh.locale_link('Espanol','es')
|
94
|
+
end
|
95
|
+
|
96
|
+
should "specify the locale in the query string when the domain is an ip address" do
|
97
|
+
@lh.request.host = '155.23.322.13'
|
98
|
+
assert_equal '<a href="http://155.23.322.13/?locale=es">Espanol</a>', @lh.locale_link('Espanol','es')
|
99
|
+
end
|
100
|
+
|
101
|
+
should "prepend the locale if multiple submdomains are specified and the first is not www" do
|
102
|
+
@lh.request.host = 'math.folksemantic.com'
|
103
|
+
assert_equal '<a href="http://es.math.folksemantic.com/">Espanol</a>', @lh.locale_link('Espanol','es')
|
104
|
+
end
|
105
|
+
|
106
|
+
should "replace the www subdomain if multiple submdomains are specified and the first is www" do
|
107
|
+
@lh.request.host = 'www.math.folksemantic.com'
|
108
|
+
assert_equal '<a href="http://es.math.folksemantic.com/">Espanol</a>', @lh.locale_link('Espanol','es')
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: muck-engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.32
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Ball
|
@@ -303,6 +303,9 @@ files:
|
|
303
303
|
- test/rails_root/config/routes.rb
|
304
304
|
- test/rails_root/db/.keep
|
305
305
|
- test/rails_root/db/migrate/20090320174818_create_muck_permissions_and_roles.rb
|
306
|
+
- test/rails_root/db/migrate/20090402234137_create_languages.rb
|
307
|
+
- test/rails_root/db/migrate/20090426041056_create_countries.rb
|
308
|
+
- test/rails_root/db/migrate/20090426041103_create_states.rb
|
306
309
|
- test/rails_root/db/migrate/20090602041838_create_users.rb
|
307
310
|
- test/rails_root/features/step_definitions/webrat_steps.rb
|
308
311
|
- test/rails_root/features/support/env.rb
|
@@ -476,6 +479,7 @@ files:
|
|
476
479
|
- test/rails_root/test/test_helper.rb
|
477
480
|
- test/rails_root/test/unit/.keep
|
478
481
|
- test/rails_root/test/unit/basic_mailer_test.rb
|
482
|
+
- test/rails_root/test/unit/muck_engine_helper_test.rb
|
479
483
|
- test/rails_root/vendor/plugins/ssl_requirement/README
|
480
484
|
- test/rails_root/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb
|
481
485
|
- test/rails_root/vendor/plugins/ssl_requirement/test/ssl_requirement_test.rb
|
@@ -533,6 +537,9 @@ test_files:
|
|
533
537
|
- test/rails_root/config/initializers/session_store.rb
|
534
538
|
- test/rails_root/config/routes.rb
|
535
539
|
- test/rails_root/db/migrate/20090320174818_create_muck_permissions_and_roles.rb
|
540
|
+
- test/rails_root/db/migrate/20090402234137_create_languages.rb
|
541
|
+
- test/rails_root/db/migrate/20090426041056_create_countries.rb
|
542
|
+
- test/rails_root/db/migrate/20090426041103_create_states.rb
|
536
543
|
- test/rails_root/db/migrate/20090602041838_create_users.rb
|
537
544
|
- test/rails_root/features/step_definitions/webrat_steps.rb
|
538
545
|
- test/rails_root/features/support/env.rb
|
@@ -548,6 +555,7 @@ test_files:
|
|
548
555
|
- test/rails_root/test/shoulda_macros/plugins.rb
|
549
556
|
- test/rails_root/test/test_helper.rb
|
550
557
|
- test/rails_root/test/unit/basic_mailer_test.rb
|
558
|
+
- test/rails_root/test/unit/muck_engine_helper_test.rb
|
551
559
|
- test/rails_root/vendor/plugins/ssl_requirement/lib/ssl_requirement.rb
|
552
560
|
- test/rails_root/vendor/plugins/ssl_requirement/test/ssl_requirement_test.rb
|
553
561
|
- test/rails_root/vendor/plugins/validation_reflection/init.rb
|