inertia_rails 1.11.1 → 1.12.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: 60a2f2a20da36323f792051d3a0c1327b3f085f78e8fed5906064e8892c516d9
4
- data.tar.gz: c9a40fd17509def36b88862a671f98a4ed839f158ffd0959a66aba3023ee6084
3
+ metadata.gz: 468c8c88d85da84a010be47c474e9d8d1ed4735d5d83cd8058038401e322334c
4
+ data.tar.gz: ce4ccdf41063f88495e8829dbefc4eb92936850d9f4da8a4f51e907eff9f90f4
5
5
  SHA512:
6
- metadata.gz: c136e534632a852b4d92ec7303cb5eba67fed88706cf28cc16e8bc541fda5320f9f09aa3e92f481951fe93390e30714813f0950bd67b75389b933634721d8dd5
7
- data.tar.gz: b6f8568840f971249c90142afd6b20adf39b4d99a4864d952ddbedcbfdfb49884a6e35f9c419fd180d7abf50590bee70863f3766b94e6883a171b8995cef5f9e
6
+ metadata.gz: 6a097f6f871a2b7b294e5e497d051c8d677230f8a600e4a602a73b742e76bce34686b7b76d3287bb2d5af897a3254a6d368b03a672c0830779b7753f9284a0f0
7
+ data.tar.gz: caa62abc7dab0b7abe669b3735a4381e7ee1af3b705983b386059c4a0938a9df6a26f274f85169dbdf55a76bb4a06383e6930e22464035ef29fb6492af36bd2d
data/CHANGELOG.md CHANGED
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [1.12.0] - 2022-05-04
8
+
9
+ * SSR!
10
+
7
11
  ## [1.11.1] - 2021-06-27
8
12
 
9
13
  * Fixed thread safety in the middleware. Thanks @caifara!
@@ -0,0 +1,11 @@
1
+ <script>
2
+ export let name;
3
+ </script>
4
+
5
+ <style>
6
+ h1 { font-family: sans-serif; text-align: center; }
7
+ </style>
8
+
9
+ <h1>
10
+ Hello {name}!
11
+ </h1>
@@ -0,0 +1,19 @@
1
+ import axios from 'axios'
2
+
3
+ import { createInertiaApp } from '@inertiajs/inertia-svelte'
4
+ import { InertiaProgress } from '@inertiajs/progress'
5
+
6
+ document.addEventListener('DOMContentLoaded', () => {
7
+ const csrfToken = document.querySelector('meta[name=csrf-token]').content
8
+ axios.defaults.headers.common['X-CSRF-Token'] = csrfToken
9
+
10
+ InertiaProgress.init()
11
+
12
+ createInertiaApp({
13
+ id: 'app',
14
+ resolve: name => import(`../Pages/${name}.svelte`),
15
+ setup({ el, App, props }) {
16
+ new App({ target: el, props })
17
+ },
18
+ })
19
+ })
@@ -6,6 +6,7 @@ module InertiaRails
6
6
  FRONT_END_INSTALLERS = [
7
7
  'react',
8
8
  'vue',
9
+ 'svelte',
9
10
  ]
10
11
 
11
12
  def install
@@ -70,5 +71,14 @@ module InertiaRails
70
71
  template "vue/inertia.js", Rails.root.join("app/javascript/packs/inertia.js").to_s
71
72
  say "done!", :green
72
73
  end
74
+
75
+ def install_svelte!
76
+ say "Creating a Svelte page component...", :blue
77
+ run 'yarn add @inertiajs/inertia-svelte'
78
+ template "svelte/InertiaExample.svelte", Rails.root.join("app/javascript/Pages/InertiaExample.svelte").to_s
79
+ say "Copying inertia.js into webpacker's packs folder...", :blue
80
+ template "svelte/inertia.js", Rails.root.join("app/javascript/packs/inertia.js").to_s
81
+ say "done!", :green
82
+ end
73
83
  end
74
84
  end
@@ -1,4 +1,5 @@
1
1
  require_relative "inertia_rails"
2
+ require_relative "helper"
2
3
 
3
4
  module InertiaRails
4
5
  module Controller
@@ -9,6 +10,7 @@ module InertiaRails
9
10
  # :inertia_errors are deleted from the session by the middleware
10
11
  InertiaRails.share(errors: session[:inertia_errors]) if session[:inertia_errors].present?
11
12
  end
13
+ helper ::InertiaRails::Helper
12
14
  end
13
15
 
14
16
  module ClassMethods
@@ -0,0 +1,7 @@
1
+ require_relative 'inertia_rails'
2
+
3
+ module InertiaRails::Helper
4
+ def inertia_headers
5
+ ::InertiaRails.html_headers.join.html_safe
6
+ end
7
+ end
@@ -5,6 +5,7 @@ require 'inertia_rails/lazy'
5
5
  module InertiaRails
6
6
  thread_mattr_accessor :threadsafe_shared_plain_data
7
7
  thread_mattr_accessor :threadsafe_shared_blocks
8
+ thread_mattr_accessor :threadsafe_html_headers
8
9
 
9
10
  def self.configure
10
11
  yield(Configuration)
@@ -23,6 +24,18 @@ module InertiaRails
23
24
  Configuration.layout
24
25
  end
