Skip to content

Commit 7dc2b01

Browse files
authored
Merge pull request #2353 from ViewComponent/2188-config
add configuration page to docs
2 parents 9bcd46c + 82cd699 commit 7dc2b01

10 files changed

Lines changed: 35 additions & 24 deletions

File tree

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ nav_order: 6
1818

1919
*Joel Hawksley*
2020

21+
* BREAKING: Rename `config.generate.component_parent_class` to `config.generate.parent_class`.
22+
23+
*Joel Hawksley*
24+
2125
* Fix bug where `config.previews.enabled` did not function properly in production environments.
2226

2327
*Joel Hawksley*

docs/api.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,6 @@ A custom default layout used for the previews index page and individual previews
275275

276276
config.view_component.previews.default_layout = "preview_layout"
277277

278-
### `.test_controller`
279-
280-
The controller used for testing components.
281-
Can also be configured on a per-test basis using `#with_controller_class`.
282-
Defaults to `ApplicationController`.
283-
284278
## ViewComponent::TestHelpers
285279

286280
### `#render_in_view_context(...)`

docs/guide/configuration.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
layout: default
3+
title: Configuration
4+
parent: How-to guide
5+
---
6+
7+
# Configuration
8+
9+
To configure ViewComponent, set options in `config/ENVIRONMENT.rb`:
10+
11+
```ruby
12+
MyApplication.configure do
13+
config.view_component.instrumentation_enabled = true
14+
config.view_component.generate.path = "app/custom_components"
15+
config.view_component.previews.controller = "MyPreviewController"
16+
end
17+
```
18+
19+
For a list of available options, see [/api](/api#configuration).

docs/guide/generators.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ bin/rails generate view_component:component Example title content --parent MyBas
192192
create app/components/example_component.html.erb
193193
```
194194

195-
To always use a specific parent class, set `config.view_component.component_parent_class = "MyBaseComponent"`.
195+
To always use a specific parent class, set `config.view_component.parent_class = "MyBaseComponent"`.
196196

197197
### Skip collision check
198198

lib/generators/view_component/component/component_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def create_component_file
4343
def parent_class
4444
return options[:parent] if options[:parent]
4545

46-
ViewComponent::Base.config.generate.component_parent_class || default_parent_class
46+
ViewComponent::Base.config.generate.parent_class || default_parent_class
4747
end
4848

4949
def initialize_signature?

lib/view_component/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,12 @@ def safe_output_postamble
441441
#
442442
# Defaults to `false`.
443443
#
444-
# #### component_parent_class
444+
# #### ßparent_class
445445
#
446446
# Parent class for generated components
447447
#
448448
# ```ruby
449-
# config.view_component.generate.component_parent_class = "MyBaseComponent"
449+
# config.view_component.generate.parent_class = "MyBaseComponent"
450450
# ```
451451
#
452452
# Defaults to nil. If this is falsy, generators will use

lib/view_component/config.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,6 @@ def defaults
128128
# Whether ActiveSupport notifications are enabled.
129129
# Defaults to `false`.
130130

131-
# @!attribute test_controller
132-
# @return [String]
133-
# The controller used for testing components.
134-
# Can also be configured on a per-test basis using `#with_controller_class`.
135-
# Defaults to `ApplicationController`.
136-
137131
def default_preview_paths
138132
(default_rails_preview_paths + default_rails_engines_preview_paths).uniq
139133
end

lib/view_component/configurable.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Configurable
55
extend ActiveSupport::Concern
66

77
included do
8-
next if respond_to?(:config) && config.respond_to?(:view_component) && config.respond_to_missing?(:test_controller)
8+
next if respond_to?(:config) && config.respond_to?(:view_component) && config.respond_to_missing?(:instrumentation_enabled)
99

1010
include ActiveSupport::Configurable
1111

test/sandbox/test/generators/component_generator_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ def test_component_with_parent_and_application_component_class
9696
end
9797
end
9898

99-
def test_component_with_parent_and_custom_component_parent_class
100-
with_custom_component_parent_class("MyBaseComponent") do
99+
def test_component_with_parent_and_custom_parent_class
100+
with_custom_parent_class("MyBaseComponent") do
101101
run_generator %w[user --parent MyOtherBaseComponent]
102102

103103
assert_file "app/components/user_component.rb" do |component|
@@ -181,8 +181,8 @@ def test_generating_components_with_application_component_class
181181
end
182182
end
183183

184-
def test_generating_components_with_custom_component_parent_class
185-
with_custom_component_parent_class("MyBaseComponent") do
184+
def test_generating_components_with_custom_parent_class
185+
with_custom_parent_class("MyBaseComponent") do
186186
run_generator %w[user]
187187

188188
assert_file "app/components/user_component.rb" do |component|
@@ -194,7 +194,7 @@ def test_generating_components_with_custom_component_parent_class
194194

195195
def test_generating_components_with_application_component_class_and_custom_parent_class
196196
with_application_component_class do
197-
with_custom_component_parent_class("MyBaseComponent") do
197+
with_custom_parent_class("MyBaseComponent") do
198198
run_generator %w[user]
199199

200200
assert_file "app/components/user_component.rb" do |component|

test/test_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ def with_custom_component_path(new_value, &block)
9595
with_generate_option(:path, new_value, &block)
9696
end
9797

98-
def with_custom_component_parent_class(new_value, &block)
99-
with_generate_option(:component_parent_class, new_value, &block)
98+
def with_custom_parent_class(new_value, &block)
99+
with_generate_option(:parent_class, new_value, &block)
100100
end
101101

102102
def with_application_component_class

0 commit comments

Comments
 (0)