diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e6bb654e2..65ff3a9b2 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -10,6 +10,10 @@ nav_order: 6 ## main +* Fix outdated settings related to default layout preview. + + *Lucas Geron* + ## 4.0.2 * Share the view context in tests to prevent out-of-order rendering issues for certain advanced use-cases, eg. testing instances of Rails' `FormBuilder`. diff --git a/docs/guide/previews.md b/docs/guide/previews.md index f6be4a681..1ba738711 100644 --- a/docs/guide/previews.md +++ b/docs/guide/previews.md @@ -110,7 +110,7 @@ To set a custom layout for individual previews and the previews index page, set: ```ruby # config/application.rb # Set the default layout to app/views/layouts/component_preview.html.erb -config.view_component.default_preview_layout = "component_preview" +config.view_component.previews.default_layout = "component_preview" ``` ## Preview paths diff --git a/lib/generators/view_component/component/component_generator.rb b/lib/generators/view_component/component/component_generator.rb index 0cce03808..60964c285 100644 --- a/lib/generators/view_component/component/component_generator.rb +++ b/lib/generators/view_component/component/component_generator.rb @@ -23,7 +23,7 @@ class ComponentGenerator < Rails::Generators::NamedBase class_option :skip_suffix, type: :boolean, default: false def create_component_file - template "component.rb", File.join(component_path, class_path, "#{file_name}#{options[:skip_suffix] ? "" : "_component"}.rb") + template "component.rb", File.join(component_path, class_path, "#{file_name}#{"_component" unless options[:skip_suffix]}.rb") end hook_for :test_framework diff --git a/lib/view_component/collection.rb b/lib/view_component/collection.rb index b76eeea1a..c53f1f1af 100644 --- a/lib/view_component/collection.rb +++ b/lib/view_component/collection.rb @@ -5,6 +5,7 @@ module ViewComponent class Collection include Enumerable + attr_reader :component delegate :size, to: :@collection diff --git a/lib/view_component/inline_template.rb b/lib/view_component/inline_template.rb index 06152e99b..95bb2acac 100644 --- a/lib/view_component/inline_template.rb +++ b/lib/view_component/inline_template.rb @@ -3,6 +3,7 @@ module ViewComponent # :nodoc: module InlineTemplate extend ActiveSupport::Concern + Template = Struct.new(:source, :language, :path, :lineno) class_methods do