actionview-svelte-handler 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/generators/svelte/install_generator.rb +2 -2
- data/lib/svelte/handler.rb +4 -2
- data/lib/svelte/helpers.rb +1 -2
- data/lib/svelte/js/builder.js +2 -2
- data/lib/svelte/version.rb +1 -1
- data/lib/ts/builder.ts +4 -3
- data/lib/ts/types/builder.d.ts +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c9116b1048a2590e52cae9e647b184d5892fc96f8a888170022620c9d68a08f
|
4
|
+
data.tar.gz: 50a787e09043f28ee9ad6bbb50fb283944cbc13512cd71afed51ff274cb8d6d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24fb49a029ef567cfe21f8495d6b46ae5b270873f155a4e3a1ce7653a5f235716fe3c22d433e90c14c4149129bd57d116b5351c0fc4afae5ba334b9003037137
|
7
|
+
data.tar.gz: 80b48d562be7b12e1cfc194b05122615241b1e623e92fd8234ca1347bba73ca4a1e54a8cd061d0598c98913745c7b40e4a162e8ec7b3a45c7e5ba08721f38be6
|
data/Gemfile.lock
CHANGED
@@ -6,8 +6,8 @@ class Svelte::InstallGenerator < Rails::Generators::Base
|
|
6
6
|
def install
|
7
7
|
copy_file "initializer.rb", "config/initializers/svelte.rb"
|
8
8
|
insert_into_file "app/views/layouts/application.html.erb",
|
9
|
-
" <%= svelte_tags
|
10
|
-
|
9
|
+
"\n <%= svelte_tags %>",
|
10
|
+
after: "<head>"
|
11
11
|
`npm install #{Svelte.gem_dir} --install-links --save=false`
|
12
12
|
end
|
13
13
|
end
|
data/lib/svelte/handler.rb
CHANGED
@@ -53,8 +53,10 @@ module Svelte
|
|
53
53
|
|
54
54
|
Rails.cache.write("svelte/template/client/" + '#{digest}', result[:compiled][:client], expires_in: 14.days)
|
55
55
|
Rails.cache.write("svelte/template/server/" + '#{digest}', result[:compiled][:server], expires_in: 14.days)
|
56
|
-
|
57
|
-
|
56
|
+
|
57
|
+
content_for(:head, (result.dig(:server, :head) || "").html_safe)
|
58
|
+
|
59
|
+
ERB.new(File.read("#{Svelte.gem_dir}/lib/svelte/templates/island.html.erb")).result_with_hash({ result:, locals: local_assigns, digest: "#{digest}", bind: binding })
|
58
60
|
RUBY
|
59
61
|
end
|
60
62
|
|
data/lib/svelte/helpers.rb
CHANGED
@@ -4,13 +4,12 @@ module Svelte
|
|
4
4
|
def svelte_tags
|
5
5
|
js = <<-JS
|
6
6
|
import "https://esm.sh/@11ty/is-land";
|
7
|
-
import "https://esm.sh/@11ty/is-land/is-land-autoinit.js";
|
8
7
|
import { readable } from "https://esm.sh/svelte/store"
|
9
8
|
|
10
9
|
window.props = readable(JSON.parse("#{j(Svelte.props.to_json)}"))
|
11
10
|
JS
|
12
11
|
|
13
|
-
tag.script(js.html_safe, type: "module")
|
12
|
+
content_for(:head) + "\n" + tag.script(js.html_safe, type: "module") # steep:ignore RequiredBlockMissing
|
14
13
|
end
|
15
14
|
|
16
15
|
delegate :destructure_attrs, to: :class
|
data/lib/svelte/js/builder.js
CHANGED
@@ -95,8 +95,8 @@ class Builder {
|
|
95
95
|
const Component = importFromStringSync(output, {
|
96
96
|
globals: { props: this.props }
|
97
97
|
}).default;
|
98
|
-
const { html, css } = await Component.render(this.locals);
|
99
|
-
return { output, html, css: css.code };
|
98
|
+
const { html, css, head } = await Component.render(this.locals);
|
99
|
+
return { output, html, head, css: css.code };
|
100
100
|
}
|
101
101
|
async build() {
|
102
102
|
try {
|
data/lib/svelte/version.rb
CHANGED
data/lib/ts/builder.ts
CHANGED
@@ -11,6 +11,7 @@ export interface BuildSuccess {
|
|
11
11
|
server: {
|
12
12
|
html: string
|
13
13
|
css: string
|
14
|
+
head: string
|
14
15
|
} | null
|
15
16
|
compiled: {
|
16
17
|
client: string
|
@@ -138,16 +139,16 @@ class Builder {
|
|
138
139
|
return recast.print(ast).code
|
139
140
|
}
|
140
141
|
|
141
|
-
async server (): Promise<{ output: string, html: string, css: string }> {
|
142
|
+
async server (): Promise<{ output: string, html: string, css: string, head: string }> {
|
142
143
|
const output = this.compiled?.server || (await this.bundle('ssr')) // eslint-disable-line
|
143
144
|
|
144
145
|
const Component = importFromStringSync(output, {
|
145
146
|
globals: { props: this.props }
|
146
147
|
}).default
|
147
148
|
|
148
|
-
const { html, css } = await Component.render(this.locals)
|
149
|
+
const { html, css, head } = await Component.render(this.locals)
|
149
150
|
|
150
|
-
return { output, html, css: css.code }
|
151
|
+
return { output, html, head, css: css.code }
|
151
152
|
}
|
152
153
|
|
153
154
|
async build (): Promise<BuildResult> {
|
data/lib/ts/types/builder.d.ts
CHANGED
@@ -4,6 +4,7 @@ export interface BuildSuccess {
|
|
4
4
|
server: {
|
5
5
|
html: string;
|
6
6
|
css: string;
|
7
|
+
head: string;
|
7
8
|
} | null;
|
8
9
|
compiled: {
|
9
10
|
client: string;
|
@@ -36,6 +37,7 @@ declare class Builder {
|
|
36
37
|
output: string;
|
37
38
|
html: string;
|
38
39
|
css: string;
|
40
|
+
head: string;
|
39
41
|
}>;
|
40
42
|
build(): Promise<BuildResult>;
|
41
43
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionview-svelte-handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- reesericci
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|