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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6e128e00d55cf10c4227ef9962666d22945291c51908ba5944a921e9409f038
4
- data.tar.gz: 89f864d3f18f58c4efce009b75f2dae79a88f0b9b5ccc6bce80db94e2910ef31
3
+ metadata.gz: 5c9116b1048a2590e52cae9e647b184d5892fc96f8a888170022620c9d68a08f
4
+ data.tar.gz: 50a787e09043f28ee9ad6bbb50fb283944cbc13512cd71afed51ff274cb8d6d2
5
5
  SHA512:
6
- metadata.gz: 2d465f91a8e4e24c80bf11485edcd4657de64f9f4a355c7d18ef204839eacd1168f3aa3d22b030432955b77355adbb126d61eba5d0dcb632039ef5e0cffcae95
7
- data.tar.gz: fb274f310264f5b719231b65b703985f9b4ead1828d1b27d631e9321e80b4ba7bb5c78ae4662d8e51f5bfb42781ca43210419a20589a9465a8fb24fad41a87d7
6
+ metadata.gz: 24fb49a029ef567cfe21f8495d6b46ae5b270873f155a4e3a1ce7653a5f235716fe3c22d433e90c14c4149129bd57d116b5351c0fc4afae5ba334b9003037137
7
+ data.tar.gz: 80b48d562be7b12e1cfc194b05122615241b1e623e92fd8234ca1347bba73ca4a1e54a8cd061d0598c98913745c7b40e4a162e8ec7b3a45c7e5ba08721f38be6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- actionview-svelte-handler (0.4.1)
4
+ actionview-svelte-handler (0.5.0)
5
5
  rails (>= 7.0)
6
6
 
7
7
  GEM
@@ -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 %>\n",
10
- before: "</head>"
9
+ "\n <%= svelte_tags %>",
10
+ after: "<head>"
11
11
  `npm install #{Svelte.gem_dir} --install-links --save=false`
12
12
  end
13
13
  end
@@ -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
- ERB.new(File.read("#{Svelte.gem_dir}/lib/svelte/templates/island.html.erb")).result_with_hash({ result:, locals: local_assigns, digest: "#{digest}"})
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
 
@@ -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
@@ -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 {
@@ -1,3 +1,3 @@
1
1
  module Svelte
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
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> {
@@ -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.1
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-05 00:00:00.000000000 Z
11
+ date: 2024-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails