view_component-styles 0.1.0 → 0.3.1
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 +9 -1
- data/lib/view_component/styles/component.rb +22 -10
- data/lib/view_component/styles/engine.rb +11 -0
- data/lib/view_component/styles/version.rb +1 -1
- data/lib/view_component/styles.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c19c45ab4f50ebd413bcd10894e4188ac21f1a1fba71c2b24cb6eed5c6e18f6
|
4
|
+
data.tar.gz: 9424e24d3b752daab5de1898972ca837df926bc6009269bddab49e7623650e8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6cee3a710358397dfe2613611b3444f0f53acab1a5656b7282ed81df3b15da3f29533e257eaaeed8c5bde252a2fae329c45a87eb3585c7dafe8fe07c7eb0b53
|
7
|
+
data.tar.gz: 937eaa25905d6b06b1b963bf6de282abd49a282735f5da436de50e0e7f193bada4cb489f3c2f1b27b08c74853fd530689cf88301d60204e1e8277c08268b5e13
|
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,6 +72,14 @@ 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 to compile component stylesheets, you may
|
76
|
+
need to add the following configuration:
|
77
|
+
|
78
|
+
`assets/config/manifest.js`
|
79
|
+
```
|
80
|
+
//= link_tree ../../components .css
|
81
|
+
```
|
82
|
+
|
75
83
|
## Development
|
76
84
|
|
77
85
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -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,30 @@ 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
|
+
|
26
|
+
subclass.prepend(Module.new.tap do |m|
|
27
|
+
m.class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
28
|
+
# def before_render
|
29
|
+
# super
|
30
|
+
# return unless self.class.asset_exists?("example")
|
31
|
+
# singleton_stylesheet_link_tag("example")
|
32
|
+
# end
|
33
|
+
def before_render
|
34
|
+
super
|
35
|
+
return unless self.class.asset_exists?(#{component_stylesheet_name.inspect})
|
36
|
+
singleton_stylesheet_link_tag(#{component_stylesheet_name.inspect})
|
37
|
+
end
|
38
|
+
RUBY
|
39
|
+
end)
|
28
40
|
end
|
29
41
|
end
|
30
42
|
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.1
|
4
|
+
version: 0.3.1
|
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
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/view_component/styles.rb
|
45
45
|
- lib/view_component/styles/component.rb
|
46
46
|
- lib/view_component/styles/controller.rb
|
47
|
+
- lib/view_component/styles/engine.rb
|
47
48
|
- lib/view_component/styles/helper.rb
|
48
49
|
- lib/view_component/styles/version.rb
|
49
50
|
- view_component-styles.gemspec
|