actionview-svelte-handler 0.4.1 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/generators/svelte/install_generator.rb +14 -12
- 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: 97206777a02770810bd34a7ae25fc086fd957a70b5e16c9daa3ec7ce4db66fd1
         | 
| 4 | 
            +
              data.tar.gz: 9c30b773a3d63d31adecb966b32b411849000e11aed787212263c08893364de9
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: c40dc6a7d81e65235970b8a63c53b72cf56df6a56e3cc4fbde48d29f11cd8eb8eb29118a94252518f6ecc2440cb1497c5caba80417ab1d0c81e0a0aaa77f8385
         | 
| 7 | 
            +
              data.tar.gz: '08ca1b675e5357ca1ce8b12331933b70147588995a712e0edd977b3e65abe1ecb96a5cb7653adb2fa97ff01b3801383d20d5c8b346265efbaf95af8fdc0f0f3e'
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
| @@ -1,13 +1,15 @@ | |
| 1 | 
            -
             | 
| 2 | 
            -
               | 
| 3 | 
            -
             | 
| 4 | 
            -
               | 
| 5 | 
            -
             | 
| 6 | 
            -
               | 
| 7 | 
            -
                 | 
| 8 | 
            -
             | 
| 9 | 
            -
                   | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 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
         | 
    
        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.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- | 
| 11 | 
            +
            date: 2024-08-06 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         |