padrino-localization 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem "padrino"
4
- gem "i18n"
4
+ gem "localization-middleware"
5
+ gem "i18n"
5
6
 
6
7
  group :development, :test do
7
8
  gem "test-spec"
@@ -36,6 +36,8 @@ GEM
36
36
  addressable
37
37
  linecache (0.46)
38
38
  rbx-require-relative (> 0.0.4)
39
+ localization-middleware (0.1.0)
40
+ i18n
39
41
  mail (2.3.3)
40
42
  i18n (>= 0.4.0)
41
43
  mime-types (~> 1.16)
@@ -119,6 +121,7 @@ DEPENDENCIES
119
121
  debugger (~> 1.1.3)
120
122
  i18n
121
123
  jeweler (~> 1.6.4)
124
+ localization-middleware
122
125
  padrino
123
126
  rcov (~> 1.0.0)
124
127
  ruby-debug
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0
@@ -1,96 +1,8 @@
1
+ require 'localization-middleware'
2
+
1
3
  module Padrino
2
4
  module Localization
3
- class Middleware
4
- attr_reader :languages
5
- alias_method :langs, :languages
6
-
7
- class << self
8
- def languages
9
- @languages
10
- end
11
- end
12
-
13
- def initialize(app, langs)
14
- @app = app
15
- self.languages = langs
16
- end
17
-
18
- def call(env)
19
- @env = env
20
- set_locale
21
- response_array = @app.call(@env)
22
- unset_locale
23
- response_array
24
- end
25
-
26
- private
27
-
28
- def languages= langs
29
- @languages = langs.collect do |l|
30
- raise ArgumentError.new("An arguments should be 2 latters long") unless l.to_s =~ /\A[a-z]{2}\Z/i
31
- l.to_s
32
- end
33
- self.class.instance_variable_set :@languages, @languages
34
- @languages
35
- end
36
- alias_method :langs=, :languages=
37
-
38
- def locale_pattern
39
- @locale_pattern ||= /\A(?:\/(#{langs.join('|')}))?(\/?.*|)/i
40
- end
41
-
42
- def set_locale
43
- ::I18n.locale = locale_from_url.to_sym if locale_defined_in_url?
44
- end
45
-
46
- def unset_locale
47
- ::I18n.locale = ::I18n.default_locale if locale_defined_in_url?
48
- @locale_set = @locale = nil
49
- end
50
-
51
- ###
52
- # Determine locale from the request URL and return it as a string, it it
53
- # is matching any of provided locales
54
- # If locale matching failed an empty String will be returned.
55
- #
56
- # Examples:
57
- #
58
- # #http://www.example.com/se
59
- # locale_from_url # => 'se'
60
- #
61
- # #http://www.example.com/de/posts
62
- # locale_from_url # => 'se'
63
- #
64
- # #http://www.example.com/ursers
65
- # locale_from_url # => ''
66
- #
67
- def locale_from_url path_info = nil
68
- @locale_set ||= begin
69
- @locale ||= (match = (path_info || @env['PATH_INFO']).match(locale_pattern)) ? match[1] : nil
70
- @env['PATH_INFO'] = match[2] if match && @env.try(:fetch, 'PATH_INFO')
71
- true
72
- end
73
- @locale
74
- end
75
-
76
- ###
77
- # Try to determine, weather the locale is defined, from request URL, if it is matching any of
78
- # provided locales, and returns boolean as a result.
79
- #
80
- # Examples:
81
- #
82
- # #http://www.example.com/se
83
- # locale_from_url # => true
84
- #
85
- # #http://www.example.com/de/posts
86
- # locale_from_url # => true
87
- #
88
- # #http://www.example.com/ursers
89
- # locale_from_url # => false
90
- #
91
- def locale_defined_in_url?
92
- !locale_from_url.blank?
93
- end
5
+ class Middleware < ::Localization::Middleware
94
6
  end
95
7
  end
96
8
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "padrino-localization"
8
- s.version = "0.1.3"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["kot-begemot"]
12
- s.date = "2012-08-20"
12
+ s.date = "2012-08-26"
13
13
  s.description = "This gem allows you to localalize your padrino application with ease"
14
14
  s.email = "max@studentify.nl"
15
15
  s.extra_rdoc_files = [
@@ -53,6 +53,7 @@ Gem::Specification.new do |s|
53
53
 
54
54
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
55
  s.add_runtime_dependency(%q<padrino>, [">= 0"])
56
+ s.add_runtime_dependency(%q<localization-middleware>, [">= 0"])
56
57
  s.add_runtime_dependency(%q<i18n>, [">= 0"])
57
58
  s.add_development_dependency(%q<test-spec>, [">= 0"])
58
59
  s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
@@ -65,6 +66,7 @@ Gem::Specification.new do |s|
65
66
  s.add_development_dependency(%q<capybara>, [">= 0"])
66
67
  else
67
68
  s.add_dependency(%q<padrino>, [">= 0"])
69
+ s.add_dependency(%q<localization-middleware>, [">= 0"])
68
70
  s.add_dependency(%q<i18n>, [">= 0"])
69
71
  s.add_dependency(%q<test-spec>, [">= 0"])
70
72
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
@@ -78,6 +80,7 @@ Gem::Specification.new do |s|
78
80
  end
79
81
  else
80
82
  s.add_dependency(%q<padrino>, [">= 0"])
83
+ s.add_dependency(%q<localization-middleware>, [">= 0"])
81
84
  s.add_dependency(%q<i18n>, [">= 0"])
82
85
  s.add_dependency(%q<test-spec>, [">= 0"])
83
86
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-localization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-20 00:00:00.000000000Z
12
+ date: 2012-08-26 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: padrino
16
- requirement: &85254750 !ruby/object:Gem::Requirement
16
+ requirement: &75672620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *85254750
24
+ version_requirements: *75672620
25
+ - !ruby/object:Gem::Dependency
26
+ name: localization-middleware
27
+ requirement: &75672080 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *75672080
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: i18n
27
- requirement: &85202010 !ruby/object:Gem::Requirement
38
+ requirement: &75671540 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: '0'
33
44
  type: :runtime
34
45
  prerelease: false
35
- version_requirements: *85202010
46
+ version_requirements: *75671540
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: test-spec
38
- requirement: &85201580 !ruby/object:Gem::Requirement
49
+ requirement: &75671000 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: '0'
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *85201580
57
+ version_requirements: *75671000
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: yard
49
- requirement: &85201180 !ruby/object:Gem::Requirement
60
+ requirement: &75670650 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ~>
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: 0.6.0
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *85201180
68
+ version_requirements: *75670650
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: bundler
60
- requirement: &85200740 !ruby/object:Gem::Requirement
71
+ requirement: &75670280 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ~>
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: 1.0.0
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *85200740
79
+ version_requirements: *75670280
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: jeweler
71
- requirement: &85200330 !ruby/object:Gem::Requirement
82
+ requirement: &75669870 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ~>
@@ -76,10 +87,10 @@ dependencies:
76
87
  version: 1.6.4
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *85200330
90
+ version_requirements: *75669870
80
91
  - !ruby/object:Gem::Dependency
81
92
  name: debugger
82
- requirement: &85199870 !ruby/object:Gem::Requirement
93
+ requirement: &75669510 !ruby/object:Gem::Requirement
83
94
  none: false
84
95
  requirements:
85
96
  - - ~>
@@ -87,10 +98,10 @@ dependencies:
87
98
  version: 1.1.3
88
99
  type: :development
89
100
  prerelease: false
90
- version_requirements: *85199870
101
+ version_requirements: *75669510
91
102
  - !ruby/object:Gem::Dependency
92
103
  name: simplecov
93
- requirement: &85199470 !ruby/object:Gem::Requirement
104
+ requirement: &75669200 !ruby/object:Gem::Requirement
94
105
  none: false
95
106
  requirements:
96
107
  - - ~>
@@ -98,10 +109,10 @@ dependencies:
98
109
  version: 0.6.4
99
110
  type: :development
100
111
  prerelease: false
101
- version_requirements: *85199470
112
+ version_requirements: *75669200
102
113
  - !ruby/object:Gem::Dependency
103
114
  name: ruby-debug
104
- requirement: &85199090 !ruby/object:Gem::Requirement
115
+ requirement: &75668880 !ruby/object:Gem::Requirement
105
116
  none: false
106
117
  requirements:
107
118
  - - ! '>='
@@ -109,10 +120,10 @@ dependencies:
109
120
  version: '0'
110
121
  type: :development
111
122
  prerelease: false
112
- version_requirements: *85199090
123
+ version_requirements: *75668880
113
124
  - !ruby/object:Gem::Dependency
114
125
  name: rcov
115
- requirement: &85198690 !ruby/object:Gem::Requirement
126
+ requirement: &75668420 !ruby/object:Gem::Requirement
116
127
  none: false
117
128
  requirements:
118
129
  - - ~>
@@ -120,10 +131,10 @@ dependencies:
120
131
  version: 1.0.0
121
132
  type: :development
122
133
  prerelease: false
123
- version_requirements: *85198690
134
+ version_requirements: *75668420
124
135
  - !ruby/object:Gem::Dependency
125
136
  name: capybara
126
- requirement: &85198280 !ruby/object:Gem::Requirement
137
+ requirement: &75622500 !ruby/object:Gem::Requirement
127
138
  none: false
128
139
  requirements:
129
140
  - - ! '>='
@@ -131,7 +142,7 @@ dependencies:
131
142
  version: '0'
132
143
  type: :development
133
144
  prerelease: false
134
- version_requirements: *85198280
145
+ version_requirements: *75622500
135
146
  description: This gem allows you to localalize your padrino application with ease
136
147
  email: max@studentify.nl
137
148
  executables: []
@@ -179,7 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
190
  version: '0'
180
191
  segments:
181
192
  - 0
182
- hash: -154014833
193
+ hash: 474849517
183
194
  required_rubygems_version: !ruby/object:Gem::Requirement
184
195
  none: false
185
196
  requirements: