opal_stimulus 0.1.0 → 0.1.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/CHANGELOG.md +4 -0
- data/README.md +18 -3
- data/lib/install/opal +1 -0
- data/lib/opal_stimulus/stimulus_controller.rb +11 -13
- data/lib/opal_stimulus/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22842799923c6a3bad9030dd9971a4819c7c2fe37cb729c42c9780500b8ddbd4
|
4
|
+
data.tar.gz: c1055d0c8854bef13a168eae8740f71b851d1488d39199bc4c4fc388cc72115c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a97cccb1708103c33bb3deb915d4bf505bd0ef1c016aa8e4e4fcd28eedd71db2e9ad2a66911188eb2c21479e86607921bb3e8d40b79ed61733e1e03f4d6c0772
|
7
|
+
data.tar.gz: 1c03b955c9528e34fcd8489e2be91c1eb15f9ba8f6013815ec7e5169d48a281be9722919203fa72ba9b4360b20f380777f8aa40e2ce09f1c49e5120e7db8241c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# Opal Stimulus for Rails
|
2
2
|
|
3
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).
|
4
4
|
|
@@ -10,13 +10,19 @@ Add this line to your Gemfile:
|
|
10
10
|
gem 'opal_stimulus'
|
11
11
|
```
|
12
12
|
|
13
|
-
|
13
|
+
Execute:
|
14
14
|
|
15
15
|
```bash
|
16
16
|
bundle install
|
17
17
|
rails generate opal_stimulus:install
|
18
18
|
```
|
19
19
|
|
20
|
+
Start application:
|
21
|
+
|
22
|
+
```bash
|
23
|
+
bin/dev
|
24
|
+
```
|
25
|
+
|
20
26
|
## Basic Example
|
21
27
|
|
22
28
|
Here's a Hello World example with OpalStimulus. Compare with the [original JavaScript example](https://stimulus.hotwired.dev/handbook/hello-stimulus):
|
@@ -25,11 +31,13 @@ Here's a Hello World example with OpalStimulus. Compare with the [original JavaS
|
|
25
31
|
|
26
32
|
```ruby
|
27
33
|
# app/opal/controllers/hello_controller.rb
|
34
|
+
# new controllers will be automatically added to app/opal/controllers_requires.rb
|
35
|
+
# (ordered files load is not supported yet)
|
28
36
|
class HelloController < StimulusController
|
29
37
|
self.targets = ["name", "output"]
|
30
38
|
|
31
39
|
def greet
|
32
|
-
output_target.
|
40
|
+
output_target.content = "Hello, #{name_target.value}!"
|
33
41
|
end
|
34
42
|
end
|
35
43
|
```
|
@@ -49,6 +57,13 @@ end
|
|
49
57
|
</div>
|
50
58
|
```
|
51
59
|
|
60
|
+
**Result**
|
61
|
+
|
62
|
+
https://github.com/user-attachments/assets/c51ed28c-13d2-4e06-b882-1cc997e9627b
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
52
67
|
## Contributing
|
53
68
|
|
54
69
|
Bug reports and pull requests are welcome on GitHub at https://github.com/josephschito/opal_stimulus.
|
data/lib/install/opal
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require "opal"
|
4
4
|
require "native"
|
5
|
+
require "promise"
|
6
|
+
require "browser/setup/full"
|
5
7
|
|
6
8
|
class StimulusController < `Controller`
|
7
9
|
include Native::Wrapper
|
@@ -20,20 +22,12 @@ class StimulusController < `Controller`
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def self.stimulus_name
|
23
|
-
self.name.gsub(/Controller$/, "").gsub(/([a-z])([A-Z])/, '\1-\2').downcase
|
25
|
+
self.name.gsub(/Controller$/, "").gsub(/([a-z])([A-Z])/, '\1-\2').gsub("::", "--").downcase
|
24
26
|
end
|
25
27
|
|
26
28
|
def self.method_added(name)
|
27
29
|
return if DEFAULT_GETTERS.include?(name)
|
28
30
|
|
29
|
-
self.bridge_method(name)
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.register(controller)
|
33
|
-
`Stimulus.register(#{self.stimulus_name}, #{controller})`
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.bridge_method(name)
|
37
31
|
%x{
|
38
32
|
#{self.stimulus_controller}.prototype[name] = function (...args) {
|
39
33
|
return #{self.stimulus_controller}.prototype['$' + name].apply(this, args);
|
@@ -46,11 +40,13 @@ class StimulusController < `Controller`
|
|
46
40
|
|
47
41
|
targets.each do |target|
|
48
42
|
define_method(target + "_target") do
|
49
|
-
`
|
43
|
+
Browser::DOM::Element.new(`this[#{target + "Target"}]`)
|
50
44
|
end
|
51
45
|
|
52
46
|
define_method(target + "_targets") do
|
53
|
-
`
|
47
|
+
`this[#{target + "Targets"}]`.map do |el|
|
48
|
+
Browser::DOM::Element.new(el)
|
49
|
+
end
|
54
50
|
end
|
55
51
|
|
56
52
|
define_method("has_" + target + "_target") do
|
@@ -84,11 +80,13 @@ class StimulusController < `Controller`
|
|
84
80
|
|
85
81
|
outlets.each do |outlet|
|
86
82
|
define_method(outlet + "_outlet") do
|
87
|
-
`
|
83
|
+
Browser::DOM::Element.new(`this[#{outlet + "Outlet"}]`)
|
88
84
|
end
|
89
85
|
|
90
86
|
define_method(outlet + "_outlets") do
|
91
|
-
`
|
87
|
+
`this[#{outlet + "Outlets"}]`.map do |outlet|
|
88
|
+
Browser::DOM::Element.new(outlet)
|
89
|
+
end
|
92
90
|
end
|
93
91
|
|
94
92
|
define_method("has_" + outlet + "_outlet") do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal_stimulus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Schito
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: opal
|
@@ -37,6 +37,20 @@ dependencies:
|
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: 3.9.0
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: opal-browser
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.3.5
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.3.5
|
40
54
|
description: Opal Stimulus provides a way to write Stimulus controllers in Ruby, leveraging
|
41
55
|
the Opal compiler to convert Ruby code into JavaScript. This allows developers familiar
|
42
56
|
with Ruby to use the Stimulus framework without needing to write JavaScript directly.
|
@@ -83,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
97
|
- !ruby/object:Gem::Version
|
84
98
|
version: '0'
|
85
99
|
requirements: []
|
86
|
-
rubygems_version: 3.6.
|
100
|
+
rubygems_version: 3.6.9
|
87
101
|
specification_version: 4
|
88
102
|
summary: 'Opal Stimulus: Write Stimulus controllers in Ruby'
|
89
103
|
test_files: []
|