opal_stimulus 0.1.7 → 0.1.9

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: e71677302b86e4d6f248a98170efd0dd24478c852b53f97747bb840d071cfccf
4
- data.tar.gz: 47241b7d3e38b2cefae139cab2f1fb8d4461cd6d591c4303c4eadf0ac84b1dbf
3
+ metadata.gz: ed5dba8c0e0b7d1f75d37a60d417f2e2af188a9adf0b249b9a55af55d67e0933
4
+ data.tar.gz: '0970f685ca56fb9d945615e53f0986bc1688c933c099aa550072fd11c1d15a9f'
5
5
  SHA512:
6
- metadata.gz: 0211e443ec8b5a3b214276882807f1f58bd56624a14f345a30a5789783ceb2aca6dd71dd7838d39b4771d89b40d1bd552a0a18a7013b502d5efa98c43b117e19
7
- data.tar.gz: 7805082cfc93be9f1906dc4e51e1dea39c6c3872b6646c85a0990d986a27a8dd0183ef35d15ae35e8416ca42f90da46a6c3cf38a09532cb82d78e3baed8757fb
6
+ metadata.gz: 30354047b38f078cd5d809b608011c6e26a17d7f3953d6ba20824f33cf5f5cca2673b2d9a1eed1bb6fce9a9c2a4d9783537bc52695c156b1cef7ad982ed570bb
7
+ data.tar.gz: 715f6366c20a94eb653fa66ba322baced833f604cb49ae1b2202f0f32563cfddbfeb1e0787e0f511dde49659939d1e876eb884777d166a28658063eb9d7fece6
data/CHANGELOG.md CHANGED
@@ -43,3 +43,12 @@
43
43
 
44
44
  - Add installation on Rails tests
45
45
  - Make it production ready enhancing `assets:precompile` with `opal_stimulus:build`
46
+
47
+ ## [0.1.8] - 2025-08-27
48
+
49
+ - Improve installation on Rails tests
50
+
51
+ ## [0.1.9] - 2025-11-14
52
+
53
+ - Revise README for Opal Stimulus by @elia
54
+ - Change README
data/README.md CHANGED
@@ -1,45 +1,46 @@
1
1
  # Opal Stimulus for Rails
2
2
 
