-
Notifications
You must be signed in to change notification settings - Fork 330
/
Copy pathengine.rb
90 lines (78 loc) · 2.92 KB
/
engine.rb
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require "rails/engine"
require "turbo/test_assertions"
module Turbo
class Engine < Rails::Engine
isolate_namespace Turbo
config.eager_load_namespaces << Turbo
config.turbo = ActiveSupport::OrderedOptions.new
config.autoload_once_paths = %W(
#{root}/app/channels
#{root}/app/controllers
#{root}/app/controllers/concerns
#{root}/app/helpers
#{root}/app/models
#{root}/app/models/concerns
#{root}/app/jobs
)
initializer "turbo.no_action_cable", before: :set_eager_load_paths do
config.eager_load_paths.delete("#{root}/app/channels") unless defined?(ActionCable)
end
# If you don't want to precompile Turbo's assets (eg. because you're using webpack),
# you can do this in an intiailzer:
#
# config.after_initialize do
# config.assets.precompile -= Turbo::Engine::PRECOMPILE_ASSETS
# end
PRECOMPILE_ASSETS = %w( turbo.js turbo.min.js turbo.min.js.map )
initializer "turbo.assets" do
if Rails.application.config.respond_to?(:assets)
Rails.application.config.assets.precompile += PRECOMPILE_ASSETS
end
end
initializer "turbo.helpers", before: :load_config_initializers do
ActiveSupport.on_load(:action_controller_base) do
include Turbo::Streams::TurboStreamsTagBuilder, Turbo::Frames::FrameRequest, Turbo::Native::Navigation
helper Turbo::Engine.helpers
end
end
initializer "turbo.broadcastable" do
ActiveSupport.on_load(:active_record) do
include Turbo::Broadcastable
end
end
initializer "turbo.mimetype" do
Mime::Type.register "text/vnd.turbo-stream.html", :turbo_stream
end
initializer "turbo.renderer" do
ActiveSupport.on_load(:action_controller) do
ActionController::Renderers.add :turbo_stream do |turbo_streams_html, options|
self.content_type = Mime[:turbo_stream] if media_type.nil?
turbo_streams_html
end
end
end
initializer "turbo.signed_stream_verifier_key" do
config.after_initialize do
Turbo.signed_stream_verifier_key = config.turbo.signed_stream_verifier_key ||
Rails.application.key_generator.generate_key("turbo/signed_stream_verifier_key")
end
end
initializer "turbo.test_assertions" do
ActiveSupport.on_load(:active_support_test_case) do
include Turbo::TestAssertions
end
end
initializer "turbo.integration_test_request_encoding" do
ActiveSupport.on_load(:action_dispatch_integration_test) do
# Support `as: :turbo_stream`. Public `register_encoder` API is a little too strict.
class ActionDispatch::RequestEncoder
class TurboStreamEncoder < IdentityEncoder
header = [ Mime[:turbo_stream], Mime[:html] ].join(",")
define_method(:accept_header) { header }
end
@encoders[:turbo_stream] = TurboStreamEncoder.new
end
end
end
end
end