1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionview/lib/action_view/railtie.rb

102 lines
3.3 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require "action_view"
require "rails"
module ActionView
# = Action View Railtie
class Railtie < Rails::Engine # :nodoc:
NULL_OPTION = Object.new
config.action_view = ActiveSupport::OrderedOptions.new
config.action_view.embed_authenticity_token_in_remote_forms = nil
config.action_view.debug_missing_translation = true
config.action_view.default_enforce_utf8 = nil
config.action_view.finalize_compiled_template_methods = NULL_OPTION
config.eager_load_namespaces << ActionView
Don't require "action_view/base" in action pack: - ### Problem ActionPack requires "action_view/base" at boot time, this causes a variety of issue that I described in detail in #38024. There is no real reason to require av/base in the ActionDispatch::Debugexceptions class. ### Solution Like any other components (such as ActiveRecord, ActiveJob...), ActionView::Base shouldn't be loaded at boot time. Here are the two main changes needed for this: 1) Actionview has a special initializer that needs to run before the app is fully booted (adding a executor needs to be done before application is done booting) https://github.com/rails/rails/blob/63ec70e700e321b22e9baf2ad2d45cd3f4febc79/actionview/lib/action_view/railtie.rb#L81-L84 That initializer used a lazy load hooks but we can't do that anymore because Action::Base view won't be triggered during booting process. When it will get triggered, (presumably on the first request), it's too late to add an executor. ------------------------------------------------ 2) Compare to other components, ActionView doesn't use `Base` for configuration flag. A lot of flags ares instead set on modules (FormHelper, FormTagHelper). The problem is that those module depends on AV::Base to be loaded, as otherwise configuration set by the user aren't applied. (Since the lazy load hooks hasn't been triggered) https://github.com/rails/rails/blob/63ec70e700e321b22e9baf2ad2d45cd3f4febc79/actionview/lib/action_view/railtie.rb#L66-L69 We shouldn't wait for AB::Base to be loaded in order to set these configuration. However, we need to do it inside an `after_initialize` block in order to let application set it to the value they want. Closes #28538 Co-authored-by: betesh <iybetesh@gmail.com>"
2019-12-18 11:23:50 -05: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)
end
Don't require "action_view/base" in action pack: - ### Problem ActionPack requires "action_view/base" at boot time, this causes a variety of issue that I described in detail in #38024. There is no real reason to require av/base in the ActionDispatch::Debugexceptions class. ### Solution Like any other components (such as ActiveRecord, ActiveJob...), ActionView::Base shouldn't be loaded at boot time. Here are the two main changes needed for this: 1) Actionview has a special initializer that needs to run before the app is fully booted (adding a executor needs to be done before application is done booting) https://github.com/rails/rails/blob/63ec70e700e321b22e9baf2ad2d45cd3f4febc79/actionview/lib/action_view/railtie.rb#L81-L84 That initializer used a lazy load hooks but we can't do that anymore because Action::Base view won't be triggered during booting process. When it will get triggered, (presumably on the first request), it's too late to add an executor. ------------------------------------------------ 2) Compare to other components, ActionView doesn't use `Base` for configuration flag. A lot of flags ares instead set on modules (FormHelper, FormTagHelper). The problem is that those module depends on AV::Base to be loaded, as otherwise configuration set by the user aren't applied. (Since the lazy load hooks hasn't been triggered) https://github.com/rails/rails/blob/63ec70e700e321b22e9baf2ad2d45cd3f4febc79/actionview/lib/action_view/railtie.rb#L66-L69 We shouldn't wait for AB::Base to be loaded in order to set these configuration. However, we need to do it inside an `after_initialize` block in order to let application set it to the value they want. Closes #28538 Co-authored-by: betesh <iybetesh@gmail.com>"
2019-12-18 11:23:50 -05: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
end
end
Don't require "action_view/base" in action pack: - ### Problem ActionPack requires "action_view/base" at boot time, this causes a variety of issue that I described in detail in #38024. There is no real reason to require av/base in the ActionDispatch::Debugexceptions class. ### Solution Like any other components (such as ActiveRecord, ActiveJob...), ActionView::Base shouldn't be loaded at boot time. Here are the two main changes needed for this: 1) Actionview has a special initializer that needs to run before the app is fully booted (adding a executor needs to be done before application is done booting) https://github.com/rails/rails/blob/63ec70e700e321b22e9baf2ad2d45cd3f4febc79/actionview/lib/action_view/railtie.rb#L81-L84 That initializer used a lazy load hooks but we can't do that anymore because Action::Base view won't be triggered during booting process. When it will get triggered, (presumably on the first request), it's too late to add an executor. ------------------------------------------------ 2) Compare to other components, ActionView doesn't use `Base` for configuration flag. A lot of flags ares instead set on modules (FormHelper, FormTagHelper). The problem is that those module depends on AV::Base to be loaded, as otherwise configuration set by the user aren't applied. (Since the lazy load hooks hasn't been triggered) https://github.com/rails/rails/blob/63ec70e700e321b22e9baf2ad2d45cd3f4febc79/actionview/lib/action_view/railtie.rb#L66-L69 We shouldn't wait for AB::Base to be loaded in order to set these configuration. However, we need to do it inside an `after_initialize` block in order to let application set it to the value they want. Closes #28538 Co-authored-by: betesh <iybetesh@gmail.com>"
2019-12-18 11:23:50 -05: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
end
end
Don't require "action_view/base" in action pack: - ### Problem ActionPack requires "action_view/base" at boot time, this causes a variety of issue that I described in detail in #38024. There is no real reason to require av/base in the ActionDispatch::Debugexceptions class. ### Solution Like any other components (such as ActiveRecord, ActiveJob...), ActionView::Base shouldn't be loaded at boot time. Here are the two main changes needed for this: 1) Actionview has a special initializer that needs to run before the app is fully booted (adding a executor needs to be done before application is done booting) https://github.com/rails/rails/blob/63ec70e700e321b22e9baf2ad2d45cd3f4febc79/actionview/lib/action_view/railtie.rb#L81-L84 That initializer used a lazy load hooks but we can't do that anymore because Action::Base view won't be triggered during booting process. When it will get triggered, (presumably on the first request), it's too late to add an executor. ------------------------------------------------ 2) Compare to other components, ActionView doesn't use `Base` for configuration flag. A lot of flags ares instead set on modules (FormHelper, FormTagHelper). The problem is that those module depends on AV::Base to be loaded, as otherwise configuration set by the user aren't applied. (Since the lazy load hooks hasn't been triggered) https://github.com/rails/rails/blob/63ec70e700e321b22e9baf2ad2d45cd3f4febc79/actionview/lib/action_view/railtie.rb#L66-L69 We shouldn't wait for AB::Base to be loaded in order to set these configuration. However, we need to do it inside an `after_initialize` block in order to let application set it to the value they want. Closes #28538 Co-authored-by: betesh <iybetesh@gmail.com>"
2019-12-18 11:23:50 -05:00
config.after_initialize do |app|
ActiveSupport.on_load(:action_view) do
Don't require "action_view/base" in action pack: - ### Problem ActionPack requires "action_view/base" at boot time, this causes a variety of issue that I described in detail in #38024. There is no real reason to require av/base in the ActionDispatch::Debugexceptions class. ### Solution Like any other components (such as ActiveRecord, ActiveJob...), ActionView::Base shouldn't be loaded at boot time. Here are the two main changes needed for this: 1) Actionview has a special initializer that needs to run before the app is fully booted (adding a executor needs to be done before application is done booting) https://github.com/rails/rails/blob/63ec70e700e321b22e9baf2ad2d45cd3f4febc79/actionview/lib/action_view/railtie.rb#L81-L84 That initializer used a lazy load hooks but we can't do that anymore because Action::Base view won't be triggered during booting process. When it will get triggered, (presumably on the first request), it's too late to add an executor. ------------------------------------------------ 2) Compare to other components, ActionView doesn't use `Base` for configuration flag. A lot of flags ares instead set on modules (FormHelper, FormTagHelper). The problem is that those module depends on AV::Base to be loaded, as otherwise configuration set by the user aren't applied. (Since the lazy load hooks hasn't been triggered) https://github.com/rails/rails/blob/63ec70e700e321b22e9baf2ad2d45cd3f4febc79/actionview/lib/action_view/railtie.rb#L66-L69 We shouldn't wait for AB::Base to be loaded in order to set these configuration. However, we need to do it inside an `after_initialize` block in order to let application set it to the value they want. Closes #28538 Co-authored-by: betesh <iybetesh@gmail.com>"
2019-12-18 11:23:50 -05:00
app.config.action_view.each do |k, v|
send "#{k}=", v
end
end
end
initializer "action_view.finalize_compiled_template_methods" do |app|
ActiveSupport.on_load(:action_view) do
option = app.config.action_view.delete(:finalize_compiled_template_methods)
if option != NULL_OPTION
ActiveSupport::Deprecation.warn "action_view.finalize_compiled_template_methods is deprecated and has no effect"
end
end
end
2012-01-18 12:05:36 -05:00
initializer "action_view.logger" do
ActiveSupport.on_load(:action_view) { self.logger ||= Rails.logger }
end
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 08:48:40 -04:00
initializer "action_view.setup_action_pack" do |app|
2013-06-26 08:48:40 -04:00
ActiveSupport.on_load(:action_controller) do
ActionView::RoutingUrlFor.include(ActionDispatch::Routing::UrlFor)
2013-06-26 08:48:40 -04:00
end
end
initializer "action_view.collection_caching", after: "action_controller.set_configs" do |app|
PartialRenderer.collection_cache = app.config.action_controller.cache_store
end
Don't require "action_view/base" in action pack: - ### Problem ActionPack requires "action_view/base" at boot time, this causes a variety of issue that I described in detail in #38024. There is no real reason to require av/base in the ActionDispatch::Debugexceptions class. ### Solution Like any other components (such as ActiveRecord, ActiveJob...), ActionView::Base shouldn't be loaded at boot time. Here are the two main changes needed for this: 1) Actionview has a special initializer that needs to run before the app is fully booted (adding a executor needs to be done before application is done booting) https://github.com/rails/rails/blob/63ec70e700e321b22e9baf2ad2d45cd3f4febc79/actionview/lib/action_view/railtie.rb#L81-L84 That initializer used a lazy load hooks but we can't do that anymore because Action::Base view won't be triggered during booting process. When it will get triggered, (presumably on the first request), it's too late to add an executor. ------------------------------------------------ 2) Compare to other components, ActionView doesn't use `Base` for configuration flag. A lot of flags ares instead set on modules (FormHelper, FormTagHelper). The problem is that those module depends on AV::Base to be loaded, as otherwise configuration set by the user aren't applied. (Since the lazy load hooks hasn't been triggered) https://github.com/rails/rails/blob/63ec70e700e321b22e9baf2ad2d45cd3f4febc79/actionview/lib/action_view/railtie.rb#L66-L69 We shouldn't wait for AB::Base to be loaded in order to set these configuration. However, we need to do it inside an `after_initialize` block in order to let application set it to the value they want. Closes #28538 Co-authored-by: betesh <iybetesh@gmail.com>"
2019-12-18 11:23:50 -05: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
rake_tasks do |app|
unless app.config.api_only
load "action_view/tasks/cache_digests.rake"
end
end
end
end