has_stimulus_attrs 0.1.0 → 0.2.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/CHANGELOG.md +8 -0
- data/README.md +10 -3
- data/lib/has_stimulus_attrs/version.rb +1 -1
- data/lib/has_stimulus_attrs.rb +30 -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: b084253adc44c27b3004ce03b89af50e106e08d785f098eabc4ed36e531f9a63
|
4
|
+
data.tar.gz: a939337452e2b4911dec9b6ae1f66da3986f04f647545205dfda4d4957e06653
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75d67545b94948163458e3ac971de8b75033e124506156b4b858f3dcae02eecd83b0d1770eb6a11e1cb4dcae894d31ce49f5662f11627027380f2c7fc56f95ba
|
7
|
+
data.tar.gz: c64fe067de8e607dd99ede0b4a953a478480ffa3c72007b1f32e6d205d939b45d6060b217bd5ff1ab2a34ab0ed32428c2ba40db10907a387dd3a52f607aaeea5
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [0.2.0](https://github.com/tomasc/has_stimulus_attrs/compare/v0.1.0...v0.2.0) (2023-03-22)
|
4
|
+
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
* allow controller option to accept proc ([1d34ae2](https://github.com/tomasc/has_stimulus_attrs/commit/1d34ae29f283e36aaed3fc56bd43f671c72308bf))
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
Helper methods for dealing with [stimulus](https://stimulus.hotwired.dev/) data attributes.
|
6
6
|
|
7
|
-
Relies on [`has_dom_attrs`](github.com/tomasc/has_dom_attrs) and [`stimulus_helpers`](github.com/tomasc/stimulus_helpers).
|
7
|
+
Relies on [`has_dom_attrs`](https://github.com/tomasc/has_dom_attrs) and [`stimulus_helpers`](https://github.com/tomasc/stimulus_helpers).
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -44,7 +44,7 @@ end
|
|
44
44
|
class DetailsComponent < ApplicationComponent
|
45
45
|
end
|
46
46
|
|
47
|
-
DetailsComponent.
|
47
|
+
DetailsComponent.controller_name
|
48
48
|
# => "details-component"
|
49
49
|
```
|
50
50
|
|
@@ -53,25 +53,32 @@ your class:
|
|
53
53
|
|
54
54
|
```ruby
|
55
55
|
class ModalComponent < ApplicationComponent
|
56
|
+
# Controller
|
56
57
|
has_stimulus_controller # sets the "controller" data attribute using :controller_name by default
|
57
58
|
has_stimulus_controller "click-outside"
|
58
59
|
has_stimulus_controller "scroll-lock", if: :open? # conditionally add the controller
|
59
60
|
has_stimulus_controller "scroll-lock", unless: :closed? # conditionally add the controller
|
60
61
|
|
62
|
+
# Action
|
61
63
|
has_stimulus_action "click", "onClick"
|
62
64
|
has_stimulus_action "click", "onClick", if: :open?
|
63
65
|
|
66
|
+
# Class
|
64
67
|
has_stimulus_class "open", "modal--open"
|
65
68
|
has_stimulus_class "width", -> { "modal--#{width}" } # resolve the class name dynamically
|
66
69
|
|
70
|
+
# Outlet
|
67
71
|
has_stimulus_outlet "outlet", ".selector"
|
68
72
|
|
73
|
+
# Param
|
69
74
|
has_stimulus_param id: 123
|
70
75
|
has_stimulus_param id: -> { id }
|
71
76
|
|
77
|
+
# Target
|
72
78
|
has_stimulus_target "target"
|
73
79
|
has_stimulus_target "target", controller: "other-controller"
|
74
80
|
|
81
|
+
# Value
|
75
82
|
has_stimulus_value "id", 123
|
76
83
|
has_stimulus_value "id", -> { id }
|
77
84
|
has_stimulus_value "id", -> { id }, controller: "other-controller"
|
@@ -86,4 +93,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
86
93
|
|
87
94
|
## Contributing
|
88
95
|
|
89
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
96
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tomasc/has_stimulus_attrs.
|
data/lib/has_stimulus_attrs.rb
CHANGED
@@ -28,6 +28,11 @@ module HasStimulusAttrs
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def has_stimulus_action(event, action, controller: nil, **options)
|
31
|
+
controller = case controller
|
32
|
+
when Proc then instance_exec(&controller)
|
33
|
+
else controller
|
34
|
+
end
|
35
|
+
|
31
36
|
key = :action
|
32
37
|
val = -> { stimulus_action((controller || controller_name), event, action).values.first }
|
33
38
|
|
@@ -35,6 +40,11 @@ module HasStimulusAttrs
|
|
35
40
|
end
|
36
41
|
|
37
42
|
def has_stimulus_class(name, value, controller: nil, **options)
|
43
|
+
controller = case controller
|
44
|
+
when Proc then instance_exec(&controller)
|
45
|
+
else controller
|
46
|
+
end
|
47
|
+
|
38
48
|
key = -> { stimulus_class((controller || controller_name), name, "N/A").keys.first }
|
39
49
|
val = -> {
|
40
50
|
v = case value
|
@@ -48,6 +58,11 @@ module HasStimulusAttrs
|
|
48
58
|
end
|
49
59
|
|
50
60
|
def has_stimulus_outlet(name, value, controller: nil, **options)
|
61
|
+
controller = case controller
|
62
|
+
when Proc then instance_exec(&controller)
|
63
|
+
else controller
|
64
|
+
end
|
65
|
+
|
51
66
|
key = -> { stimulus_outlet((controller || controller_name), name, "N/A").keys.first }
|
52
67
|
val = -> {
|
53
68
|
v = case value
|
@@ -62,6 +77,11 @@ module HasStimulusAttrs
|
|
62
77
|
end
|
63
78
|
|
64
79
|
def has_stimulus_param(name, value, controller: nil, **options)
|
80
|
+
controller = case controller
|
81
|
+
when Proc then instance_exec(&controller)
|
82
|
+
else controller
|
83
|
+
end
|
84
|
+
|
65
85
|
key = -> { stimulus_param((controller || controller_name), name, "N/A").keys.first }
|
66
86
|
val = -> {
|
67
87
|
v = case value
|
@@ -76,6 +96,11 @@ module HasStimulusAttrs
|
|
76
96
|
end
|
77
97
|
|
78
98
|
def has_stimulus_target(name, controller: nil, **options)
|
99
|
+
controller = case controller
|
100
|
+
when Proc then instance_exec(&controller)
|
101
|
+
else controller
|
102
|
+
end
|
103
|
+
|
79
104
|
key = -> { stimulus_target((controller || controller_name), name).keys.first }
|
80
105
|
val = -> { stimulus_target((controller || controller_name), name).values.first }
|
81
106
|
|
@@ -83,6 +108,11 @@ module HasStimulusAttrs
|
|
83
108
|
end
|
84
109
|
|
85
110
|
def has_stimulus_value(name, value = nil, controller: nil, **options)
|
111
|
+
controller = case controller
|
112
|
+
when Proc then instance_exec(&controller)
|
113
|
+
else controller
|
114
|
+
end
|
115
|
+
|
86
116
|
key = -> { stimulus_value((controller || controller_name), name, "N/A").keys.first }
|
87
117
|
val = -> {
|
88
118
|
v = case value
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_stimulus_attrs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Celizna
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-03-
|
12
|
+
date: 2023-03-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: stimulus_helpers
|
@@ -119,6 +119,7 @@ extra_rdoc_files: []
|
|
119
119
|
files:
|
120
120
|
- ".rubocop.yml"
|
121
121
|
- ".ruby-version"
|
122
|
+
- CHANGELOG.md
|
122
123
|
- Gemfile
|
123
124
|
- LICENSE
|
124
125
|
- README.md
|