phlex-stimulus 0.1.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5f51c97b602da2ffe25109fc4229e2980839134de4602912fcda7de9993331a
4
- data.tar.gz: 16897e82b71726d0b84e33b1f3b7fdb00387408f892180d7e529aa48ce53b177
3
+ metadata.gz: '01190c3e09b4d2381741d1191ba5b06f2222fed5c20246e69732f80672e742b0'
4
+ data.tar.gz: 79686f42a9561d53b17c94f7652c762ba9d43358ad710f8fd456129907ea0e76
5
5
  SHA512:
6
- metadata.gz: 304b3c3b6a8a9160a5e873864621cfa6a9f6047bd1808e93a595eb9f5a47a86fecde535b060278cdbaae49c546d24bc79dadba3ec1f3038920f4592b26e92fbe
7
- data.tar.gz: b815213393ae0d157571a6fe46fc081386bd657bfa71a4f93afc369b9bc1d1b65f25c404d67d8ed17ad24a66fbae9294bc849527742dbd9508c411b7f5ee7717
6
+ metadata.gz: 5e857f549c94fa68e8639f9e8bbcfda48626bbf2e3fb960d25d0e1490f97c453cce96174239c660532a1be4a2abd2be85a82221f3a8c2c380da24b5d9ed24fde
7
+ data.tar.gz: 7d459a8ff17f0626c0fc692b5b9fa929c2081815b8438e38a198518f10e94a16d0157a2c6e5ce94597c37914085d2a8216d121e8e67ffa51bb845af437d43334
data/CHANGELOG.md CHANGED
@@ -9,6 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  Add changes in new features here. Do not change the gem's version in pull/merge requests.
11
11
 
12
+ ## [0.2.0] - 29.07.2026
13
+
14
+ [Diff](https://github.com/espago/phlex-stimulus/compare/v0.1.3...v0.2.0)
15
+
16
+ - Add action parameter support
17
+
18
+ ## [0.1.3] - 28.07.2026
19
+
20
+ [Diff](https://github.com/espago/phlex-stimulus/compare/v0.1.2...v0.1.3)
21
+
22
+ - Fix tapioca compiler
23
+
12
24
  ## [0.1.2] - 27.07.2026
13
25
 
14
26
  [Diff](https://github.com/espago/phlex-stimulus/compare/v0.1.1...v0.1.2)
data/README.md CHANGED
@@ -210,6 +210,40 @@ This is the same as:
210
210
  div(data: { 'summary:redirected' => 'other#do' })
211
211
  ```
212
212
 
213
+ #### `param`
214
+
215
+ This method helps you get the names of parameters
216
+ given to stimulus actions.
217
+ You can read more about action parameters [here](https://stimulus.hotwired.dev/reference/https://stimulus.hotwired.dev/reference/actions#action-parameters).
218
+
219
+ ```rb
220
+ class SummaryController < Controller
221
+ self.controller_name = 'summary'
222
+
223
+ actions :foo
224
+ end
225
+
226
+ SummaryController.param('id') #=> "summary-id-param"
227
+ ```
228
+
229
+ You would use it like so to define a parameter for a stimulus action:
230
+
231
+ ```rb
232
+ div(
233
+ data: {
234
+ action: event('click', SummaryController.foo_action),
235
+ # will be available as `event.id` in the action
236
+ SummaryController.param('id') => 35,
237
+ },
238
+ )
239
+ ```
240
+
241
+ This is the same as:
242
+
243
+ ```rb
244
+ div(data: { 'summary:redirected' => 'other#do' })
245
+ ```
246
+
213
247
  ### Component Helpers
214
248
 
215
249
  There are some useful helper methods you can use in every phlex component.
@@ -59,6 +59,17 @@ module Phlex::Stimulus::Generators
59
59
 
60
60
  copy_template 'app/javascript/utils/misc.ts'
61
61
  copy_template 'app/javascript/utils/template.ts'
62
+
63
+ append_to_file File.join(destination_root, 'sorbet', 'tapioca', 'require.rb'), <<~RUBY
64
+
65
+ # monkey patch so that tapioca doesn't override
66
+ # the default `new` constructor
67
+ class Phlex::SGML
68
+ class << self
69
+ undef_method :new
70
+ end
71
+ end
72
+ RUBY
62
73
  end
63
74
 
64
75
  private
@@ -84,6 +84,16 @@ module Phlex::Stimulus
84
84
  @target_defs ||= []
85
85
  end
86
86
 
87
+ # Constructs a Stimulus action parameter name
88
+ # eg.
89
+ #
90
+ # SummaryController.param('id') #=> "summary-id-param"
91
+ #
92
+ #: (String) -> String
93
+ def param(param_name)
94
+ "#{controller_name}-#{param_name}-param"
95
+ end
96
+
87
97
  # Constructs a Stimulus dispatched event name
88
98
  # eg.
89
99
  #
@@ -3,6 +3,6 @@
3
3
 
4
4
  module Phlex
5
5
  module Stimulus
6
- VERSION = '0.1.2'
6
+ VERSION = '0.2.0'
7
7
  end
8
8
  end
@@ -23,7 +23,7 @@ module Tapioca
23
23
  def decorate
24
24
  root.create_path(constant) do |klass|
25
25
  klass.comments << RBI::Comment.new(
26
- <<~DOC
26
+ <<~DOC,
27
27
  A Phlex component that wraps the `#{constant.controller_name.inspect}` Stimulus controller.
28
28
 
29
29
  LINK: #{constant.controller_path}
@@ -43,12 +43,12 @@ module Tapioca
43
43
 
44
44
  Result: `#{action.full_name.inspect}`
45
45
  DOC
46
- )
46
+ ),
47
47
  ]
