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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e2b9722851b24c4870cc76265994a889813d4d59e826e4e945c4859b9de9f873
4
- data.tar.gz: 6c9df0ea9b687094f3cb266abacb8824456809dcfdcd100a744fe04c667bf8bf
3
+ metadata.gz: 22842799923c6a3bad9030dd9971a4819c7c2fe37cb729c42c9780500b8ddbd4
4
+ data.tar.gz: c1055d0c8854bef13a168eae8740f71b851d1488d39199bc4c4fc388cc72115c
5
5
  SHA512:
6
- metadata.gz: 05edb688629527e884549e82cb92a375b1006735d7c082ac2a013c553b3e7214ef1ae90160b904528626d3804ac281c26987480cf1081b84331566884d413675
7
- data.tar.gz: aaad0562773f879a73bf66eed31966a8048b766056e12bf401a3f4785833d19f14b6381a9d8cd2fef68e0c1cb6239443adee71ac7176c9ac7929c800800bb473
6
+ metadata.gz: a97cccb1708103c33bb3deb915d4bf505bd0ef1c016aa8e4e4fcd28eedd71db2e9ad2a66911188eb2c21479e86607921bb3e8d40b79ed61733e1e03f4d6c0772
7
+ data.tar.gz: 1c03b955c9528e34fcd8489e2be91c1eb15f9ba8f6013815ec7e5169d48a281be9722919203fa72ba9b4360b20f380777f8aa40e2ce09f1c49e5120e7db8241c
data/CHANGELOG.md CHANGED
@@ -3,3 +3,7 @@
3
3
  ## [0.1.0] - 2025-03-27
4
4
 
5
5
  - Initial release
6
+
7
+ ## [0.1.1] - 2025-07-02
8
+
9
+ - Generate better stimulus controller name replacing controller class's namespace resolution operators to --
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # opal_stimulus for Rails
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
- Then execute:
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.JS[:textContent] = "Hello, #{name_target.JS[:value]}!"
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
@@ -4,6 +4,7 @@
4
4
  require "bundler/setup"
5
5
  require "listen"
6
6
  require "opal"
7
+ require "opal-browser"
7
8
 
8
9
  GEM_NAME = "opal_stimulus"
9
10
 
@@ -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
- `return this[#{target + "Target"}]`
43
+ Browser::DOM::Element.new(`this[#{target + "Target"}]`)
50
44
  end
51
45
 
52
46
  define_method(target + "_targets") do
53
- `return this[#{target + "Targets"}]`
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
- `return this[#{outlet + "Outlet"}]`
83
+ Browser::DOM::Element.new(`this[#{outlet + "Outlet"}]`)
88
84
  end
89
85
 
90
86
  define_method(outlet + "_outlets") do
91
- `return this[#{outlet + "Outlets"}]`
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpalStimulus
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
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.0
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: 2025-06-19 00:00:00.000000000 Z
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.2
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: []