view_component_helper 0.9.0 → 0.9.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 +31 -6
- data/lib/view_component_helper/version.rb +1 -1
- data/lib/view_component_helper/view_helper.rb +5 -2
- 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: 5966bd782f29a9d3e10a9bd583c6d79d7239f2f767de4cd3e4e5a13b302e0e81
|
4
|
+
data.tar.gz: 7c6fc694458ae9dd2d583b6d7df13c482399b81f3c4c618c979bc6d7288baf84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70c4004614931d4caa0f88de8f07fd9dd312c9e456450b4c8094225aeb760c3d876be8339cc6daa22c92e8dde428f038e37876a24ccab61fc0be2f2c51033eff
|
7
|
+
data.tar.gz: d75ee370dfc30a75114c4012f55c6ff0b6d89f370678957ca04b0d1a07e570db6d6a88e223d21a482df022f525883c876b8a8f3f3e9709f36c8f0f02f87cedf3
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# ViewComponentHelper
|
2
|
+
[](https://badge.fury.io/rb/view_component_helper)
|
2
3
|
|
3
|
-
|
4
|
+
`ViewComponentHelper` is a simple gem designed to enhance the functionality provided by [ViewComponent](https://github.com/ViewComponent/view_component). It offers shortcuts to access generated ViewComponents, making your Rails development experience smoother and more efficient.
|
4
5
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -30,15 +30,40 @@ or
|
|
30
30
|
<%= vc("messageComponent", name: "World") %>
|
31
31
|
```
|
32
32
|
|
33
|
-
|
33
|
+
## Usage
|
34
|
+
For more information on ViewComponents, please refer to the [official documentation](https://viewcomponent.org/).
|
35
|
+
|
36
|
+
`ViewComponentHelper` allows for easier referencing of `ViewComponent` classes located under the `app/components` directory by providing you with intuitive shortcut methods.
|
37
|
+
|
38
|
+
### How it works
|
39
|
+
For every `ViewComponent` you define within the `app/components` directory, `ViewComponentHelper` automatically provides a shortcut method to render it.
|
40
|
+
|
41
|
+
### Examples
|
34
42
|
|
43
|
+
1. For a component located at `app/components/title_component.rb`:
|
35
44
|
|
45
|
+
You can utilize the following shortcut:
|
46
|
+
```ruby
|
47
|
+
title_component(title: "test title")
|
48
|
+
```
|
49
|
+
|
50
|
+
2. For a component located at `app/components/button.rb`:
|
36
51
|
|
37
|
-
|
52
|
+
```erb
|
53
|
+
<%= button %>
|
54
|
+
```
|
38
55
|
|
39
|
-
|
56
|
+
3. For a component located at `app/components/dialog/component.rb`
|
40
57
|
|
41
|
-
|
58
|
+
```erb
|
59
|
+
<%= dialog_component do |c| %>
|
60
|
+
<% c.with_title { "dialog title" } %>
|
61
|
+
<% c.with_body do %>
|
62
|
+
<p>this is dialog body</p>
|
63
|
+
<% end %>
|
64
|
+
<div>content</div>
|
65
|
+
<% end %>
|
66
|
+
```
|
42
67
|
|
43
68
|
## Contributing
|
44
69
|
|
@@ -15,7 +15,9 @@ module ViewComponentHelper
|
|
15
15
|
if collection
|
16
16
|
render component_klass.with_collection(collection, *args, **kwargs, &block)
|
17
17
|
else
|
18
|
-
|
18
|
+
component_instance = component_klass.new(*args, **kwargs)
|
19
|
+
component_instance.instance_exec(&block) if block_given?
|
20
|
+
render(component_instance)
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -43,7 +45,8 @@ module ViewComponentHelper
|
|
43
45
|
if collection
|
44
46
|
render component_klass.with_collection(collection, *args, **kwargs, &block)
|
45
47
|
else
|
46
|
-
|
48
|
+
component_instance = component_klass.new(*args, **kwargs, &block)
|
49
|
+
render component_instance
|
47
50
|
end
|
48
51
|
end
|
49
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: view_component_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yamitake
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Simplify integration and boost productivity. '
|
14
14
|
email:
|