2017-07-23 15:36:41 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2009-12-31 20:28:48 +00:00
|
|
|
require "action_view"
|
2010-01-12 23:41:04 +00:00
|
|
|
require "rails"
|
|
|
|
|
|
|
|
module ActionView
|
2010-06-16 18:27:50 +00:00
|
|
|
# = Action View Railtie
|
2016-11-25 16:10:52 +00:00
|
|
|
class Railtie < Rails::Engine # :nodoc:
|
2010-03-26 17:47:55 +00:00
|
|
|
config.action_view = ActiveSupport::OrderedOptions.new
|
2017-03-23 20:43:11 +00:00
|
|
|
config.action_view.embed_authenticity_token_in_remote_forms = nil
|
2015-12-01 15:49:44 +00:00
|
|
|
config.action_view.debug_missing_translation = true
|
2018-02-27 11:07:04 +00:00
|
|
|
config.action_view.default_enforce_utf8 = nil
|
2020-02-13 23:48:21 +00:00
|
|
|
config.action_view.image_loading = nil
|
2012-03-28 02:03:50 +00:00
|
|
|
|
2012-08-01 18:54:22 +00:00
|
|
|
config.eager_load_namespaces << ActionView
|
|
|
|
|
2019-12-18 16:23:50 +00:00
|
|
|
config.after_initialize do |app|
|
|
|
|
ActionView::Helpers::FormTagHelper.embed_authenticity_token_in_remote_forms =
|
|
|
|
app.config.action_view.delete(:embed_authenticity_token_in_remote_forms)
|
2012-03-28 02:03:50 +00:00
|
|
|
end
|
2010-06-22 22:30:22 +00:00
|
|
|
|
2019-12-18 16:23:50 +00:00
|
|
|
config.after_initialize do |app|
|
|
|
|
form_with_generates_remote_forms = app.config.action_view.delete(:form_with_generates_remote_forms)
|
|
|
|
ActionView::Helpers::FormHelper.form_with_generates_remote_forms = form_with_generates_remote_forms
|
|
|
|
end
|
|
|
|
|
|
|
|
config.after_initialize do |app|
|
|
|
|
form_with_generates_ids = app.config.action_view.delete(:form_with_generates_ids)
|
|
|
|
unless form_with_generates_ids.nil?
|
|
|
|
ActionView::Helpers::FormHelper.form_with_generates_ids = form_with_generates_ids
|
2017-04-21 16:23:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-18 16:23:50 +00:00
|
|
|
config.after_initialize do |app|
|
|
|
|
default_enforce_utf8 = app.config.action_view.delete(:default_enforce_utf8)
|
|
|
|
unless default_enforce_utf8.nil?
|
|
|
|
ActionView::Helpers::FormTagHelper.default_enforce_utf8 = default_enforce_utf8
|
2017-06-13 14:54:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-13 23:48:21 +00:00
|
|
|
config.after_initialize do |app|
|
|
|
|
ActionView::Helpers::AssetTagHelper.image_loading = app.config.action_view.delete(:image_loading)
|
|
|
|
end
|
|
|
|
|
2019-12-18 16:23:50 +00:00
|
|
|
config.after_initialize do |app|
|
2018-02-27 11:07:04 +00:00
|
|
|
ActiveSupport.on_load(:action_view) do
|
2019-12-18 16:23:50 +00:00
|
|
|
app.config.action_view.each do |k, v|
|
2017-12-27 00:51:42 +00:00
|
|
|
if k == :raise_on_missing_translations
|
|
|
|
ActiveSupport::Deprecation.warn \
|
|
|
|
"action_view.raise_on_missing_translations is deprecated and will be removed in Rails 6.2. " \
|
|
|
|
"Set i18n.raise_on_missing_translations instead. " \
|
|
|
|
"Note that this new setting also affects how missing translations are handled in controllers."
|
|
|
|
end
|
2019-12-18 16:23:50 +00:00
|
|
|
send "#{k}=", v
|
2018-02-27 11:07:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-18 17:05:36 +00:00
|
|
|
initializer "action_view.logger" do
|
|
|
|
ActiveSupport.on_load(:action_view) { self.logger ||= Rails.logger }
|
|
|
|
end
|
|
|
|
|
2010-12-16 20:37:48 +00:00
|
|
|
initializer "action_view.caching" do |app|
|
|
|
|
ActiveSupport.on_load(:action_view) do
|
|
|
|
if app.config.action_view.cache_template_loading.nil?
|
|
|
|
ActionView::Resolver.caching = app.config.cache_classes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-06-26 12:48:40 +00:00
|
|
|
|
2013-12-05 18:34:22 +00:00
|
|
|
initializer "action_view.setup_action_pack" do |app|
|
2013-06-26 12:48:40 +00:00
|
|
|
ActiveSupport.on_load(:action_controller) do
|
2015-02-01 04:12:37 +00:00
|
|
|
ActionView::RoutingUrlFor.include(ActionDispatch::Routing::UrlFor)
|
2013-06-26 12:48:40 +00:00
|
|
|
end
|
|
|
|
end
|
2013-07-17 13:13:16 +00:00
|
|
|
|
2016-04-27 21:21:10 +00:00
|
|
|
initializer "action_view.collection_caching", after: "action_controller.set_configs" do |app|
|
|
|
|
PartialRenderer.collection_cache = app.config.action_controller.cache_store
|
|
|
|
end
|
|
|
|
|
2019-12-18 16:23:50 +00:00
|
|
|
config.after_initialize do |app|
|
|
|
|
enable_caching = if app.config.action_view.cache_template_loading.nil?
|
|
|
|
app.config.cache_classes
|
|
|
|
else
|
|
|
|
app.config.action_view.cache_template_loading
|
|
|
|
end
|
|
|
|
|
|
|
|
unless enable_caching
|
|
|
|
app.executor.to_run ActionView::CacheExpiry::Executor.new(watcher: app.config.file_watcher)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-05 17:42:39 +00:00
|
|
|
rake_tasks do |app|
|
|
|
|
unless app.config.api_only
|
2016-03-09 23:32:11 +00:00
|
|
|
load "action_view/tasks/cache_digests.rake"
|
2015-05-05 17:42:39 +00:00
|
|
|
end
|
2013-09-26 19:19:19 +00:00
|
|
|
end
|
2010-01-12 23:41:04 +00:00
|
|
|
end
|
2010-12-16 20:37:48 +00:00
|
|
|
end
|