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!
This commit is contained in:
parent
d27c03606f
commit
c0e4291745
5 changed files with 5 additions and 27 deletions
|
@ -2,12 +2,10 @@ require 'async'
|
||||||
require 'async/container'
|
require 'async/container'
|
||||||
|
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
include FragmentLocalization
|
|
||||||
|
|
||||||
protect_from_forgery
|
protect_from_forgery
|
||||||
|
|
||||||
helper_method :current_user, :user_signed_in?
|
helper_method :current_user, :user_signed_in?
|
||||||
|
|
||||||
before_action :set_locale
|
before_action :set_locale
|
||||||
|
|
||||||
before_action :configure_permitted_parameters, if: :devise_controller?
|
before_action :configure_permitted_parameters, if: :devise_controller?
|
||||||
|
@ -45,7 +43,7 @@ class ApplicationController < ActionController::Base
|
||||||
def user_signed_in?
|
def user_signed_in?
|
||||||
auth_user_signed_in?
|
auth_user_signed_in?
|
||||||
end
|
end
|
||||||
|
|
||||||
def infer_locale
|
def infer_locale
|
||||||
return params[:locale] if valid_locale?(params[:locale])
|
return params[:locale] if valid_locale?(params[:locale])
|
||||||
return cookies[:locale] if valid_locale?(cookies[: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)) ||
|
http_accept_language.language_region_compatible_from(I18n.available_locales.map(&:to_s)) ||
|
||||||
I18n.default_locale
|
I18n.default_locale
|
||||||
end
|
end
|
||||||
|
|
||||||
def not_found(record_name='record')
|
def not_found(record_name='record')
|
||||||
raise ActionController::RoutingError.new("#{record_name} not found")
|
raise ActionController::RoutingError.new("#{record_name} not found")
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
include FragmentLocalization
|
|
||||||
|
|
||||||
def absolute_url(path_or_url)
|
def absolute_url(path_or_url)
|
||||||
if path_or_url.include?('://') # already an absolute URL
|
if path_or_url.include?('://') # already an absolute URL
|
||||||
path_or_url
|
path_or_url
|
||||||
|
@ -165,13 +163,6 @@ module ApplicationHelper
|
||||||
|
|
||||||
options
|
options
|
||||||
end
|
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
|
def auth_user_sign_in_path_with_return_to
|
||||||
new_auth_user_session_path :return_to => request.fullpath
|
new_auth_user_session_path :return_to => request.fullpath
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
%h2= t '.newest_items.header'
|
%h2= t '.newest_items.header'
|
||||||
= render @newest_items
|
= render @newest_items
|
||||||
|
|
||||||
- localized_cache :action_suffix => 'species_search_links' do
|
- cache "items/index species_search_links locale=#{I18n.locale}" do
|
||||||
#species-search-links
|
#species-search-links
|
||||||
%h2= t '.species_search.header'
|
%h2= t '.species_search.header'
|
||||||
= standard_species_search_links
|
= standard_species_search_links
|
||||||
|
|
|
@ -90,7 +90,7 @@
|
||||||
%h3= t '.newest_items.unmodeled.header'
|
%h3= t '.newest_items.unmodeled.header'
|
||||||
%ul#newest-unmodeled-items
|
%ul#newest-unmodeled-items
|
||||||
- @newest_unmodeled_items.each do |item|
|
- @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}
|
%li{'data-item-id' => item.id}
|
||||||
= link_to image_tag(item.thumbnail_url), item, :class => 'image-link'
|
= link_to image_tag(item.thumbnail_url), item, :class => 'image-link'
|
||||||
= link_to item, :class => 'header' do
|
= link_to item, :class => 'header' do
|
||||||
|
|
|
@ -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
|
|
Loading…
Reference in a new issue