File tree Expand file tree Collapse file tree 3 files changed +9
-4
lines changed Expand file tree Collapse file tree 3 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ def defaults
26
26
test_controller : "ApplicationController" ,
27
27
default_preview_layout : nil ,
28
28
capture_compatibility_patch_enabled : false ,
29
- frozen_string_literal : false
29
+ frozen_string_literal : :inherit_from_rails
30
30
} )
31
31
end
32
32
@@ -160,8 +160,10 @@ def defaults
160
160
# Enables compiling templates with the frozen_string_literal magic
161
161
# comment, which prevents modification of string objects by
162
162
# assuming they are frozen on initialize. Has performance
163
- # benefits.
164
- # Defaults to `false`.
163
+ # benefits. This configuration will default to inheriting from
164
+ # `Rails.application.config.action_view.frozen_string_literal`, but can be
165
+ # overridden.
166
+ # Defaults to `:inherit_from_rails`.
165
167
166
168
def default_preview_paths
167
169
return [ ] unless defined? ( Rails . root ) && Dir . exist? ( "#{ Rails . root } /test/components/previews" )
Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ class Engine < Rails::Engine # :nodoc:
13
13
end
14
14
15
15
initializer "view_component.set_configs" do |app |
16
+ if app . config . view_component . frozen_string_literal == :inherit_from_rails
17
+ app . config . view_component . frozen_string_literal = !!Rails . application . config . action_view . frozen_string_literal
18
+ end
16
19
options = app . config . view_component
17
20
18
21
%i[ generate preview_controller preview_route show_previews_source ] . each do |config_option |
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ def test_defaults_are_correct
18
18
assert_equal @config . render_monkey_patch_enabled , true
19
19
assert_equal @config . show_previews , true
20
20
assert_equal @config . preview_paths , [ "#{ Rails . root } /test/components/previews" ]
21
- assert_equal @config . frozen_string_literal , false
21
+ assert_equal @config . frozen_string_literal , :inherit_from_rails
22
22
end
23
23
24
24
def test_all_methods_are_documented
You can’t perform that action at this time.
0 commit comments