diff --git a/CHANGELOG.md b/CHANGELOG.md index 1096eea5..14196e38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 10.0.0 / 2021-01-16 * [BUGFIX] Verify host path consistency by default ([#91](https://github.com/enriclluelles/route_translator/issues/91), [#171](https://github.com/enriclluelles/route_translator/issues/171)) +* [FEATURE] Remove Engine support ([#166](https://github.com/enriclluelles/route_translator/issues/166), [#172](https://github.com/enriclluelles/route_translator/issues/172)) * [FEATURE] Remove the option to verify host path consistency * [ENHANCEMENT] Avoid duplicate routes when using host_locales ([#87](https://github.com/enriclluelles/route_translator/issues/87), [#171](https://github.com/enriclluelles/route_translator/issues/171)) * [ENHANCEMENT] Test against Ruby 3.0.0 diff --git a/lib/route_translator/extensions/mapper.rb b/lib/route_translator/extensions/mapper.rb index 9a58d2c1..8c475970 100644 --- a/lib/route_translator/extensions/mapper.rb +++ b/lib/route_translator/extensions/mapper.rb @@ -41,16 +41,6 @@ def add_route(action, controller, options, _path, to, via, formatted, anchor, op @set.add_localized_route(mapping, ast, as, anchor, @scope, path, controller, default_action, to, via, formatted, options_constraints, options) end # rubocop:enable Lint/UnderscorePrefixedVariableName, Metrics/PerceivedComplexity - - private - - def define_generate_prefix(app, name) - return super unless @localized - - RouteTranslator::Translator.available_locales.each do |locale| - super(app, "#{name}_#{locale.to_s.underscore}") - end - end end end end diff --git a/lib/route_translator/translator.rb b/lib/route_translator/translator.rb index e6820e9d..1f6ce90b 100644 --- a/lib/route_translator/translator.rb +++ b/lib/route_translator/translator.rb @@ -9,6 +9,15 @@ module Translator class << self private + def available_locales + locales = RouteTranslator.available_locales + # Make sure the default locale is translated in last place to avoid + # problems with wildcards when default locale is omitted in paths. The + # default routes will catch all paths like wildcard if it is translated first. + locales.delete I18n.default_locale + locales.push I18n.default_locale + end + def locale_from_args(args) args_hash = args.detect { |arg| arg.is_a?(Hash) } args_hash[:locale] if RouteTranslator.config.host_locales.present? && args_hash @@ -51,15 +60,6 @@ def translate_path(path, locale, scope) module_function - def available_locales - locales = RouteTranslator.available_locales - # Make sure the default locale is translated in last place to avoid - # problems with wildcards when default locale is omitted in paths. The - # default routes will catch all paths like wildcard if it is translated first. - locales.delete I18n.default_locale - locales.push I18n.default_locale - end - def translations_for(route) RouteTranslator::Translator::RouteHelpers.add route.name, route.route_set.named_routes diff --git a/test/dummy/app/controllers/blorgh/posts_controller.rb b/test/dummy/app/controllers/blorgh/posts_controller.rb deleted file mode 100644 index 12238385..00000000 --- a/test/dummy/app/controllers/blorgh/posts_controller.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -module Blorgh - class PostsController < ApplicationController - around_action :set_locale_from_url - - def index - render plain: I18n.locale - end - end -end diff --git a/test/dummy/app/controllers/dummy_controller.rb b/test/dummy/app/controllers/dummy_controller.rb index c4abadd5..5ce29dd9 100644 --- a/test/dummy/app/controllers/dummy_controller.rb +++ b/test/dummy/app/controllers/dummy_controller.rb @@ -15,14 +15,6 @@ def suffix render plain: params[:id] end - def engine_es - render plain: blorgh_es.posts_path - end - - def engine - render plain: blorgh.posts_path - end - def slash render plain: request.env['PATH_INFO'] end diff --git a/test/dummy/config/initializers/blorgh.rb b/test/dummy/config/initializers/blorgh.rb deleted file mode 100644 index 6bd62704..00000000 --- a/test/dummy/config/initializers/blorgh.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -module Blorgh - class Engine < Rails::Engine - isolate_namespace Blorgh - end -end - -Blorgh::Engine.routes.draw do - resources :posts, only: :index -end diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb index df0436a5..de041e44 100644 --- a/test/dummy/config/routes.rb +++ b/test/dummy/config/routes.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true Rails.application.routes.draw do - mount Blorgh::Engine, at: '/blorgh' - localized do get 'dummy', to: 'dummy#dummy' get 'show', to: 'dummy#show' @@ -19,15 +17,11 @@ namespace :account do root to: 'foo#account_root' end - - mount Blorgh::Engine, at: '/blorgh' end get 'unlocalized', to: 'dummy#unlocalized' get 'partial_caching', to: 'dummy#partial_caching' get 'native', to: 'dummy#native' - get 'engine_es', to: 'dummy#engine_es' - get 'engine', to: 'dummy#engine' root to: 'dummy#dummy' end diff --git a/test/integration/engine_test.rb b/test/integration/engine_test.rb deleted file mode 100644 index 98d6dc02..00000000 --- a/test/integration/engine_test.rb +++ /dev/null @@ -1,27 +0,0 @@ -# frozen_string_literal: true - -require 'test_helper' - -class RoutingTest < ActionDispatch::IntegrationTest - include RouteTranslator::ConfigurationHelper - - def test_with_engine_inside_localized_block - get '/engine_es' - assert_response :success - - url = - if Rails.version < '5.1.3' - '/blorgh/posts' - else - '/es/blorgh/posts' - end - - assert_equal url, response.body - end - - def test_with_engine_outside_localized_block - get '/engine' - assert_response :success - assert_equal '/blorgh/posts', response.body - end -end