Sha256: f9801dc65d3b970a7892947797a248e8977ae886303bd7b2bcecb1df3446cfeb

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

module LocalizableRoutes
  module Extensions
    module ActionDispatch
      module NamedRouteCollection
        extend ActiveSupport::Concern

        def define_localized_url_helper(name, localization)
          %w(path url).each do |type|
            helper = :"#{name}_#{type}"
            target = instance_variable_get("@#{type}_helpers_module")
            target.remove_possible_method helper
            target.module_eval do
              define_method helper do |*args|
                options = args.extract_options!
                strategy = localization[:strategy]
                if strategy == :param
                  locale = (options[:locale] || url_options[:locale] || I18n.locale)
                else
                  key = (options[strategy] || url_options[strategy])
                  locale = localization[:locales][key.to_s]
                end
                send "#{name}_#{locale}_#{type}", *(args << options)
              end
            end
            instance_variable_get("@#{type}_helpers") << helper
          end
        end

      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
localizable_routes-4.0.0.1 lib/localizable_routes/extensions/action_dispatch/named_route_collection.rb
localizable_routes-4.0.0.0 lib/localizable_routes/extensions/action_dispatch/named_route_collection.rb
localizable_routes-2.1.0 lib/localizable_routes/extensions/action_dispatch/named_route_collection.rb