25
26
 
27
+ def self.ssr_enabled?
28
+ Configuration.ssr_enabled
29
+ end
30
+
31
+ def self.ssr_url
32
+ Configuration.ssr_url
33
+ end
34
+
35
+ def self.html_headers
36
+ self.threadsafe_html_headers || []
37
+ end
38
+
26
39
  # "Setters"
27
40
  def self.share(**args)
28
41
  self.shared_plain_data = self.shared_plain_data.merge(args)
@@ -32,9 +45,14 @@ module InertiaRails
32
45
  self.shared_blocks = self.shared_blocks + [block]
33
46
  end
34
47
 
48
+ def self.html_headers=(headers)
49
+ self.threadsafe_html_headers = headers
50
+ end
51
+
35
52
  def self.reset!
36
53
  self.shared_plain_data = {}
37
54
  self.shared_blocks = []
55
+ self.html_headers = []
38
56
  end
39
57
 
40
58
  def self.lazy(value = nil, &block)
@@ -46,6 +64,8 @@ module InertiaRails
46
64
  module Configuration
47
65
  mattr_accessor(:layout) { 'application' }
48
66
  mattr_accessor(:version) { nil }
67
+ mattr_accessor(:ssr_enabled) { false }
68
+ mattr_accessor(:ssr_url) { 'http://localhost:13714' }
49
69
 
50
70
  def self.evaluated_version
51
71
  self.version.respond_to?(:call) ? self.version.call : self.version
@@ -1,3 +1,5 @@
1
+ require 'net/http'
2
+ require 'json'
1
3
  require_relative "inertia_rails"
2
4
 
3
5
  module InertiaRails
@@ -15,6 +17,8 @@ module InertiaRails
15
17
  end
16
18
 
17
19
  def render
20
+ return render_ssr if ::InertiaRails.ssr_enabled?
21
+
18
22
  if @request.headers['X-Inertia']
19
23
  @response.set_header('Vary', 'Accept')
20
24
  @response.set_header('X-Inertia', 'true')
@@ -26,6 +30,14 @@ module InertiaRails
26
30
 
27
31
  private
28
32
 
33
+ def render_ssr
34
+ uri = URI("#{::InertiaRails.ssr_url}/render")
35
+ res = JSON.parse(Net::HTTP.post(uri, page.to_json, 'Content-Type' => 'application/json').body)
36
+
37
+ ::InertiaRails.html_headers = res['head']
38
+ @render_method.call html: res['body'].html_safe, layout: ::InertiaRails.layout, locals: (view_data).merge({page: page})
39
+ end
40
+
29
41
  def props
30
42
  _props = ::InertiaRails.shared_data(@controller).merge(@props).select do |key, prop|
31
43
  if rendering_partial_component?
@@ -1,3 +1,3 @@
1
1
  module InertiaRails
2
- VERSION = "1.11.1"
2
+ VERSION = "1.12.0"
3
3
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inertia_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.1
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Knoles
8
8
  - Brandon Shar
9
9
  - Eugene Granovsky
10
- autorequire:
10
+ autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2021-06-27 00:00:00.000000000 Z
13
+ date: 2022-05-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -124,7 +124,7 @@ dependencies:
124
124
  - - ">="
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
- description:
127
+ description:
128
128
  email:
129
129
  - brain@bellawatt.com
130
130
  - brandon@bellawatt.com
@@ -156,12 +156,15 @@ files:
156
156
  - lib/generators/inertia_rails/install/controller.rb
157
157
  - lib/generators/inertia_rails/install/react/InertiaExample.jsx
158
158
  - lib/generators/inertia_rails/install/react/inertia.jsx
159
+ - lib/generators/inertia_rails/install/svelte/InertiaExample.svelte
160
+ - lib/generators/inertia_rails/install/svelte/inertia.js
159
161
  - lib/generators/inertia_rails/install/vue/InertiaExample.vue
160
162
  - lib/generators/inertia_rails/install/vue/inertia.js
161
163
  - lib/generators/inertia_rails/install_generator.rb
162
164
  - lib/inertia_rails.rb
163
165
  - lib/inertia_rails/controller.rb
164
166
  - lib/inertia_rails/engine.rb
167
+ - lib/inertia_rails/helper.rb
165
168
  - lib/inertia_rails/inertia_rails.rb
166
169
  - lib/inertia_rails/lazy.rb
167
170
  - lib/inertia_rails/middleware.rb
@@ -182,7 +185,7 @@ metadata:
182
185
  homepage_uri: https://github.com/inertiajs/inertia-rails
183
186
  source_code_uri: https://github.com/inertiajs/inertia-rails
184
187
  changelog_uri: https://github.com/inertiajs/inertia-rails/CHANGELOG.md
185
- post_install_message:
188
+ post_install_message:
186
189
  rdoc_options: []
187
190
  require_paths:
188
191
  - lib
@@ -197,8 +200,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
200
  - !ruby/object:Gem::Version
198
201
  version: '0'
199
202
  requirements: []
200
- rubygems_version: 3.1.4
201
- signing_key:
203
+ rubygems_version: 3.3.3
204
+ signing_key:
202
205
  specification_version: 4
203
206
  summary: Inertia adapter for Rails
204
207
  test_files: []