Skip to content

Commit 60a92d2

Browse files
committed
try inheriting from rails
1 parent a8f950d commit 60a92d2

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

lib/view_component/config.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def defaults
2626
test_controller: "ApplicationController",
2727
default_preview_layout: nil,
2828
capture_compatibility_patch_enabled: false,
29-
frozen_string_literal: false
29+
frozen_string_literal: :inherit_from_rails
3030
})
3131
end
3232

@@ -160,8 +160,10 @@ def defaults
160160
# Enables compiling templates with the frozen_string_literal magic
161161
# comment, which prevents modification of string objects by
162162
# 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`.
165167

166168
def default_preview_paths
167169
return [] unless defined?(Rails.root) && Dir.exist?("#{Rails.root}/test/components/previews")

lib/view_component/engine.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class Engine < Rails::Engine # :nodoc:
1313
end
1414

1515
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
1619
options = app.config.view_component
1720

1821
%i[generate preview_controller preview_route show_previews_source].each do |config_option|

test/sandbox/test/config_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_defaults_are_correct
1818
assert_equal @config.render_monkey_patch_enabled, true
1919
assert_equal @config.show_previews, true
2020
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
2222
end
2323

2424
def test_all_methods_are_documented

0 commit comments

Comments
 (0)