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 +4 -4
- data/lib/svelte/handler.rb +17 -11
- data/lib/svelte/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9167cd64c58c539f35cd795e5c6b4f753f2c66ba7abee1b83f9846dc064498a2
|
4
|
+
data.tar.gz: fe6da9a5f4de7c21411aaefccd5847505be84b2944db2a42f9c475873729aabf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18eac635e7134c55e4d3907d44635558ec7f53e2e831339f48e1d9f32c971c0f910999daf41975f63c75aeaafc8f35cca1f7e66bdd34014e469e25bc9a7575fb
|
7
|
+
data.tar.gz: 42633207280f2c079fc378ce90ac1594110d997419db831315508b15522b6f31c0d2a3138de1f86e6ad6c14ae65b6e1a1706f673adf1bdef16a2db54ad18956f
|
data/lib/svelte/handler.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Svelte
|
2
|
-
class Handler
|
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
|
-
|
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
|
-
#{
|
40
|
+
#{js}
|
32
41
|
|
33
|
-
new Component({
|
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
|
data/lib/svelte/version.rb
CHANGED