opal_stimulus 0.1.1 → 0.1.3

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: 22842799923c6a3bad9030dd9971a4819c7c2fe37cb729c42c9780500b8ddbd4
4
- data.tar.gz: c1055d0c8854bef13a168eae8740f71b851d1488d39199bc4c4fc388cc72115c
3
+ metadata.gz: 123ac1d5e6112d3896cd623518b80732351357cfa11443dd8142fd07f32bec49
4
+ data.tar.gz: 41bbd48c083fc12359f979f8c8c5d5de2486acd56cf969c0af417edf9576c1d0
5
5
  SHA512:
6
- metadata.gz: a97cccb1708103c33bb3deb915d4bf505bd0ef1c016aa8e4e4fcd28eedd71db2e9ad2a66911188eb2c21479e86607921bb3e8d40b79ed61733e1e03f4d6c0772
7
- data.tar.gz: 1c03b955c9528e34fcd8489e2be91c1eb15f9ba8f6013815ec7e5169d48a281be9722919203fa72ba9b4360b20f380777f8aa40e2ce09f1c49e5120e7db8241c
6
+ metadata.gz: fa36ee6800f4e0795640c29c061be9b5c49cdc639c9b976381af2ea41863a40a22cac80368956edb1ca569712191f016764d4c4fa16ceb9583f5fca164b391f5
7
+ data.tar.gz: 9cea24bad6cbf6bfba34ab79026b8589b6f25c180ee210f263568e275a91a1da16314539ecda837e222637657e4534a4d8a421ec8e38aa9c6a90b1c67cca1605
data/CHANGELOG.md CHANGED
@@ -7,3 +7,12 @@
7
7
  ## [0.1.1] - 2025-07-02
8
8
 
9
9
  - Generate better stimulus controller name replacing controller class's namespace resolution operators to --
10
+
11
+ ## [0.1.2] - 2025-07-29
12
+
13
+ - Implement Opal Source maps https://opalrb.com/docs/guides/v1.4.1/source_maps.html
14
+
15
+ ## [0.1.3] - 2025-07-29
16
+
17
+ - Add missing ignore for app/assets/builds/opal.js.map
18
+ - Replace opal-browser with opal_proxy, check it out here.
data/README.md CHANGED
@@ -14,7 +14,7 @@ Execute:
14
14
 
15
15
  ```bash
16
16
  bundle install
17
- rails generate opal_stimulus:install
17
+ rails opal_stimulus:install
18
18
  ```
19
19
 
20
20
  Start application:
@@ -25,7 +25,7 @@ bin/dev
25
25
 
26
26
  ## Basic Example
27
27
 
28
- Here's a Hello World example with OpalStimulus. Compare with the [original JavaScript example](https://stimulus.hotwired.dev/handbook/hello-stimulus):
28
+ 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):
29
29
 
30
30
  **Ruby Controller:**
31
31
 
@@ -37,7 +37,7 @@ class HelloController < StimulusController
37
37
  self.targets = ["name", "output"]
38
38
 
39
39
  def greet
40
- output_target.content = "Hello, #{name_target.value}!"
40
+ output_target.text_content = "Hello, #{name_target.value}!"
41
41
  end
42
42
  end
43
43
  ```
@@ -40,6 +40,7 @@ window.Controller = Controller;
40
40
  end
41
41
  append_to_file ".gitignore", "/.opal-cache\n"
42
42
  append_to_file ".gitignore", "app/assets/builds/opal.js\n"
43
+ append_to_file ".gitignore", "app/assets/builds/opal.js.map\n"
43
44
  empty_directory APPLICATION_OPAL_STIMULUS_BIN_PATH
44
45
  empty_directory APPLICATION_OPAL_STIMULUS_PATH
45
46
  empty_directory "#{APPLICATION_OPAL_STIMULUS_PATH}/controllers"
data/lib/install/opal CHANGED
@@ -4,20 +4,30 @@
4
4
  require "bundler/setup"
5
5
  require "listen"
6
6
  require "opal"
7
- require "opal-browser"
8
7
 
9
- GEM_NAME = "opal_stimulus"
8
+ GEMS = ["opal_proxy", "opal_stimulus"]
10
9
 
11
- Opal.use_gem(GEM_NAME) rescue Opal.append_path(File.expand_path("lib", Bundler.rubygems.find_name(GEM_NAME).first.full_gem_path))
10
+ GEMS.each do |gem_name|
11
+ Opal.use_gem(gem_name) rescue Opal.append_path(File.expand_path("lib", Bundler.rubygems.find_name(gem_name).first.full_gem_path))
12
+ end
12
13
 
13
14
  Opal.append_path("app/opal")
14
15
 
15
16
  build = -> {
16
17
  puts "🔨 Compiling Opal..."
17
18
 
18
- builder = Opal::Builder.build("application", requirable: false)
19
+ builder = Opal::Builder.new
20
+
21
+ result = builder.build("application")
22
+
19
23
  output_path = "app/assets/builds/opal.js"
20
- File.write(output_path, builder.to_s)
24
+ sourcemap_path = "#{output_path}.map"
25
+
26
+ js_code = result.to_s
27
+ source_map_json = result.source_map.to_json
28
+
29
+ File.write(output_path, js_code + "\n//# sourceMappingURL=/assets/opal.js.map")
30
+ File.write(sourcemap_path, source_map_json)
21
31
 
22
32
  puts "✅ Compiled to #{output_path}"
23
33
  }
@@ -2,8 +2,7 @@
2
2
 
3
3
  require "opal"
4
4
  require "native"
5
- require "promise"
6
- require "browser/setup/full"
5
+ require "js/proxy"
7
6
 
8
7
  class StimulusController < `Controller`
9
8
  include Native::Wrapper
@@ -30,7 +29,11 @@ class StimulusController < `Controller`
30
29
 
31
30
  %x{
32
31
  #{self.stimulus_controller}.prototype[name] = function (...args) {
33
- return #{self.stimulus_controller}.prototype['$' + name].apply(this, args);
32
+ try {
33
+ return this['$' + name].apply(this, args);
34
+ } catch (e) {
35
+ console.error("Uncaught", e);
36
+ }
34
37
  }
35
38
  }
36
39
  end
@@ -40,12 +43,12 @@ class StimulusController < `Controller`
40
43
 
41
44
  targets.each do |target|
42
45
  define_method(target + "_target") do
43
- Browser::DOM::Element.new(`this[#{target + "Target"}]`)
46
+ JS::Proxy.new(`this[#{target + "Target"}]`)
44
47
  end
45
48
 
46
49
  define_method(target + "_targets") do
47
50
  `this[#{target + "Targets"}]`.map do |el|
48
- Browser::DOM::Element.new(el)
51
+ JS::Proxy.new(el)
49
52
  end
50
53
  end
51
54
 
@@ -80,12 +83,12 @@ class StimulusController < `Controller`
80
83
 
81
84
  outlets.each do |outlet|
82
85
  define_method(outlet + "_outlet") do
83
- Browser::DOM::Element.new(`this[#{outlet + "Outlet"}]`)
86
+ JS::Proxy.new(`this[#{outlet + "Outlet"}]`)
84
87
  end
85
88
 
86
89
  define_method(outlet + "_outlets") do
87
90
  `this[#{outlet + "Outlets"}]`.map do |outlet|
88
- Browser::DOM::Element.new(outlet)
91
+ JS::Proxy.new(outlet)
89
92
  end
90
93
  end
91
94
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpalStimulus
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
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.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Schito
@@ -38,19 +38,19 @@ dependencies:
38
38
  - !ruby/object:Gem::Version
39
39
  version: 3.9.0
40
40
  - !ruby/object:Gem::Dependency
41
- name: opal-browser
41
+ name: opal_proxy
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.3.5
46
+ version: 0.1.0
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: 0.3.5
53
+ version: 0.1.0
54
54
  description: Opal Stimulus provides a way to write Stimulus controllers in Ruby, leveraging
55
55
  the Opal compiler to convert Ruby code into JavaScript. This allows developers familiar
56
56
  with Ruby to use the Stimulus framework without needing to write JavaScript directly.