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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -6
- data/lib/view_component/styles/component.rb +21 -10
- data/lib/view_component/styles/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6a33a7dc4b487fd3566dd11be4bbe7b1835eff2f96890e11368c2385b3c4cfe
|
4
|
+
data.tar.gz: c97a2f170ec893938667211616d95427f8a575a6a7ea75696c63478020568468
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c31abd5e53f570a6e803e3325e3ae52a72931ac685ab237f7d7ce07260f2895fe5315f04ae058e5ea67fdcb31b973a075c5f9ecd7f22ecc0a42bfd8b8539731e
|
7
|
+
data.tar.gz: ca8b913acecfa92c9f7ec5bf7381d6cf276729dd5fe3ab6511b1a69c35c621e4ebd2b23b6cdcdedfdd57cc81d1901c0452eec23a100ecb45047c73f37cfec296
|
data/Gemfile.lock
CHANGED
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
|
-
|
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
|
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
|
-
|
21
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2022-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|