48
48
  mod.create_method(
49
49
  action.ruby_action_method_name,
50
50
  return_type: 'String',
51
- comments: comments,
51
+ comments: comments,
52
52
  )
53
53
  end
54
54
 
@@ -62,12 +62,12 @@ module Tapioca
62
62
 
63
63
  Result: `#{target.target_name.inspect}`
64
64
  DOC
65
- )
65
+ ),
66
66
  ]
67
67
  mod.create_method(
68
68
  target.ruby_target_method_name,
69
69
  return_type: 'String',
70
- comments: comments,
70
+ comments: comments,
71
71
  )
72
72
  end
73
73
 
data/rbi/phlex.rbi ADDED
@@ -0,0 +1,41 @@
1
+ # typed: true
2
+
3
+ class Phlex::HTML < Phlex::SGML
4
+ include ActionView::Helpers::AssetUrlHelper
5
+ include ActionView::Helpers::FormHelper
6
+ include ActionView::Helpers::AssetTagHelper
7
+ include ActionView::Helpers::NumberHelper
8
+
9
+ sig { params(key: T.untyped, options: T.untyped).returns(String) }
10
+ def t(key, **options); end
11
+
12
+ def label(**attributes); end
13
+
14
+ def form_authenticity_token(*_arg0, **_arg1, &_arg2); end
15
+
16
+ sig { returns(ApplicationController::HelperProxy) }
17
+ def view_context; end
18
+
19
+ # Outputs an `<svg>` tag.
20
+ #
21
+ # [MDN Docs](https://developer.mozilla.org/docs/Web/SVG/Element/svg)
22
+ # [Spec](https://html.spec.whatwg.org/#the-svg-element)
23
+ #
24
+ # source://phlex//lib/phlex/html.rb#20
25
+ #
26
+ #: (*untyped, **String) ?{ (Phlex::SVG) -> void } -> void
27
+ def svg(*args, **attrs, &block); end
28
+ end
29
+
30
+ class Phlex::SGML
31
+ #: (String?) -> void
32
+ def plain(content); end
33
+
34
+ #: (String?) -> void
35
+ def raw(content); end
36
+ end
37
+
38
+ module Phlex::Rails::Helpers::Translate
39
+ sig { params(key: String, _arg1: T.anything).returns(String) }
40
+ def t(key, **_arg1); end
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex-stimulus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Espago
@@ -130,6 +130,8 @@ files:
130
130
  - lib/phlex/stimulus/components/base.rb
131
131
  - lib/phlex/stimulus/components/controller.rb
132
132
  - lib/phlex/stimulus/version.rb
133
+ - lib/tapioca/dsl/compilers/phlex_controller.rb
134
+ - rbi/phlex.rbi
133
135
  - sorbet/config
134
136
  - sorbet/rbi/annotations/.gitattributes
135
137
  - sorbet/rbi/annotations/actionmailer.rbi
@@ -234,7 +236,6 @@ files:
234
236
  - sorbet/rbi/shims/gems/rails.rbi
235
237
  - sorbet/rbi/shims/gems/refract.rbi
236
238
  - sorbet/rbi/shims/gems/shoulda-context.rbi
237
- - sorbet/tapioca/compilers/phlex_controller.rb
238
239
  - sorbet/tapioca/config.yml
239
240
  - sorbet/tapioca/extensions/load_gem.rb
240
241
  - sorbet/tapioca/require.rb