actionview-svelte-handler 0.4.1 → 0.5.5

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: 97206777a02770810bd34a7ae25fc086fd957a70b5e16c9daa3ec7ce4db66fd1
4
+ data.tar.gz: 9c30b773a3d63d31adecb966b32b411849000e11aed787212263c08893364de9
5
5
  SHA512:
6
- metadata.gz: 2d465f91a8e4e24c80bf11485edcd4657de64f9f4a355c7d18ef204839eacd1168f3aa3d22b030432955b77355adbb126d61eba5d0dcb632039ef5e0cffcae95
7
- data.tar.gz: fb274f310264f5b719231b65b703985f9b4ead1828d1b27d631e9321e80b4ba7bb5c78ae4662d8e51f5bfb42781ca43210419a20589a9465a8fb24fad41a87d7
6
+ metadata.gz: c40dc6a7d81e65235970b8a63c53b72cf56df6a56e3cc4fbde48d29f11cd8eb8eb29118a94252518f6ecc2440cb1497c5caba80417ab1d0c81e0a0aaa77f8385
7
+ data.tar.gz: '08ca1b675e5357ca1ce8b12331933b70147588995a712e0edd977b3e65abe1ecb96a5cb7653adb2fa97ff01b3801383d20d5c8b346265efbaf95af8fdc0f0f3e'
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.5)
5
5
  rails (>= 7.0)
6
6
 
7
7
  GEM
@@ -1,13 +1,15 @@
1
- class Svelte::InstallGenerator < Rails::Generators::Base
2
- desc "This generator installs actionview-svelte-handler"
3
-
4
- source_root File.expand_path("templates/install", __dir__)
5
-
6
- def install
7
- copy_file "initializer.rb", "config/initializers/svelte.rb"
8
- insert_into_file "app/views/layouts/application.html.erb",
9
- " <%= svelte_tags %>\n",
10
- before: "</head>"
11
- `npm install #{Svelte.gem_dir} --install-links --save=false`
1
+ module Svelte
2
+ class InstallGenerator < Rails::Generators::Base
3
+ desc "This generator installs actionview-svelte-handler"
4
+
5
+ source_root File.expand_path("templates/install", __dir__)
6
+
7
+ def install
8
+ copy_file "initializer.rb", "config/initializers/svelte.rb"
9
+ insert_into_file "app/views/layouts/application.html.erb",
10
+ "\n <%= svelte_tags %>",
11
+ after: "<head>"
12
+ `npm install #{Gem::Specification.find_by_name("actionview-svelte-handler").gem_dir} --install-links --save=false`
13
+ end
12
14
  end
13
- end
15
+ 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.5"
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.5
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