3
- **Opal Stimulus** is a Stimulus wrapper made with Opal (a source-to-source Ruby to JavaScript compiler) that allows you to write Stimulus controllers in Ruby instead of JavaScript (It works only with Rails >= 7.2 and < 8.0.3).
3
+ Write your [Stimulus](https://stimulus.hotwired.dev/) controllers in Ruby instead of JavaScript! 🎉
4
+
5
+ **Opal Stimulus** uses the [Opal Ruby-to-JavaScript compiler](https://opalrb.com/) to bring the elegance of Ruby to your frontend controllers. If you love Ruby and prefer its syntax over JavaScript, this gem is for you.
6
+
7
+ **Compatibility:** Rails >= 7.2
4
8
 
5
9
  [![Ruby](https://github.com/josephschito/opal_stimulus/actions/workflows/main.yml/badge.svg)](https://github.com/josephschito/opal_stimulus/actions/workflows/main.yml)
6
10
 
7
- ## Installation
11
+ ## Click here to watch the walkthrough! 👇
8
12
 
9
- Add this line to your Gemfile:
13
+ [<img width="640" height="360" alt="opal stimulus" src="https://github.com/user-attachments/assets/3eba6d3f-c62a-4faa-b918-5181ec9e2efc" />](https://www.youtube.com/watch?v=YyaVUUMq7po)
10
14
 
11
- ```ruby
12
- gem 'opal_stimulus'
13
- ```
15
+ ## Quick Start
14
16
 
15
- Execute:
17
+ Add to your Rails app and get started in seconds:
16
18
 
17
19
  ```bash
18
- bundle install
20
+ bundle add opal_stimulus
19
21
  rails opal_stimulus:install
22
+ bin/dev
20
23
  ```
21
24
 
22
- Start application:
25
+ Generate your first Ruby controller:
23
26
 
24
27
  ```bash
25
- bin/dev
28
+ bin/rails generate opal_stimulus hello
26
29
  ```
27
30
 
28
- Create a new controller:
31
+ This creates `app/opal/controllers/hello_controller.rb`. If you have an existing JavaScript controller, you can remove it:
29
32
 
30
33
  ```bash
31
- bin/rails generate opal_stimulus hello
34
+ bin/rails destroy stimulus hello # removes app/javascript/controllers/hello_controller.js
32
35
  ```
33
- This command will create `app/opal/controllers/hello_controller.rb`
34
36
 
35
- ## Basic Example
37
+ ## Example: Hello World
36
38
 
37
- Here's a Hello World example with OpalStimulus. Compare with the [original JavaScript example](https://stimulus.hotwired.dev/#:~:text=%2F%2F%20hello_controller.js%0Aimport%20%7B%20Controller%20%7D%20from%20%22stimulus%22%0A%0Aexport%20default%20class%20extends%20Controller%20%7B%0A%20%20static%20targets%20%3D%20%5B%20%22name%22%2C%20%22output%22%20%5D%0A%0A%20%20greet()%20%7B%0A%20%20%20%20this.outputTarget.textContent%20%3D%0A%20%20%20%20%20%20%60Hello%2C%20%24%7Bthis.nameTarget.value%7D!%60%0A%20%20%7D%0A%7D):
39
+ Here's the classic Stimulus example, but in Ruby! Compare with the [JavaScript version](https://stimulus.hotwired.dev/#:~:text=%2F%2F%20hello_controller.js%0Aimport%20%7B%20Controller%20%7D%20from%20%22stimulus%22%0A%0Aexport%20default%20class%20extends%20Controller%20%7B%0A%20%20static%20targets%20%3D%20%5B%20%22name%22%2C%20%22output%22%20%5D%0A%0A%20%20greet()%20%7B%0A%20%20%20%20this.outputTarget.textContent%20%3D%0A%20%20%20%20%20%20%60Hello%2C%20%24%7Bthis.nameTarget.value%7D!%60%0A%20%20%7D%0A%7D).
38
40
 
39
- **Ruby Controller:**
41
+ **Ruby Controller (`app/opal/controllers/hello_controller.rb`):**
40
42
 
41
43
  ```ruby
42
- # app/opal/controllers/hello_controller.rb
43
44
  class HelloController < StimulusController
44
45
  self.targets = ["name", "output"]
45
46
 
@@ -49,31 +50,30 @@ class HelloController < StimulusController
49
50
  end
50
51
  ```
51
52
 
52
- **HTML:**
53
+ **HTML (unchanged from regular Stimulus):**
53
54
 
54
55
  ```html
55
56
  <div data-controller="hello">
56
57
  <input data-hello-target="name" type="text">
57
-
58
- <button data-action="click->hello#greet">
59
- Greet
60
- </button>
61
-
62
- <span data-hello-target="output">
63
- </span>
58
+ <button data-action="click->hello#greet">Greet</button>
59
+ <span data-hello-target="output"></span>
64
60
  </div>
65
61
  ```
66
62
 
67
- **Notes:**
63
+ ### Key Differences from JavaScript Stimulus
68
64
 
69
- - In general any reference method is snake cased, so `container` target will produce `container_target` and not ~`containerTarget`~
70
- - Any `target`, `element`, `document`, `window` and `event` is a `JS::Proxy` instance, that provides a dynamic interface to JavaScript objects in Opal
71
- - The frontend definition part will remain the same
65
+ - **Snake case**: JavaScript's `containerTarget` becomes `container_target` in Ruby
66
+ - **DOM objects**: All `target`, `element`, `document`, `window`, and `event` objects are `JS::Proxy` instances that provide Ruby-friendly access to JavaScript APIs
67
+ - **HTML stays the same**: Your templates and data attributes work exactly like regular Stimulus
72
68
 
69
+ ## Reference Examples
73
70
 
74
- ## Some examples based on [Stimulus Reference](https://stimulus.hotwired.dev/reference/controllers)
71
+ Based on the [Stimulus Reference](https://stimulus.hotwired.dev/reference/controllers), here's how common patterns work in Ruby:
75
72
 
76
73
  ### Lifecycle Callbacks
74
+
75
+ > 📚 [Stimulus Lifecycle Callbacks Reference](https://stimulus.hotwired.dev/reference/lifecycle-callbacks)
76
+
77
77
  ```ruby
78
78
  class AlertController < StimulusController
79
79
  def initialize; end
@@ -82,12 +82,15 @@ class AlertController < StimulusController
82
82
  end
83
83
  ```
84
84
 
85
- ### Actions
85
+ ### Actions & Events
86
+
87
+ > 📚 [Stimulus Actions Reference](https://stimulus.hotwired.dev/reference/actions)
88
+
86
89
  ```ruby
87
90
  class WindowResizeController < StimulusController
88
91
  def resized(event)
89
92
  if !@resized && event.target.inner_width >= 1080
90
- puts "Full HD? Nice!"
93
+ puts "Full HD detected!"
91
94
  @resized = true
92
95
  end
93
96
  end
@@ -95,6 +98,9 @@ end
95
98
  ```
96
99
 
97
100
  ### Targets
101
+
102
+ > 📚 [Stimulus Targets Reference](https://stimulus.hotwired.dev/reference/targets)
103
+
98
104
  ```ruby
99
105
  class ContainerController < StimulusController
100
106
  self.targets = ["container"]
@@ -112,6 +118,9 @@ end
112
118
  ```
113
119
 
114
120
  ### Outlets
121
+
122
+ > 📚 [Stimulus Outlets Reference](https://stimulus.hotwired.dev/reference/outlets)
123
+
115
124
  ```ruby
116
125
  class ChatController < StimulusController
117
126
  self.outlets = [ "user-status" ]
@@ -125,6 +134,9 @@ end
125
134
  ```
126
135
 
127
136
  ### Values
137
+
138
+ > 📚 [Stimulus Values Reference](https://stimulus.hotwired.dev/reference/values)
139
+
128
140
  ```ruby
129
141
  class LoaderController < StimulusController
130
142
  self.values = { url: :string }
@@ -146,18 +158,24 @@ end
146
158
  ```
147
159
 
148
160
  ### CSS Classes
161
+
162
+ > 📚 [Stimulus CSS Classes Reference](https://stimulus.hotwired.dev/reference/css-classes)
163
+
149
164
  ```ruby
150
165
  class SearchController < StimulusController
151
- self.classes = [ "loading" ]
166
+ self.classes = ["loading"]
152
167
 
153
- def loadResults
154
- element.class_list.add loading_class
168
+ def load_results
169
+ element.class_list.add(loading_class)
155
170
  end
156
171
  end
157
172
  ```
158
173
 
159
- ## Extra tools
160
- ### Window
174
+ ## Working with the DOM
175
+
176
+ Opal Stimulus gives you Ruby-friendly access to all the browser APIs you know and love:
177
+
178
+ ### `window`
161
179
  ```ruby
162
180
  class WindowController < StimulusController
163
181
  def connect
@@ -169,20 +187,25 @@ class WindowController < StimulusController
169
187
  end
170
188
  ```
171
189
 
172
- ### Document
190
+ ### `document`
173
191
  ```ruby
174
192
  class DocumentController < StimulusController
175
193
  def connect
176
- headers = document.querySelectorAll("h1")
177
- headers.each do |h1|
194
+ document.querySelectorAll("h1").each do |h1|
178
195
  h1.text_content = "Opal is great!"
179
196
  end
180
197
  end
181
198
  end
182
199
  ```
183
200
 
184
- ## Run tests
185
- `bundle exec rake`
201
+
202
+ ## Development
203
+
204
+ Run the test suite:
205
+
206
+ ```bash
207
+ bundle exec rake
208
+ ```
186
209
 
187
210
  ## Contributing
188
211
 
@@ -33,8 +33,8 @@ if File.exist? APPLICATION_LAYOUT_PATH
33
33
  empty_directory APPLICATION_OPAL_STIMULUS_BIN_PATH
34
34
  empty_directory APPLICATION_OPAL_STIMULUS_PATH
35
35
  empty_directory "#{APPLICATION_OPAL_STIMULUS_PATH}/controllers"
36
- create_file "#{APPLICATION_OPAL_STIMULUS_PATH}/controllers/.keep"
37
- create_file "app/assets/builds/.keep"
36
+ keep_file "#{APPLICATION_OPAL_STIMULUS_PATH}/controllers"
37
+ keep_file "app/assets/builds"
38
38
  copy_file "#{__dir__}/dev", "#{APPLICATION_OPAL_STIMULUS_BIN_PATH}/dev"
39
39
  FileUtils.chmod("+x", "#{APPLICATION_OPAL_STIMULUS_BIN_PATH}/dev")
40
40
  copy_file "#{__dir__}/application.rb", "#{APPLICATION_OPAL_STIMULUS_PATH}/application.rb"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpalStimulus
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.9"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal_stimulus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Schito
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  requirements: []
140
- rubygems_version: 3.6.9
140
+ rubygems_version: 3.7.2
141
141
  specification_version: 4
142
142
  summary: 'Opal Stimulus: Write Stimulus controllers in Ruby'
143
143
  test_files: []