Module: LocalizableRoutes::Extensions::ActionDispatch::Mapper
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/localizable_routes/extensions/action_dispatch/mapper.rb
Instance Method Summary collapse
- #add_route(action, options) ⇒ Object
- #initialize(set) ⇒ Object
- #localized(options) ⇒ Object
- #name_for_action(as, action) ⇒ Object
- #path_for_action(action, path) ⇒ Object
Instance Method Details
#add_route(action, options) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/localizable_routes/extensions/action_dispatch/mapper.rb', line 24 def add_route(action, ) if @localization @localization[:locales].each do |locale| = .dup [:constraints] ||= {} [:defaults] ||= {} strategy = @localization[:strategy] if strategy == :param @locale = locale [:constraints][:locale] = locale [:defaults][:locale] = locale else @locale = locale.second [:constraints][strategy] = locale.first [:defaults][strategy] = locale.first end super action, end @locale = nil if .fetch(:as, true) @set.named_routes.define_localized_url_helper( name_for_action([:as], action), @localization ) end else super end end |
#initialize(set) ⇒ Object
7 8 9 10 |
# File 'lib/localizable_routes/extensions/action_dispatch/mapper.rb', line 7 def initialize(set) super @localization = @locale = nil end |
#localized(options) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/localizable_routes/extensions/action_dispatch/mapper.rb', line 12 def localized() @localization = if [:strategy] == :param scope(':locale') do yield end else yield end @localization = nil end |
#name_for_action(as, action) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/localizable_routes/extensions/action_dispatch/mapper.rb', line 54 def name_for_action(as, action) candidate = super if candidate && @locale suffixed_candidate = "#{super}_#{@locale}" if !as.nil? || !@set.named_routes.routes.has_key?(suffixed_candidate.to_sym) suffixed_candidate end else candidate end end |
#path_for_action(action, path) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/localizable_routes/extensions/action_dispatch/mapper.rb', line 66 def path_for_action(action, path) candidate = super if candidate && @locale candidate.gsub(/:?[a-z0-9_-]+/) do |slug| if slug =~ /^[\:]/ slug else I18n.t "routes.#{slug.gsub('-', '_')}", locale: @locale.to_s, default: slug end end else candidate end end |