has_stimulus_attrs 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e702f304344f1da5c028901abba68b02aec77c575cef53dedc213aa5b684c68d
4
- data.tar.gz: 15d9bd70b5bf3a905a8b7a4a32f685763e0f57a0a7c38f340d989aaf6191f28a
3
+ metadata.gz: 30733a72610251b36d86685a77eba3bc28689499b3a609c38d04651126fb6dc9
4
+ data.tar.gz: 47f05a93f75c3c4b2e2808d72b7e94e39a5ce45aba99042162a1109e6e73eb89
5
5
  SHA512:
6
- metadata.gz: 7fb5adfb5f24e1434260cb128ed8055238498e93a21ae97d94a4ebfffab95dab23646db78cadec1598482ab3f5b5db7a2e9c59181cbaeab7a8f95dd3d6deb1bd
7
- data.tar.gz: 598f5ad7b233c3ba368d897fa8fa4a57ca9601f790c9afe843e5df625b432c1d0bfeb8a371843f1c760fdacaae600b1fbc84b6de1ac8816ca83b4327c7d9452f
6
+ metadata.gz: bdfda50766bfe7be5070c9113dec375ff207204556fd81260e190d6bd4bd93fe2f537c0fb43e58757ab03f59897876ae0e61c24704ebe8d5d7fe9491b0cf8a05
7
+ data.tar.gz: e25d1a3e77cff0090515040ff4b1dc8053bf0e6136f710337f2cd527def9fa0bbcf198769d7e456860bf5f7b2457c13b0cfe135804ed2d20dd7cb7048378d5bf
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.new.controller_name
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/[USERNAME]/has_stimulus_attrs.
96
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tomasc/has_stimulus_attrs.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HasStimulusAttrs
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
@@ -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.1.0
4
+ version: 0.1.1
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-11 00:00:00.000000000 Z
12
+ date: 2023-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: stimulus_helpers