Class: ViewComponent::Config
- Inherits:
-
Object
- Object
- ViewComponent::Config
- Defined in:
- lib/view_component/config.rb
Class Attribute Summary collapse
-
.generate ⇒ ActiveSupport::OrderedOptions
The subset of configuration options relating to generators.
-
.instrumentation_enabled ⇒ Boolean
Whether ActiveSupport notifications are enabled.
-
.previews ⇒ ActiveSupport::OrderedOptions
The subset of configuration options relating to previews.
Instance Attribute Summary collapse
-
#current ⇒ ViewComponent::Config
Returns the current ViewComponent::Config.
Class Method Summary collapse
- .default_generate_options ⇒ Object
-
.default_preview_paths ⇒ Boolean
Whether ActiveSupport notifications are enabled.
- .default_previews_options ⇒ Object
- .default_rails_engines_preview_paths ⇒ Object
- .default_rails_preview_paths ⇒ Object
- .defaults ⇒ Object
- .registered_rails_engines_with_previews ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
181 182 183 |
# File 'lib/view_component/config.rb', line 181 def initialize @config = self.class.defaults end |
Class Attribute Details
.generate ⇒ ActiveSupport::OrderedOptions
The subset of configuration options relating to generators.
All options under this namespace default to ‘false` unless otherwise stated.
#### ‘#path`
Where to put generated components. Defaults to ‘app/components`:
config.view_component.generate.path = "lib/components"
#### ‘#sidecar`
Always generate a component with a sidecar directory:
config.view_component.generate.sidecar = true
#### ‘#stimulus_controller`
Always generate a Stimulus controller alongside the component:
config.view_component.generate.stimulus_controller = true
#### ‘#typescript`
Generate TypeScript files instead of JavaScript files:
config.view_component.generate.typescript = true
#### ‘#locale`
Always generate translations file alongside the component:
config.view_component.generate.locale = true
#### ‘#distinct_locale_files`
Always generate as many translations files as available locales:
config.view_component.generate.distinct_locale_files = true
One file will be generated for each configured ‘I18n.available_locales`, falling back to `[:en]` when no `available_locales` is defined.
#### ‘#preview`
Always generate a preview alongside the component:
config.view_component.generate.preview = true
#### #preview_path
Path to generate preview:
config.view_component.generate.preview_path = "test/components/previews"
Required when there is more than one path defined in preview_paths. Defaults to ‘“”`. If this is blank, the generator will use `ViewComponent.config.previews.paths` if defined, `“test/components/previews”` otherwise
#### ‘#use_component_path_for_rspec_tests`
Whether to use ‘config.generate.path` when generating new RSpec component tests:
config.view_component.generate.use_component_path_for_rspec_tests = true
When set to ‘true`, the generator will use the `path` to decide where to generate the new RSpec component test. For example, if the `path` is `app/views/components`, then the generator will create a new spec file in `spec/views/components/` rather than the default `spec/components/`.
|
# File 'lib/view_component/config.rb', line 21
|
.instrumentation_enabled ⇒ Boolean
Whether ActiveSupport notifications are enabled. Defaults to ‘false`.
131 132 133 |
# File 'lib/view_component/config.rb', line 131 def default_preview_paths (default_rails_preview_paths + default_rails_engines_preview_paths).uniq end |
.previews ⇒ ActiveSupport::OrderedOptions
The subset of configuration options relating to previews.
#### ‘#controller`
The controller used for previewing components. Defaults to ‘ViewComponentsController`:
config.view_component.previews.controller = "MyPreviewController"
#### ‘#route`
The entry route for component previews. Defaults to ‘/rails/view_components`:
config.view_component.previews.route = "/my_previews"
#### ‘#enabled`
Whether component previews are enabled. Defaults to ‘true` in development and test environments:
config.view_component.previews.enabled = false
#### ‘#default_layout`
A custom default layout used for the previews index page and individual previews. Defaults to ‘nil`:
config.view_component.previews.default_layout = "preview_layout"
|
# File 'lib/view_component/config.rb', line 97
|
Instance Attribute Details
#current ⇒ ViewComponent::Config
Returns the current ViewComponent::Config. This is persisted against this class so that config options remain accessible before the rest of ViewComponent has loaded. Defaults to an instance of ViewComponent::Config with all other documented defaults set.
179 |
# File 'lib/view_component/config.rb', line 179 class_attribute :current, default: defaults, instance_predicate: false |
Class Method Details
.default_generate_options ⇒ Object
155 156 157 158 159 160 |
# File 'lib/view_component/config.rb', line 155 def = ActiveSupport::OrderedOptions.new(false) .preview_path = "" .path = "app/components" end |
.default_preview_paths ⇒ Boolean
Whether ActiveSupport notifications are enabled. Defaults to ‘false`.
131 132 133 |
# File 'lib/view_component/config.rb', line 131 def default_preview_paths (default_rails_preview_paths + default_rails_engines_preview_paths).uniq end |
.default_previews_options ⇒ Object
162 163 164 165 166 167 168 169 170 |
# File 'lib/view_component/config.rb', line 162 def = ActiveSupport::OrderedOptions.new .controller = "ViewComponentsController" .route = "/rails/view_components" .enabled = Rails.env.development? || Rails.env.test? .default_layout = nil .paths = default_preview_paths end |
.default_rails_engines_preview_paths ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/view_component/config.rb', line 141 def default_rails_engines_preview_paths return [] unless defined?(Rails::Engine) registered_rails_engines_with_previews.map do |descendant| "#{descendant.root}/test/components/previews" end end |
.default_rails_preview_paths ⇒ Object
135 136 137 138 139 |
# File 'lib/view_component/config.rb', line 135 def default_rails_preview_paths return [] unless defined?(Rails.root) && Dir.exist?("#{Rails.root}/test/components/previews") ["#{Rails.root}/test/components/previews"] end |
.defaults ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/view_component/config.rb', line 13 def defaults ActiveSupport::OrderedOptions.new.merge!({ generate: , previews: , instrumentation_enabled: false }) end |
.registered_rails_engines_with_previews ⇒ Object
149 150 151 152 153 |
# File 'lib/view_component/config.rb', line 149 def registered_rails_engines_with_previews Rails::Engine.descendants.select do |descendant| defined?(descendant.root) && Dir.exist?("#{descendant.root}/test/components/previews") end end |