view_component-scoped_styles 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99036b6a74c47fa492904ea9d68dca4354d62f97071e45a6da2cc2ace09b4a70
4
- data.tar.gz: 9d12f41dc240f8cc9b5b9526bd1462b17681edb64d4bcd85ef87c8863cdb7773
3
+ metadata.gz: 11d8e3379f898df14de704b6cf85d52511347b83968941fe15b1f50c40f4e84b
4
+ data.tar.gz: 8f6ca431aad7a2ef07953a913f0819fb01c5c07aaf8332ecd4874c013cd4e766
5
5
  SHA512:
6
- metadata.gz: 57fd226b7dad095ce6a37caf2cca43a8bc934ce9e8309c49f1409ce4956896330cf663c6eaaa59459655b0c850f212520c97b52bf81bb659795b7768f2e4fb76
7
- data.tar.gz: 6dfb4eece1a9e1f18850fe239449462c436b5a8d07d0314203df954e212aaafc5a3e6833f017eef19075dfccc07b3becc9e607ee00d92e0d76b13d1baf3efbd7
6
+ metadata.gz: e7185f8787fe5e6a1da003263da693223521b2f710269c426d936af8df6f6b9268450450ff1e2d8a8e10c5b49667b76649e3b0d4c439422514ddba45703378c1
7
+ data.tar.gz: e26733e488cac418042f5ebf920bf670e06592c1df023044f8587db4b64db108abe067c8a82c7cc46d305b6569bf1555baa69955c0145021c78b0a2e233a4921
data/README.md CHANGED
@@ -65,22 +65,27 @@ Learn more about sidecar [here](https://viewcomponent.org/guide/generators.html#
65
65
  bin/rails generate view_component:component Example title --sidecar
66
66
  ```
67
67
 
68
- With automatic stylesheet generation enabled in `config/application.rb`, `config/ENVIRONMENT.rb`, or wherever you configure ViewComponent:
68
+ `view_component:component` creates a `.css` file by default, adds
69
+ `include ViewComponent::ScopedStyles` to the component class, and sets
70
+ `class="<%= component_class %>"` on the generated ERB template. With `--sidecar`,
71
+ the stylesheet is placed in the sidecar directory. No stylesheet configuration
72
+ is needed.
73
+
74
+ Pass `--no-stylesheet` to skip CSS generation for one component. To disable it
75
+ for the app, add this to `config/application.rb`:
69
76
 
70
77
  ```ruby
71
- # Ensure sidebar is enabled
72
- config.view_component.generate.sidecar = true
73
- # Generate scoped stylesheets alongside components
74
78
  config.generators do |g|
75
- g.view_component stylesheet: true
79
+ g.component stylesheet: false
76
80
  end
77
81
  ```
78
82
 
79
- `view_component:component` also creates the sidecar `.css` file, adds `include ViewComponent::ScopedStyles` to the component class, and sets `class="<%= component_class %>"` on the generated ERB template. You can pass `--no-stylesheet` to skip CSS generation for a single component.
83
+ Pass `--stylesheet` to generate CSS when the app default is disabled. You can
84
+ also use `g.view_component stylesheet: false`. Settings under `g.component`
85
+ take precedence, including an explicit `false`.
80
86
 
81
- Replace `config.view_component.generate.stylesheet = true` in existing apps with
82
- the `config.generators` block above. ViewComponent does not support a `stylesheet`
83
- configuration option and rejects it in versions with strict configuration validation.
87
+ Remove `config.view_component.generate.stylesheet = true` from existing apps.
88
+ ViewComponent does not support that option and rejects it starting in 4.21.
84
89
 
85
90
  ```bash
86
91
  bin/rails generate view_component:component Example title --sidecar
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Optional ViewComponent generator settings (in config/application.rb, config/ENVIRONMENT.rb, or wherever you configure ViewComponent):
4
- # Ensure sidebar is enabled
4
+ # Ensure sidecar is enabled
5
5
  # config.view_component.generate.sidecar = true
6
- # Then generate stylesheets via
7
- # config.view_component.generate.stylesheet = true
6
+ # Scoped stylesheets are generated by default. To disable generation:
7
+ # config.generators do |g|
8
+ # g.component stylesheet: false
9
+ # end
8
10
 
9
11
  ViewComponent::ScopedStyles.configure do |config|
10
12
  # Where ViewComponent classes live (relative to Rails.root). Default: "app/components"
@@ -6,7 +6,7 @@ require "generators/view_component/component/component_generator"
6
6
  module ViewComponent
7
7
  module Generators
8
8
  class ComponentGenerator
9
- class_option :stylesheet, type: :boolean, default: false
9
+ class_option :stylesheet, type: :boolean, default: true
10
10
 
11
11
  hook_for :stylesheet, type: :boolean
12
12
  end
@@ -6,8 +6,18 @@ require "rails/railtie"
6
6
  module ViewComponent
7
7
  module ScopedStyles
8
8
  class Railtie < Rails::Railtie
9
- generators do
9
+ generators do |app|
10
10
  require_relative "component_generator_hook"
11
+
12
+ options = app.config.generators.options
13
+ namespace = %i[component view_component rails].find do |name|
14
+ options.fetch(name, {}).key?(:stylesheet)
15
+ end
16
+ default = namespace ? options[namespace][:stylesheet] : true
17
+
18
+ ViewComponent::Generators::ComponentGenerator.class_option(
19
+ :stylesheet, type: :boolean, default: default
20
+ )
11
21
  end
12
22
 
13
23
  config.after_initialize do
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ViewComponent
4
4
  module ScopedStyles
5
- VERSION = "0.8.2"
5
+ VERSION = "0.8.3"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component-scoped_styles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Edwards