Skip to content

Commit

Permalink
try inheriting from rails
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellhenke committed Oct 26, 2023
1 parent a8f950d commit 60a92d2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/view_component/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def defaults
test_controller: "ApplicationController",
default_preview_layout: nil,
capture_compatibility_patch_enabled: false,
frozen_string_literal: false
frozen_string_literal: :inherit_from_rails
})
end

Expand Down Expand Up @@ -160,8 +160,10 @@ def defaults
# Enables compiling templates with the frozen_string_literal magic
# comment, which prevents modification of string objects by
# assuming they are frozen on initialize. Has performance
# benefits.
# Defaults to `false`.
# benefits. This configuration will default to inheriting from
# `Rails.application.config.action_view.frozen_string_literal`, but can be
# overridden.
# Defaults to `:inherit_from_rails`.

def default_preview_paths
return [] unless defined?(Rails.root) && Dir.exist?("#{Rails.root}/test/components/previews")
Expand Down
3 changes: 3 additions & 0 deletions lib/view_component/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class Engine < Rails::Engine # :nodoc:
end

initializer "view_component.set_configs" do |app|
if app.config.view_component.frozen_string_literal == :inherit_from_rails
app.config.view_component.frozen_string_literal = !!Rails.application.config.action_view.frozen_string_literal
end
options = app.config.view_component

%i[generate preview_controller preview_route show_previews_source].each do |config_option|
Expand Down
2 changes: 1 addition & 1 deletion test/sandbox/test/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_defaults_are_correct
assert_equal @config.render_monkey_patch_enabled, true
assert_equal @config.show_previews, true
assert_equal @config.preview_paths, ["#{Rails.root}/test/components/previews"]
assert_equal @config.frozen_string_literal, false
assert_equal @config.frozen_string_literal, :inherit_from_rails
end

def test_all_methods_are_documented
Expand Down

0 comments on commit 60a92d2

Please sign in to comment.