From c0e4291745c8e2799bf786d578ea02cc0c72330f Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Fri, 20 Sep 2024 20:10:04 -0700 Subject: [PATCH] Remove FragmentLocalization and localized_cache helper We replace the `localized_cache` helper with just simple keys provided to the `cache` helper, with `locale=#{I18n.locale}` inlined. End of an era! --- app/controllers/application_controller.rb | 8 +++----- app/helpers/application_helper.rb | 9 --------- app/views/items/index.html.haml | 2 +- app/views/outfits/new.html.haml | 2 +- lib/fragment_localization.rb | 11 ----------- 5 files changed, 5 insertions(+), 27 deletions(-) delete mode 100644 lib/fragment_localization.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2d383695..cc7746e5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,12 +2,10 @@ require 'async' require 'async/container' class ApplicationController < ActionController::Base - include FragmentLocalization - protect_from_forgery helper_method :current_user, :user_signed_in? - + before_action :set_locale before_action :configure_permitted_parameters, if: :devise_controller? @@ -45,7 +43,7 @@ class ApplicationController < ActionController::Base def user_signed_in? auth_user_signed_in? end - + def infer_locale return params[:locale] if valid_locale?(params[:locale]) return cookies[:locale] if valid_locale?(cookies[:locale]) @@ -53,7 +51,7 @@ class ApplicationController < ActionController::Base http_accept_language.language_region_compatible_from(I18n.available_locales.map(&:to_s)) || I18n.default_locale end - + def not_found(record_name='record') raise ActionController::RoutingError.new("#{record_name} not found") end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 33e72149..91f870c8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,6 +1,4 @@ module ApplicationHelper - include FragmentLocalization - def absolute_url(path_or_url) if path_or_url.include?('://') # already an absolute URL path_or_url @@ -165,13 +163,6 @@ module ApplicationHelper options end - - def localized_cache(key={}, &block) - localized_key = localize_fragment_key(key, locale) - # TODO: The digest feature is handy, but it's not compatible with how we - # check for fragments existence in the controller, so skip it for now. - cache(localized_key, skip_digest: true, &block) - end def auth_user_sign_in_path_with_return_to new_auth_user_session_path :return_to => request.fullpath diff --git a/app/views/items/index.html.haml b/app/views/items/index.html.haml index 517049d7..e33147a6 100644 --- a/app/views/items/index.html.haml +++ b/app/views/items/index.html.haml @@ -31,7 +31,7 @@ %h2= t '.newest_items.header' = render @newest_items - - localized_cache :action_suffix => 'species_search_links' do + - cache "items/index species_search_links locale=#{I18n.locale}" do #species-search-links %h2= t '.species_search.header' = standard_species_search_links diff --git a/app/views/outfits/new.html.haml b/app/views/outfits/new.html.haml index ee324e63..3aca7cd4 100644 --- a/app/views/outfits/new.html.haml +++ b/app/views/outfits/new.html.haml @@ -90,7 +90,7 @@ %h3= t '.newest_items.unmodeled.header' %ul#newest-unmodeled-items - @newest_unmodeled_items.each do |item| - - localized_cache "items/#{item.id} modeling_progress updated_at=#{item.updated_at.to_i}" do + - cache "items/#{item.id} modeling_progress locale=#{I18n.locale} updated_at=#{item.updated_at.to_i}" do %li{'data-item-id' => item.id} = link_to image_tag(item.thumbnail_url), item, :class => 'image-link' = link_to item, :class => 'header' do diff --git a/lib/fragment_localization.rb b/lib/fragment_localization.rb deleted file mode 100644 index 012e14a4..00000000 --- a/lib/fragment_localization.rb +++ /dev/null @@ -1,11 +0,0 @@ -module FragmentLocalization - def localize_fragment_key(key, locale) - if key.is_a?(Hash) - {:locale => locale}.merge(key) - elsif key.is_a?(String) - "#{key} #{locale}" - else - raise TypeError, "unexpected fragment key type: #{key.class}" - end - end -end