view_component-styles 0.2.0 → 0.3.0

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: 284d24a7b4c34148fbd09a1c7bf826b6feba1a7f90dce99742b7718fdf3f2f97
4
- data.tar.gz: 9de7fce7e7eb437b8d7ab82882ef131aeb125fdbd882edcb9374ffd84f523544
3
+ metadata.gz: c6a33a7dc4b487fd3566dd11be4bbe7b1835eff2f96890e11368c2385b3c4cfe
4
+ data.tar.gz: c97a2f170ec893938667211616d95427f8a575a6a7ea75696c63478020568468
5
5
  SHA512:
6
- metadata.gz: 7ee52704df578a1d265451260cbd61d05f6214d0adedf11e7ad1d9049b64d42cfc417839e0f6001163d144327f11d4cd95506ffcb01de4b7fb42b30f96f2c5b4
7
- data.tar.gz: 64788007b403748829cab0e2b1e901cbbc837ac06ead5dd7252a0dda57691665d435c83ca3bd709a1ed3d90277f148ccfe020860aea394e7518045ac10fc963e
6
+ metadata.gz: c31abd5e53f570a6e803e3325e3ae52a72931ac685ab237f7d7ce07260f2895fe5315f04ae058e5ea67fdcb31b973a075c5f9ecd7f22ecc0a42bfd8b8539731e
7
+ data.tar.gz: ca8b913acecfa92c9f7ec5bf7381d6cf276729dd5fe3ab6511b1a69c35c621e4ebd2b23b6cdcdedfdd57cc81d1901c0452eec23a100ecb45047c73f37cfec296
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- view_component-styles (0.2.0)
4
+ view_component-styles (0.3.0)
5
5
  rails (>= 5)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -24,7 +24,7 @@ Or install it yourself as:
24
24
 
25
25
  ```ruby
26
26
  class ApplicationComponent < ViewComponent::Base
27
- include ViewComponent::Styles::Component
27
+ extend ViewComponent::Styles::Component
28
28
  end
29
29
  ```
30
30
  ```ruby
@@ -72,13 +72,9 @@ At this point you're all set up! Whenever a component is included in a view that
72
72
  styles will be aggregated into a single stylesheet and then loaded right into the layout. From here, they can be
73
73
  rendered regularly or picked up by premailer for inlining.
74
74
 
75
- Note that in order to properly configure the asset pipeline in Rails in order to be compatible with this gem, you may
75
+ Note that in order to properly configure the asset pipeline in Rails to compile component stylesheets, you may
76
76
  need to add the following configuration:
77
77
 
78
- `application.rb`
79
- ```ruby
80
- config.assets.paths << Rails.root.join('app', 'components')
81
- ```
82
78
  `assets/config/manifest.js`
83
79
  ```
84
80
  //= link_tree ../../components .css
@@ -3,10 +3,6 @@
3
3
  module ViewComponent
4
4
  module Styles
5
5
  module Component
6
- include ViewComponent::Styles::Helper
7
-
8
- # @param path [String]
9
- # @return [Boolean]
10
6
  def asset_exists?(path)
11
7
  if Rails.configuration.assets.compile
12
8
  # Dynamic compilation
@@ -17,14 +13,29 @@ module ViewComponent
17
13
  end
18
14
  end
19
15
 
20
- # @return [void]
21
- def before_render
22
- singleton_stylesheet_link_tag(component_stylesheet_name) if asset_exists?(component_stylesheet_name)
16
+ def component_stylesheet_name
17
+ "#{name.underscore}.css"
23
18
  end
24
19
 
25
- # @return [String]
26
- def component_stylesheet_name
27
- "#{self.class.name.underscore}.css"
20
+ def inherited(subclass)
21
+ super
22
+ subclass.include(ViewComponent::Styles::Helper)
23
+
24
+ component_stylesheet_name = subclass.component_stylesheet_name
25
+ return unless asset_exists?(component_stylesheet_name)
26
+
27
+ subclass.prepend(Module.new.tap do |m|
28
+ m.class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
29
+ # def before_render
30
+ # super
31
+ # singleton_stylesheet_link_tag("example")
32
+ # end
33
+ def before_render
34
+ super
35
+ singleton_stylesheet_link_tag(#{component_stylesheet_name.inspect})
36
+ end
37
+ RUBY
38
+ end)
28
39
  end
29
40
  end
30
41
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ViewComponent
4
4
  module Styles
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component-styles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-10 00:00:00.000000000 Z
11
+ date: 2022-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails