actionview-svelte-handler 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a8d743d73bb7a9c2d20b16c9ba153ee83bb558800780f9913ed92edd6b9c3f5
4
- data.tar.gz: 2b506e0b2402d4c236e24caaf1d8ee09db301585568bfbbb3f5e68c90dd21e3a
3
+ metadata.gz: 9167cd64c58c539f35cd795e5c6b4f753f2c66ba7abee1b83f9846dc064498a2
4
+ data.tar.gz: fe6da9a5f4de7c21411aaefccd5847505be84b2944db2a42f9c475873729aabf
5
5
  SHA512:
6
- metadata.gz: 37254f91eb9aded2426d894cf44047af5b0d31c73f99ec9946aff73518301b24d537c63888151e1a542fcd725360036de91551450893c83337f7dba3a87de1f0
7
- data.tar.gz: 1536e077c112bd44b1785792892f39f0cd5ea4057bf5a23ee6758cdcd94631ce93fd2ff787b4164a7d99648f64fd49f2c17064f32353069cfd995fe78006821c
6
+ metadata.gz: 18eac635e7134c55e4d3907d44635558ec7f53e2e831339f48e1d9f32c971c0f910999daf41975f63c75aeaafc8f35cca1f7e66bdd34014e469e25bc9a7575fb
7
+ data.tar.gz: 42633207280f2c079fc378ce90ac1594110d997419db831315508b15522b6f31c0d2a3138de1f86e6ad6c14ae65b6e1a1706f673adf1bdef16a2db54ad18956f
@@ -1,7 +1,6 @@
1
1
  module Svelte
2
- class Handler < ActionView::Template::Handlers::Raw
2
+ class Handler
3
3
  include ActionView::Helpers::JavaScriptHelper
4
-
5
4
  def call(template, source)
6
5
  file = Tempfile.new
7
6
  src = Tempfile.new
@@ -20,28 +19,35 @@ module Svelte
20
19
  file.rewind
21
20
 
22
21
  compiled = JSON.parse(%x(bun run #{file.path})).deep_symbolize_keys
22
+
23
+ return <<-RUBY
24
+ Svelte::Handler.generate_island(#{(compiled.dig(:js, :code) || "").dump}, local_assigns.to_json.presence)
25
+ RUBY
26
+ end
23
27
 
24
- source = <<-HTML
28
+ def self.call(template, source)
29
+ new.call(template, source)
30
+ end
31
+
32
+ def self.generate_island(js, props)
33
+ return <<-HTML
25
34
  <is-land on:visible on:idle>
26
35
  <template data-island>
27
36
  <div id="svelte-app-client">
28
37
  </div>
29
38
 
30
39
  <script type="module">
31
- #{compiled.dig(:js, :code)}
40
+ #{js}
32
41
 
33
- new Component({ target: document.getElementById("svelte-app-client") });
42
+ new Component({
43
+ target: document.getElementById("svelte-app-client"),
44
+ props: JSON.parse(#{props.to_json.presence || "{}"})
45
+ });
34
46
  </script>
35
47
 
36
48
  </template>
37
49
  </is-land>
38
50
  HTML
39
-
40
- super
41
- end
42
-
43
- def self.call(template, source)
44
- new.call(template, source)
45
51
  end
46
52
  end
47
53
  end
@@ -1,3 +1,3 @@
1
1
  module Svelte
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionview-svelte-handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - reesericci