aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/lib/action_view/railtie.rb
blob: 4113448af01f4ed35ed27e9af7b9a57dd8132268 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require "action_view"
require "rails"

module ActionView
  # = Action View Railtie
  class Railtie < Rails::Railtie # :nodoc:
    config.action_view = ActiveSupport::OrderedOptions.new
    config.action_view.embed_authenticity_token_in_remote_forms = false

    config.eager_load_namespaces << ActionView

    initializer "action_view.embed_authenticity_token_in_remote_forms" do |app|
      ActiveSupport.on_load(:action_view) do
        ActionView::Helpers::FormTagHelper.embed_authenticity_token_in_remote_forms =
          app.config.action_view.delete(:embed_authenticity_token_in_remote_forms)
      end
    end

    initializer "action_view.logger" do
      ActiveSupport.on_load(:action_view) { self.logger ||= Rails.logger }
    end

    initializer "action_view.set_configs" do |app|
      ActiveSupport.on_load(:action_view) do
        app.config.action_view.each do |k,v|
          send "#{k}=", v
        end
      end
    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

    initializer "action_view.setup_action_pack", before: :add_view_paths do |app|
      ActiveSupport.on_load(:action_controller) do
        ActionController::Base.superclass.send(:include, ActionView::Layouts)
        ActionView::RoutingUrlFor.send(:include, ActionDispatch::Routing::UrlFor)
      end
    end

    initializer "action_view.setup_action_mailer", before: :add_view_paths do |app|
      ActiveSupport.on_load(:action_mailer) do
        ActionMailer::Base.send(:include, ActionView::Layouts)
      end
    end
  end
end