i18n-inflector-rails 0.1.0 → 0.2.0
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.tar.gz.sig +0 -0
- data/ChangeLog +18 -0
- data/Gemfile +3 -4
- data/Manifest.txt +1 -0
- data/README.rdoc +1 -1
- data/Rakefile +8 -5
- data/docs/HISTORY +7 -1
- data/i18n-inflector-rails.gemspec +3 -3
- data/lib/i18n-inflector-rails.rb +3 -0
- data/lib/i18n-inflector-rails/inflector.rb +24 -8
- data/lib/i18n-inflector-rails/options.rb +52 -0
- data/lib/i18n-inflector-rails/version.rb +2 -2
- data/spec/inflector_spec.rb +35 -2
- metadata +12 -29
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/ChangeLog
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
commit 15e330e957f34579fa95aa2036f0c06fd168ab54
|
2
|
+
Author: Paweł Wilk <siefca@gnu.org>
|
3
|
+
Date: Sun Jan 16 07:06:57 2011 +0100
|
4
|
+
|
5
|
+
Documentation updated
|
6
|
+
|
7
|
+
commit e10a3bbbc25c053529976d82a0304819b7235213
|
8
|
+
Author: Paweł Wilk <siefca@gnu.org>
|
9
|
+
Date: Sun Jan 16 07:02:19 2011 +0100
|
10
|
+
|
11
|
+
additional_options.rb renamed to options.rb, HISTORY updated
|
12
|
+
|
13
|
+
commit 097cc40da6bd9edec7231dd96a7b3197c5133888
|
14
|
+
Author: Paweł Wilk <siefca@gnu.org>
|
15
|
+
Date: Sun Jan 16 06:46:28 2011 +0100
|
16
|
+
|
17
|
+
Added conditional checking if method to be called exists, dependencies fixed
|
18
|
+
|
1
19
|
commit 807a61dea750e19bd52fb350d34609e259557bbd
|
2
20
|
Author: Paweł Wilk <siefca@gnu.org>
|
3
21
|
Date: Fri Jan 14 18:05:40 2011 +0100
|
data/Gemfile
CHANGED
@@ -2,16 +2,15 @@
|
|
2
2
|
|
3
3
|
source :gemcutter
|
4
4
|
|
5
|
-
gem "i18n-inflector", "~>2.0
|
6
|
-
gem "railties", "~>3.0
|
7
|
-
gem "actionpack", "~>3.0
|
5
|
+
gem "i18n-inflector", "~>2.0"
|
6
|
+
gem "railties", "~>3.0"
|
7
|
+
gem "actionpack", "~>3.0"
|
8
8
|
|
9
9
|
gem "hoe-yard", ">=0.1.2", :group => [:development, :test]
|
10
10
|
gem "rspec", ">=2.3.0", :group => [:development, :test]
|
11
11
|
gem "yard", ">=0.6.4", :group => [:development, :test]
|
12
12
|
gem "bundler", ">=1.0.7", :group => [:development, :test]
|
13
13
|
gem "hoe-bundler", ">=1.0.0", :group => [:development, :test]
|
14
|
-
gem "hoe-yard", ">=0.1.2", :group => [:development, :test]
|
15
14
|
gem "hoe", ">=2.8.0", :group => [:development, :test]
|
16
15
|
|
17
16
|
# vim: syntax=ruby
|
data/Manifest.txt
CHANGED
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -41,14 +41,17 @@ Hoe.spec 'i18n-inflector-rails' do
|
|
41
41
|
self.readme_file = 'README.rdoc'
|
42
42
|
self.history_file = 'docs/HISTORY'
|
43
43
|
|
44
|
-
extra_deps << ['i18n-inflector', '~> 2.0
|
45
|
-
['railties', '~> 3.0
|
46
|
-
['actionpack', '~> 3.0
|
44
|
+
extra_deps << ['i18n-inflector', '~> 2.0'] <<
|
45
|
+
['railties', '~> 3.0'] <<
|
46
|
+
['actionpack', '~> 3.0']
|
47
47
|
extra_dev_deps << ['rspec', '>= 2.3.0'] <<
|
48
48
|
['yard', '>= 0.6.4'] <<
|
49
49
|
['bundler', '>= 1.0.7'] <<
|
50
|
-
['hoe-bundler', '>= 1.0.0']
|
51
|
-
|
50
|
+
['hoe-bundler', '>= 1.0.0']
|
51
|
+
|
52
|
+
unless extra_dev_deps.flatten.include?('hoe-yard')
|
53
|
+
extra_dev_deps << ['hoe-yard', '>= 0.1.2']
|
54
|
+
end
|
52
55
|
end
|
53
56
|
|
54
57
|
task 'Manifest.txt' do
|
data/docs/HISTORY
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
+
=== 0.2.0 / 2011-01-15
|
2
|
+
|
3
|
+
* 1 major enhancement
|
4
|
+
|
5
|
+
* Added switch that causes any method from current context to be tested if is callable
|
6
|
+
|
1
7
|
=== 0.1.0 / 2011-01-11
|
2
8
|
|
3
9
|
* 2 major enhancements
|
4
10
|
|
5
11
|
* Compatible with Rails 3
|
6
|
-
* no_inflection_method added
|
12
|
+
* no_inflection_method added; it disables previously added method from using by translate()
|
7
13
|
|
8
14
|
=== 0.0.1 / 2011-01-02
|
9
15
|
|
@@ -25,9 +25,9 @@ Gem::Specification.new do |s|
|
|
25
25
|
s.required_rubygems_version = '>= 1.3.5'
|
26
26
|
s.specification_version = 3
|
27
27
|
|
28
|
-
s.add_dependency 'i18n-inflector', '~> 2.0
|
29
|
-
s.add_dependency 'railties', '~> 3.0
|
30
|
-
s.add_dependency 'actionpack', '~> 3.0
|
28
|
+
s.add_dependency 'i18n-inflector', '~> 2.0'
|
29
|
+
s.add_dependency 'railties', '~> 3.0'
|
30
|
+
s.add_dependency 'actionpack', '~> 3.0'
|
31
31
|
s.add_development_dependency 'rspec', '>= 2.3.0'
|
32
32
|
s.add_development_dependency 'yard', '>= 1.0.7'
|
33
33
|
s.add_development_dependency 'hoe-bundler', '>= 1.0.0'
|
data/lib/i18n-inflector-rails.rb
CHANGED
@@ -3,8 +3,11 @@
|
|
3
3
|
require 'i18n-inflector'
|
4
4
|
require 'i18n-inflector-rails/version'
|
5
5
|
require 'i18n-inflector-rails/errors'
|
6
|
+
require 'i18n-inflector-rails/options'
|
6
7
|
require 'i18n-inflector-rails/inflector'
|
7
8
|
|
9
|
+
I18n::Inflector::InflectionOptions.send(:include, I18n::Inflector::Rails::AdditionalOptions)
|
10
|
+
|
8
11
|
if defined? Rails::Engine
|
9
12
|
|
10
13
|
require 'i18n-inflector-rails/railtie'
|
@@ -143,21 +143,35 @@ module I18n
|
|
143
143
|
# @return [String] the translated string with inflection patterns
|
144
144
|
# interpolated
|
145
145
|
def translate(*args)
|
146
|
-
|
146
|
+
opts_present = args.last.is_a?(Hash)
|
147
|
+
if opts_present
|
148
|
+
options = args.last
|
149
|
+
test_locale = options[:locale]
|
150
|
+
else
|
151
|
+
options = {}
|
152
|
+
end
|
147
153
|
test_locale ||= I18n.locale
|
148
|
-
|
154
|
+
inflector = I18n.backend.inflector
|
155
|
+
|
156
|
+
# use standard translate if the locale is not supported
|
157
|
+
return super unless inflector.inflected_locale?(test_locale)
|
158
|
+
|
159
|
+
# read switch
|
160
|
+
verifies = options.delete(:inflector_verify_methods)
|
161
|
+
verifies = verifies.nil? ? inflector.options.verify_methods : verifies
|
149
162
|
|
150
163
|
# collect inflection variables that are present in this context
|
151
|
-
subopts
|
164
|
+
subopts = t_prepare_inflection_options(inflector, verifies)
|
152
165
|
|
153
166
|
# jump to original translate if no variables are present
|
154
167
|
return super if subopts.empty?
|
155
|
-
|
156
|
-
|
168
|
+
|
169
|
+
# pass options
|
170
|
+
args.pop if opts_present
|
157
171
|
args.push subopts.merge(options)
|
158
172
|
super
|
159
173
|
end
|
160
|
-
|
174
|
+
|
161
175
|
alias_method :t, :translate
|
162
176
|
|
163
177
|
protected
|
@@ -165,10 +179,12 @@ module I18n
|
|
165
179
|
# This method tries to read +i18n_inflector_methods+ available in the current context.
|
166
180
|
#
|
167
181
|
# @return [Hash] the inflection options (<tt>kind => value</tt>)
|
168
|
-
def t_prepare_inflection_options
|
182
|
+
def t_prepare_inflection_options(inflector, verifies)
|
169
183
|
subopts = {}
|
184
|
+
return subopts if (verifies && !respond_to?(:i18n_inflector_methods))
|
170
185
|
i18n_inflector_methods.each_pair do |m, obj|
|
171
|
-
next if obj.nil?
|
186
|
+
next if obj.nil? # method registered but disabled from usage
|
187
|
+
next if (verifies && !respond_to?(m)) # verify_methods enabled
|
172
188
|
value = method(m).call
|
173
189
|
proca = obj[:proc]
|
174
190
|
kind = obj[:kind]
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
#
|
3
|
+
# Author:: Paweł Wilk (mailto:pw@gnu.org)
|
4
|
+
# Copyright:: (c) 2011 by Paweł Wilk
|
5
|
+
# License:: This program is licensed under the terms of {file:LGPL-LICENSE GNU Lesser General Public License} or {file:COPYING Ruby License}.
|
6
|
+
#
|
7
|
+
# This file contains I18n::Inflector::Rails::AdditionalOptions module,
|
8
|
+
# which extends I18n::Inflector::InflectionOptions so new switches controlling
|
9
|
+
# inflector's behavior are available.
|
10
|
+
|
11
|
+
module I18n
|
12
|
+
module Inflector
|
13
|
+
module Rails
|
14
|
+
|
15
|
+
# This module adds options to {I18n::Inflector::InflectionOptions}
|
16
|
+
module AdditionalOptions
|
17
|
+
|
18
|
+
attr_writer :verify_methods
|
19
|
+
|
20
|
+
# When this is set to +true+ then
|
21
|
+
# inflection works a bit slower but
|
22
|
+
# checks whether any method exists before
|
23
|
+
# calling it. This switch is by default set
|
24
|
+
# to +false+.
|
25
|
+
#
|
26
|
+
# By turning this switch on you're sure that
|
27
|
+
# there will be no +NameError+ (no method) exception
|
28
|
+
# raised during translation.
|
29
|
+
#
|
30
|
+
# Alternatively you can turn this locally,
|
31
|
+
# for the specified translate call, by setting
|
32
|
+
# <tt>:inflector_verify_methods</tt> option to +true+.
|
33
|
+
#
|
34
|
+
# @example Globally enabling methods verification
|
35
|
+
# I18n.inflector.options.verify_methods = true
|
36
|
+
# @example Locally enabling methods verification
|
37
|
+
# translate('welcome', :inflector_verify_methods => true)
|
38
|
+
def verify_methods
|
39
|
+
@verify_methods || false
|
40
|
+
end
|
41
|
+
|
42
|
+
# This method resets inflector's
|
43
|
+
# switches to default values.
|
44
|
+
def reset
|
45
|
+
@verify_methods = false
|
46
|
+
super
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -15,7 +15,7 @@ module I18n
|
|
15
15
|
# @private
|
16
16
|
EMAIL = 'pw@gnu.org'
|
17
17
|
# @private
|
18
|
-
VERSION = '0.
|
18
|
+
VERSION = '0.2.0'
|
19
19
|
# @private
|
20
20
|
NAME = 'i18n-inflector-rails'
|
21
21
|
# @private
|
@@ -23,7 +23,7 @@ module I18n
|
|
23
23
|
# @private
|
24
24
|
URL = 'https://rubygems.org/gems/i18n-inflector-rails/'
|
25
25
|
# @private
|
26
|
-
DESCRIPTION = '
|
26
|
+
DESCRIPTION = 'Plug-in that provides I18n Inflector module integration with Rails.'
|
27
27
|
|
28
28
|
end
|
29
29
|
end
|
data/spec/inflector_spec.rb
CHANGED
@@ -3,6 +3,22 @@ require 'spec_helper'
|
|
3
3
|
class ApplicationController < ActionController::Base; end
|
4
4
|
class InflectedTranslateController < ApplicationController; end
|
5
5
|
|
6
|
+
describe I18n.inflector.options.class do
|
7
|
+
|
8
|
+
context "instance I18n.inflector.options" do
|
9
|
+
|
10
|
+
it "should contain verify_methods switch" do
|
11
|
+
I18n.inflector.options.should respond_to :verify_methods
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have default value set to false" do
|
15
|
+
I18n.inflector.options.verify_methods.should == false
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
6
22
|
describe ApplicationController do
|
7
23
|
|
8
24
|
before do
|
@@ -28,7 +44,7 @@ describe ApplicationController do
|
|
28
44
|
I18n.backend.store_translations(:xx, 'to_be' => 'Oh @{i:I am|you:You are|it:It is}')
|
29
45
|
|
30
46
|
end
|
31
|
-
|
47
|
+
|
32
48
|
describe ".inflection_method" do
|
33
49
|
|
34
50
|
before do
|
@@ -145,10 +161,17 @@ describe ApplicationController do
|
|
145
161
|
inflection_method :person
|
146
162
|
end
|
147
163
|
|
164
|
+
class NomethodController < InflectedTranslateController
|
165
|
+
inflection_method :nonexistent => :gender
|
166
|
+
def translate_male; translate('welcome') end
|
167
|
+
def translate_male_opt; translate('welcome', :inflector_verify_methods => true) end
|
168
|
+
end
|
169
|
+
|
148
170
|
@controller = InflectedTranslateController.new
|
149
171
|
@person_controller = InflectedLambdedController.new
|
150
172
|
@personprim_controller = InflectedLambdedPrimController.new
|
151
|
-
|
173
|
+
@nomethod_controller = NomethodController.new
|
174
|
+
|
152
175
|
@expected_hash = {:users_gender=>{:kind=>:gender, :proc=>nil},
|
153
176
|
:time=>{:kind=>:time, :proc=>nil}}
|
154
177
|
|
@@ -186,6 +209,16 @@ describe ApplicationController do
|
|
186
209
|
@person_controller.translated_person.should == 'Oh It is'
|
187
210
|
end
|
188
211
|
|
212
|
+
it "should raise exception when method does not exists" do
|
213
|
+
lambda{@nomethod_controller.translated_male}.should raise_error(NameError)
|
214
|
+
end
|
215
|
+
|
216
|
+
it "should not raise when method does not exists and verify_methods is enabled" do
|
217
|
+
lambda{@nomethod_controller.translate_male_opt}.should_not raise_error(NameError)
|
218
|
+
I18n.inflector.options.verify_methods = true
|
219
|
+
lambda{@nomethod_controller.translate_male}.should_not raise_error(NameError)
|
220
|
+
end
|
221
|
+
|
189
222
|
end
|
190
223
|
|
191
224
|
describe "#t" do
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Pawe\xC5\x82 Wilk"
|
@@ -34,7 +34,7 @@ cert_chain:
|
|
34
34
|
NK3TIZaPCh1S2/ES6wXNvjQ+5EnEEL9j/pSEop9DYEBPaM2WDVR5i0jJTAaRWw==
|
35
35
|
-----END CERTIFICATE-----
|
36
36
|
|
37
|
-
date: 2011-01-
|
37
|
+
date: 2011-01-16 00:00:00 +01:00
|
38
38
|
default_executable:
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
@@ -47,8 +47,7 @@ dependencies:
|
|
47
47
|
segments:
|
48
48
|
- 2
|
49
49
|
- 0
|
50
|
-
|
51
|
-
version: 2.0.0
|
50
|
+
version: "2.0"
|
52
51
|
type: :runtime
|
53
52
|
prerelease: false
|
54
53
|
version_requirements: *id001
|
@@ -62,8 +61,7 @@ dependencies:
|
|
62
61
|
segments:
|
63
62
|
- 3
|
64
63
|
- 0
|
65
|
-
|
66
|
-
version: 3.0.0
|
64
|
+
version: "3.0"
|
67
65
|
type: :runtime
|
68
66
|
prerelease: false
|
69
67
|
version_requirements: *id002
|
@@ -77,8 +75,7 @@ dependencies:
|
|
77
75
|
segments:
|
78
76
|
- 3
|
79
77
|
- 0
|
80
|
-
|
81
|
-
version: 3.0.0
|
78
|
+
version: "3.0"
|
82
79
|
type: :runtime
|
83
80
|
prerelease: false
|
84
81
|
version_requirements: *id003
|
@@ -157,24 +154,9 @@ dependencies:
|
|
157
154
|
type: :development
|
158
155
|
prerelease: false
|
159
156
|
version_requirements: *id008
|
160
|
-
- !ruby/object:Gem::Dependency
|
161
|
-
name: hoe-yard
|
162
|
-
requirement: &id009 !ruby/object:Gem::Requirement
|
163
|
-
none: false
|
164
|
-
requirements:
|
165
|
-
- - ">="
|
166
|
-
- !ruby/object:Gem::Version
|
167
|
-
segments:
|
168
|
-
- 0
|
169
|
-
- 1
|
170
|
-
- 2
|
171
|
-
version: 0.1.2
|
172
|
-
type: :development
|
173
|
-
prerelease: false
|
174
|
-
version_requirements: *id009
|
175
157
|
- !ruby/object:Gem::Dependency
|
176
158
|
name: hoe
|
177
|
-
requirement: &
|
159
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
178
160
|
none: false
|
179
161
|
requirements:
|
180
162
|
- - ">="
|
@@ -186,8 +168,8 @@ dependencies:
|
|
186
168
|
version: 2.8.0
|
187
169
|
type: :development
|
188
170
|
prerelease: false
|
189
|
-
version_requirements: *
|
190
|
-
description:
|
171
|
+
version_requirements: *id009
|
172
|
+
description: Plug-in that provides I18n Inflector module integration with Rails.
|
191
173
|
email:
|
192
174
|
- pw@gnu.org
|
193
175
|
executables: []
|
@@ -216,6 +198,7 @@ files:
|
|
216
198
|
- lib/i18n-inflector-rails.rb
|
217
199
|
- lib/i18n-inflector-rails/errors.rb
|
218
200
|
- lib/i18n-inflector-rails/inflector.rb
|
201
|
+
- lib/i18n-inflector-rails/options.rb
|
219
202
|
- lib/i18n-inflector-rails/railtie.rb
|
220
203
|
- lib/i18n-inflector-rails/version.rb
|
221
204
|
- spec/inflector_spec.rb
|
@@ -236,7 +219,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
236
219
|
requirements:
|
237
220
|
- - ">="
|
238
221
|
- !ruby/object:Gem::Version
|
239
|
-
hash:
|
222
|
+
hash: 2397947838501194867
|
240
223
|
segments:
|
241
224
|
- 0
|
242
225
|
version: "0"
|
@@ -245,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
245
228
|
requirements:
|
246
229
|
- - ">="
|
247
230
|
- !ruby/object:Gem::Version
|
248
|
-
hash:
|
231
|
+
hash: 2397947838501194867
|
249
232
|
segments:
|
250
233
|
- 0
|
251
234
|
version: "0"
|
metadata.gz.sig
CHANGED
Binary file
|