inertia_rails 1.2.1 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/push.yml +11 -5
- data/CHANGELOG.md +28 -0
- data/README.md +1 -1
- data/inertia_rails.gemspec +5 -4
- data/lib/inertia_rails.rb +4 -0
- data/lib/inertia_rails/controller.rb +1 -1
- data/lib/inertia_rails/inertia_rails.rb +24 -4
- data/lib/inertia_rails/middleware.rb +1 -1
- data/lib/inertia_rails/rspec.rb +1 -1
- data/lib/inertia_rails/version.rb +1 -1
- data/lib/patches/better_errors.rb +17 -0
- data/lib/patches/debug_exceptions.rb +17 -0
- data/lib/patches/debug_exceptions/patch-5-0.rb +23 -0
- data/lib/patches/debug_exceptions/patch-5-1.rb +26 -0
- data/lib/patches/request.rb +9 -0
- metadata +28 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cd358fa9c397d7899a6d5856840c8a2d3f9d375ebfb080cc8255a7c8fdeb9e6
|
4
|
+
data.tar.gz: 7fbc5d37523fda2f27781b6d39765319d8bb5cba876fd0b5a02af7ea7ece80f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d22c0fa1f8ce6f8f069e9dc72705f46f9a4ea7cf02540967aed17dbd8f548e11e096ed85c8f0cd3dd1b0ff28071c18c1687f22b8ec7cc847be355fbbe588930b
|
7
|
+
data.tar.gz: a7bb964c860efa67cd9c3647a38eb981eba239facea5578c6250b3c611ccb727c1691baeefd7357392f81300166d2a475cbda21cf2fa955238ede06ee1bdaa06
|
data/.github/workflows/push.yml
CHANGED
@@ -1,21 +1,27 @@
|
|
1
1
|
name: Testing
|
2
2
|
|
3
|
-
on: [push]
|
3
|
+
on: [push, pull_request]
|
4
4
|
|
5
5
|
jobs:
|
6
6
|
test:
|
7
|
+
strategy:
|
8
|
+
fail-fast: false
|
9
|
+
matrix:
|
10
|
+
ruby: [2.6, 2.7]
|
11
|
+
|
7
12
|
runs-on: ubuntu-latest
|
13
|
+
name: Test against Ruby ${{ matrix.ruby }}
|
8
14
|
|
9
15
|
steps:
|
10
|
-
- uses: actions/checkout@
|
16
|
+
- uses: actions/checkout@v2
|
11
17
|
|
12
18
|
- name: Setup System
|
13
19
|
run: sudo apt-get install libsqlite3-dev
|
14
20
|
|
15
|
-
- name: Set up Ruby
|
16
|
-
uses:
|
21
|
+
- name: Set up Ruby
|
22
|
+
uses: ruby/setup-ruby@v1
|
17
23
|
with:
|
18
|
-
ruby-version:
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
19
25
|
|
20
26
|
- name: Install gems
|
21
27
|
run: |
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,34 @@ 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.4.1] - 2020-08-06
|
8
|
+
|
9
|
+
* Fixed a bug involving threadsafe versions and layouts
|
10
|
+
|
11
|
+
## [1.4.0] - 2020-07-09
|
12
|
+
|
13
|
+
* Fixed Ruby 2.7 deprecation warnings
|
14
|
+
* Added `inertia_partial?` method
|
15
|
+
* Fixed homepage in the gemspec
|
16
|
+
* Make the InertiaRails module data threadsafe
|
17
|
+
|
18
|
+
## [1.3.1] - 2020-02-20
|
19
|
+
|
20
|
+
* Fix a typo in the README (inertia only has 1 t!)
|
21
|
+
|
22
|
+
## [1.3.0] - 2020-01-28
|
23
|
+
|
24
|
+
### Added
|
25
|
+
|
26
|
+
* Added request.inertia? method
|
27
|
+
|
28
|
+
## [1.2.2] - 2020-01-21
|
29
|
+
|
30
|
+
### Fixed
|
31
|
+
|
32
|
+
* Added patches to allow Rails errors to show properly in the inertia modal
|
33
|
+
* Fixed a middleware issue caused by a breaking change in Rack v2.1.*
|
34
|
+
|
7
35
|
## [1.2.1] - 2019-12-6
|
8
36
|
|
9
37
|
### Fixed
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@ Visit [inertiajs.com](https://inertiajs.com/) to learn more.
|
|
6
6
|
|
7
7
|
The initial version of the gem was named `inertia`; however, that name was not available on Rubygems.
|
8
8
|
|
9
|
-
The 1.0.0 version release on Rubygems is `
|
9
|
+
The 1.0.0 version release on Rubygems is `inertia_rails`.
|
10
10
|
|
11
11
|
The changes required are:
|
12
12
|
|
data/inertia_rails.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ["brain@bellawatt.com", "brandon@bellawatt.com", "eugene@bellawatt.com"]
|
10
10
|
|
11
11
|
spec.summary = %q{Inertia adapter for Rails}
|
12
|
-
spec.homepage = "https://github.com/inertiajs/inertia-rails
|
12
|
+
spec.homepage = "https://github.com/inertiajs/inertia-rails"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
15
15
|
spec.metadata["homepage_uri"] = spec.homepage
|
@@ -25,10 +25,11 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ["lib"]
|
27
27
|
|
28
|
+
spec.add_runtime_dependency "rails", '>= 5'
|
29
|
+
|
28
30
|
spec.add_development_dependency "bundler", "~> 2.0"
|
29
|
-
spec.add_development_dependency "rake", "~>
|
30
|
-
spec.add_development_dependency "rspec-rails", "~>
|
31
|
-
spec.add_development_dependency "rails"
|
31
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
32
|
+
spec.add_development_dependency "rspec-rails", "~> 4.0"
|
32
33
|
spec.add_development_dependency "rails-controller-testing"
|
33
34
|
spec.add_development_dependency "sqlite3"
|
34
35
|
end
|
data/lib/inertia_rails.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require 'inertia_rails/renderer'
|
2
2
|
require 'inertia_rails/engine'
|
3
3
|
|
4
|
+
require 'patches/debug_exceptions'
|
5
|
+
require 'patches/better_errors'
|
6
|
+
require 'patches/request'
|
7
|
+
|
4
8
|
ActionController::Renderers.add :inertia do |component, options|
|
5
9
|
InertiaRails::Renderer.new(
|
6
10
|
component,
|
@@ -1,6 +1,9 @@
|
|
1
|
+
# Needed for `thread_mattr_accessor`
|
2
|
+
require 'active_support/core_ext/module/attribute_accessors_per_thread'
|
3
|
+
|
1
4
|
module InertiaRails
|
2
|
-
|
3
|
-
|
5
|
+
thread_mattr_accessor :threadsafe_shared_plain_data
|
6
|
+
thread_mattr_accessor :threadsafe_shared_blocks
|
4
7
|
|
5
8
|
def self.configure
|
6
9
|
yield(Configuration)
|
@@ -21,11 +24,11 @@ module InertiaRails
|
|
21
24
|
|
22
25
|
# "Setters"
|
23
26
|
def self.share(**args)
|
24
|
-
shared_plain_data.merge
|
27
|
+
self.shared_plain_data = self.shared_plain_data.merge(args)
|
25
28
|
end
|
26
29
|
|
27
30
|
def self.share_block(block)
|
28
|
-
shared_blocks.
|
31
|
+
self.shared_blocks = self.shared_blocks + [block]
|
29
32
|
end
|
30
33
|
|
31
34
|
def self.reset!
|
@@ -44,6 +47,23 @@ module InertiaRails
|
|
44
47
|
end
|
45
48
|
end
|
46
49
|
|
50
|
+
# Getters and setters to provide default values for the threadsafe attributes
|
51
|
+
def self.shared_plain_data
|
52
|
+
self.threadsafe_shared_plain_data || {}
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.shared_plain_data=(val)
|
56
|
+
self.threadsafe_shared_plain_data = val
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.shared_blocks
|
60
|
+
self.threadsafe_shared_blocks || []
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.shared_blocks=(val)
|
64
|
+
self.threadsafe_shared_blocks = val
|
65
|
+
end
|
66
|
+
|
47
67
|
def self.evaluated_blocks(controller, blocks)
|
48
68
|
blocks.flat_map { |block| controller.instance_exec(&block) }.reduce(&:merge) || {}
|
49
69
|
end
|
@@ -40,7 +40,7 @@ module InertiaRails
|
|
40
40
|
|
41
41
|
def force_refresh(request)
|
42
42
|
request.flash.keep
|
43
|
-
Rack::Response.new('', 409, {'X-Inertia-Location' => request.original_url})
|
43
|
+
Rack::Response.new('', 409, {'X-Inertia-Location' => request.original_url}).finish
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
data/lib/inertia_rails/rspec.rb
CHANGED
@@ -61,7 +61,7 @@ RSpec.configure do |config|
|
|
61
61
|
config.before(:each, inertia: true) do
|
62
62
|
new_renderer = InertiaRails::Renderer.method(:new)
|
63
63
|
allow(InertiaRails::Renderer).to receive(:new) do |component, controller, request, response, render, named_args|
|
64
|
-
new_renderer.call(component, controller, request, response, inertia_wrap_render(render), named_args)
|
64
|
+
new_renderer.call(component, controller, request, response, inertia_wrap_render(render), **named_args)
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Patch BetterErrors::Middleware to render HTML for Inertia requests
|
2
|
+
#
|
3
|
+
# Original source:
|
4
|
+
# https://github.com/BetterErrors/better_errors/blob/v2.5.1/lib/better_errors/middleware.rb
|
5
|
+
#
|
6
|
+
|
7
|
+
if defined?(BetterErrors)
|
8
|
+
BetterErrors::Middleware.class_eval do
|
9
|
+
prepend(InertiaBetterErrors = Module.new do
|
10
|
+
def text?(env)
|
11
|
+
return false if env["HTTP_X_INERTIA"]
|
12
|
+
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests
|
2
|
+
#
|
3
|
+
# Rails has introduced text rendering for XHR requests with Rails 4.1 and
|
4
|
+
# changed the implementation in 4.2, 5.0 and 5.1 (unchanged since then).
|
5
|
+
#
|
6
|
+
# The original source needs to be patched, so that Inertia requests are
|
7
|
+
# NOT responded with plain text, but with HTML.
|
8
|
+
|
9
|
+
if defined?(ActionDispatch::DebugExceptions)
|
10
|
+
if ActionPack.version.to_s >= '5.1'
|
11
|
+
require 'patches/debug_exceptions/patch-5-1'
|
12
|
+
elsif ActionPack.version.to_s >= '5.0'
|
13
|
+
require 'patches/debug_exceptions/patch-5-0'
|
14
|
+
else
|
15
|
+
# This gem supports Rails 5 or later
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests
|
2
|
+
#
|
3
|
+
# Original source:
|
4
|
+
# https://github.com/rails/rails/blob/5-0-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
|
5
|
+
#
|
6
|
+
|
7
|
+
ActionDispatch::DebugExceptions.class_eval do
|
8
|
+
prepend(InertiaDebugExceptions = Module.new do
|
9
|
+
def render_for_default_application(request, wrapper)
|
10
|
+
template = create_template(request, wrapper)
|
11
|
+
file = "rescues/#{wrapper.rescue_template}"
|
12
|
+
|
13
|
+
if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only
|
14
|
+
body = template.render(template: file, layout: false, formats: [:text])
|
15
|
+
format = "text/plain"
|
16
|
+
else
|
17
|
+
body = template.render(template: file, layout: 'rescues/layout')
|
18
|
+
format = "text/html"
|
19
|
+
end
|
20
|
+
render(wrapper.status_code, body, format)
|
21
|
+
end
|
22
|
+
end)
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests
|
2
|
+
#
|
3
|
+
# Original source (unchanged since Rails 5.1):
|
4
|
+
# https://github.com/rails/rails/blob/5-1-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
|
5
|
+
# https://github.com/rails/rails/blob/5-2-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
|
6
|
+
# https://github.com/rails/rails/blob/6-0-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
|
7
|
+
#
|
8
|
+
|
9
|
+
ActionDispatch::DebugExceptions.class_eval do
|
10
|
+
prepend(InertiaDebugExceptions = Module.new do
|
11
|
+
def render_for_browser_request(request, wrapper)
|
12
|
+
template = create_template(request, wrapper)
|
13
|
+
file = "rescues/#{wrapper.rescue_template}"
|
14
|
+
|
15
|
+
if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only
|
16
|
+
body = template.render(template: file, layout: false, formats: [:text])
|
17
|
+
format = "text/plain"
|
18
|
+
else
|
19
|
+
body = template.render(template: file, layout: "rescues/layout")
|
20
|
+
format = "text/html"
|
21
|
+
end
|
22
|
+
|
23
|
+
render(wrapper.status_code, body, format)
|
24
|
+
end
|
25
|
+
end)
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inertia_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Knoles
|
@@ -10,64 +10,64 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-08-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: rails
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
18
18
|
requirements:
|
19
|
-
- - "
|
19
|
+
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
22
|
-
type: :
|
21
|
+
version: '5'
|
22
|
+
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
|
-
- - "
|
26
|
+
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: '
|
28
|
+
version: '5'
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
|
-
name:
|
30
|
+
name: bundler
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
32
32
|
requirements:
|
33
33
|
- - "~>"
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: '
|
35
|
+
version: '2.0'
|
36
36
|
type: :development
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - "~>"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
42
|
+
version: '2.0'
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
|
-
name:
|
44
|
+
name: rake
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
49
|
+
version: '13.0'
|
50
50
|
type: :development
|
51
51
|
prerelease: false
|
52
52
|
version_requirements: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: '
|
56
|
+
version: '13.0'
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
|
-
name: rails
|
58
|
+
name: rspec-rails
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
|
-
- - "
|
61
|
+
- - "~>"
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: '0'
|
63
|
+
version: '4.0'
|
64
64
|
type: :development
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
|
-
- - "
|
68
|
+
- - "~>"
|
69
69
|
- !ruby/object:Gem::Version
|
70
|
-
version: '0'
|
70
|
+
version: '4.0'
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: rails-controller-testing
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,13 +126,18 @@ files:
|
|
126
126
|
- lib/inertia_rails/renderer.rb
|
127
127
|
- lib/inertia_rails/rspec.rb
|
128
128
|
- lib/inertia_rails/version.rb
|
129
|
-
|
129
|
+
- lib/patches/better_errors.rb
|
130
|
+
- lib/patches/debug_exceptions.rb
|
131
|
+
- lib/patches/debug_exceptions/patch-5-0.rb
|
132
|
+
- lib/patches/debug_exceptions/patch-5-1.rb
|
133
|
+
- lib/patches/request.rb
|
134
|
+
homepage: https://github.com/inertiajs/inertia-rails
|
130
135
|
licenses:
|
131
136
|
- MIT
|
132
137
|
metadata:
|
133
|
-
homepage_uri: https://github.com/inertiajs/inertia-rails
|
134
|
-
source_code_uri: https://github.com/inertiajs/inertia-rails
|
135
|
-
changelog_uri: https://github.com/inertiajs/inertia-rails
|
138
|
+
homepage_uri: https://github.com/inertiajs/inertia-rails
|
139
|
+
source_code_uri: https://github.com/inertiajs/inertia-rails
|
140
|
+
changelog_uri: https://github.com/inertiajs/inertia-rails/CHANGELOG.md
|
136
141
|
post_install_message:
|
137
142
|
rdoc_options: []
|
138
143
|
require_paths:
|