Sha256: 5ade5a1c994f63d4f7d8b2c0d357bda1f1d66db956c0e74579c0cccd1e37a144

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

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

        def add_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]
                else
                  key = options[strategy]
                  locale = localization[:locales][key.to_s]
                end
                send "#{name}_#{locale || I18n.locale}_#{type}", *(args << options)
              end
            end
            instance_variable_get("@#{type}_helpers") << helper
          end
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
localizable_routes-5.1.2 lib/localizable_routes/extensions/action_dispatch/named_route_collection.rb