Class: RoutingFilter::Locale
- Inherits:
-
Filter
- Object
- Filter
- RoutingFilter::Locale
show all
- Defined in:
- lib/routing_filter/filters/locale.rb
Constant Summary
collapse
- @@include_default_locale =
true
Instance Attribute Summary
Attributes inherited from Filter
#next, #options, #previous
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Filter
#initialize, #run, #run_reverse
Class Method Details
.include_default_locale? ⇒ Boolean
31
32
33
|
# File 'lib/routing_filter/filters/locale.rb', line 31
def include_default_locale?
@@include_default_locale
end
|
.locales ⇒ Object
35
36
37
|
# File 'lib/routing_filter/filters/locale.rb', line 35
def locales
@@locales ||= I18n.available_locales.map(&:to_sym)
end
|
.locales=(locales) ⇒ Object
39
40
41
|
# File 'lib/routing_filter/filters/locale.rb', line 39
def locales=(locales)
@@locales = locales.map(&:to_sym)
end
|
.locales_pattern ⇒ Object
43
44
45
|
# File 'lib/routing_filter/filters/locale.rb', line 43
def locales_pattern
@@locales_pattern ||= %r(^/(#{self.locales.map { |l| Regexp.escape(l.to_s) }.join('|')})(?=/|$))
end
|
Instance Method Details
#around_generate(*args, &block) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/routing_filter/filters/locale.rb', line 55
def around_generate(*args, &block)
params = args.
locale = params.delete(:locale) locale = I18n.locale if locale.nil? locale = nil unless valid_locale?(locale)
args << params
yield.tap do |result|
prepend_segment!(result, locale) if prepend_locale?(locale)
end
end
|
#around_recognize(path, env, &block) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/routing_filter/filters/locale.rb', line 48
def around_recognize(path, env, &block)
locale = (self.class.locales_pattern, path) yield.tap do |params| params[:locale] = locale if locale end
end
|