inertia_rails 1.3.0 → 1.6.0
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/.github/workflows/push.yml +15 -5
- data/.gitignore +3 -0
- data/Appraisals +15 -0
- data/CHANGELOG.md +26 -0
- data/README.md +1 -1
- data/gemfiles/rails_5.0.gemfile +7 -0
- data/gemfiles/rails_5.1.gemfile +7 -0
- data/gemfiles/rails_5.2.gemfile +7 -0
- data/gemfiles/rails_6.0.gemfile +7 -0
- data/inertia_rails.gemspec +6 -4
- data/lib/inertia_rails/controller.rb +21 -1
- data/lib/inertia_rails/inertia_rails.rb +24 -4
- data/lib/inertia_rails/middleware.rb +61 -24
- data/lib/inertia_rails/renderer.rb +1 -1
- data/lib/inertia_rails/rspec.rb +1 -1
- data/lib/inertia_rails/version.rb +1 -1
- data/lib/patches/debug_exceptions.rb +1 -7
- data/lib/patches/request.rb +4 -0
- metadata +33 -16
- data/lib/patches/debug_exceptions/patch-4-1.rb +0 -41
- data/lib/patches/debug_exceptions/patch-4-2.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b889c5a06cf6c9310b1d64c1e19a5e979aea7ba874c3014867a462386dd28937
|
4
|
+
data.tar.gz: c5e1bf21eb3ff8dc1e14ebadedf43bb82f8b1af6aa46680610ad4b0054d90b3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65a66ab26b16808a9b88467a6b579074f68ba68877c055b8d2e333422454041f3461ff4ab0a947f2a52572edd8bf1c88d62d6d32ec7a1c8bd6ca776158f756c0
|
7
|
+
data.tar.gz: 724961702c0bd5ffb53e427d8791f1064dcc080c4cbc253297f30207c0017065b0f2c12b4822c5969401582972810c8960fbc494884bebb32fe1df907e6a7d79
|
data/.github/workflows/push.yml
CHANGED
@@ -1,24 +1,34 @@
|
|
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
|
+
rails: ['5.0', '5.1', '5.2', '6.0']
|
12
|
+
|
7
13
|
runs-on: ubuntu-latest
|
14
|
+
name: Test against Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}
|
8
15
|
|
9
16
|
steps:
|
10
|
-
- uses: actions/checkout@
|
17
|
+
- uses: actions/checkout@v2
|
11
18
|
|
12
19
|
- name: Setup System
|
13
20
|
run: sudo apt-get install libsqlite3-dev
|
14
21
|
|
15
|
-
- name: Set up Ruby
|
16
|
-
uses:
|
22
|
+
- name: Set up Ruby
|
23
|
+
uses: ruby/setup-ruby@v1
|
17
24
|
with:
|
18
|
-
ruby-version:
|
25
|
+
ruby-version: ${{ matrix.ruby }}
|
19
26
|
|
20
27
|
- name: Install gems
|
28
|
+
env:
|
29
|
+
MATRIX_RAILS_VERSION: ${{ matrix.rails }}
|
21
30
|
run: |
|
31
|
+
export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/rails_${MATRIX_RAILS_VERSION}.gemfile"
|
22
32
|
gem install bundler
|
23
33
|
bundle install --jobs 4 --retry 3
|
24
34
|
|
data/.gitignore
CHANGED
data/Appraisals
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
appraise "rails-6.0" do
|
2
|
+
gem "rails", "~> 6.0.3", '>= 6.0.3.2'
|
3
|
+
end
|
4
|
+
|
5
|
+
appraise "rails-5.2" do
|
6
|
+
gem "rails", "~> 5.2.4", '>= 5.2.4.3'
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise "rails-5.1" do
|
10
|
+
gem "rails", "~> 5.1.7"
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise "rails-5.0" do
|
14
|
+
gem "rails", "~> 5.0.7", '>= 5.0.7.2'
|
15
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,32 @@ 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.6.0] - 2020-11-20
|
8
|
+
|
9
|
+
* Built in error sharing across redirects! adding `{ inertia: { errors: 'errors go here' } }` as an option in `redirect_to` will automatically feed an `errors` prop to whatever is rendered after the redirect.
|
10
|
+
* Set content type to json for Inertia responses
|
11
|
+
* Return the original response status with Inertia responses
|
12
|
+
|
13
|
+
## [1.5.0] - 2020-10-07
|
14
|
+
|
15
|
+
* Test against multiple Rails versions in Github Actions
|
16
|
+
* Add the `inertia_location` controller method that forces a full page refresh
|
17
|
+
|
18
|
+
## [1.4.1] - 2020-08-06
|
19
|
+
|
20
|
+
* Fixed a bug involving threadsafe versions and layouts
|
21
|
+
|
22
|
+
## [1.4.0] - 2020-07-09
|
23
|
+
|
24
|
+
* Fixed Ruby 2.7 deprecation warnings
|
25
|
+
* Added `inertia_partial?` method
|
26
|
+
* Fixed homepage in the gemspec
|
27
|
+
* Make the InertiaRails module data threadsafe
|
28
|
+
|
29
|
+
## [1.3.1] - 2020-02-20
|
30
|
+
|
31
|
+
* Fix a typo in the README (inertia only has 1 t!)
|
32
|
+
|
7
33
|
## [1.3.0] - 2020-01-28
|
8
34
|
|
9
35
|
### Added
|
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,12 @@ 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"
|
35
|
+
spec.add_development_dependency "appraisal"
|
34
36
|
end
|
@@ -4,13 +4,33 @@ module InertiaRails
|
|
4
4
|
module Controller
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
+
included do
|
8
|
+
before_action do
|
9
|
+
# :inertia_errors are deleted from the session by the middleware
|
10
|
+
InertiaRails.share(errors: session[:inertia_errors]) if session[:inertia_errors].present?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
7
14
|
module ClassMethods
|
8
15
|
def inertia_share(**args, &block)
|
9
16
|
before_action do
|
10
|
-
InertiaRails.share(args) if args
|
17
|
+
InertiaRails.share(**args) if args
|
11
18
|
InertiaRails.share_block(block) if block
|
12
19
|
end
|
13
20
|
end
|
14
21
|
end
|
22
|
+
|
23
|
+
def inertia_location(url)
|
24
|
+
headers['X-Inertia-Location'] = url
|
25
|
+
head :conflict
|
26
|
+
end
|
27
|
+
|
28
|
+
def redirect_to(options = {}, response_options = {})
|
29
|
+
if (inertia_errors = response_options.fetch(:inertia, {}).fetch(:errors, nil))
|
30
|
+
session[:inertia_errors] = inertia_errors
|
31
|
+
end
|
32
|
+
|
33
|
+
super(options, response_options)
|
34
|
+
end
|
15
35
|
end
|
16
36
|
end
|
@@ -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
|
@@ -3,41 +3,78 @@ module InertiaRails
|
|
3
3
|
def initialize(app)
|
4
4
|
@app = app
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
def call(env)
|
8
|
+
@env = env
|
9
|
+
|
8
10
|
status, headers, body = @app.call(env)
|
9
11
|
request = ActionDispatch::Request.new(env)
|
10
12
|
|
11
13
|
::InertiaRails.reset!
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
[status, headers, body]
|
23
|
-
end
|
24
|
-
|
14
|
+
|
15
|
+
# Inertia errors are added to the session via redirect_to
|
16
|
+
request.session.delete(:inertia_errors) unless keep_inertia_errors?(status)
|
17
|
+
|
18
|
+
status = 303 if inertia_non_post_redirect?(status)
|
19
|
+
|
20
|
+
return stale_inertia_get? ? force_refresh(request) : [status, headers, body]
|
21
|
+
end
|
22
|
+
|
25
23
|
private
|
26
|
-
|
27
|
-
def
|
24
|
+
|
25
|
+
def keep_inertia_errors?(status)
|
26
|
+
redirect_status?(status) || stale_inertia_request?
|
27
|
+
end
|
28
|
+
|
29
|
+
def stale_inertia_request?
|
30
|
+
inertia_request? && version_stale?
|
31
|
+
end
|
32
|
+
|
33
|
+
def redirect_status?(status)
|
28
34
|
[301, 302].include? status
|
29
35
|
end
|
30
|
-
|
31
|
-
def
|
36
|
+
|
37
|
+
def non_get_redirectable_method?
|
32
38
|
['PUT', 'PATCH', 'DELETE'].include? request_method
|
33
39
|
end
|
34
|
-
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
40
|
+
|
41
|
+
def inertia_non_post_redirect?(status)
|
42
|
+
inertia_request? && redirect_status?(status) && non_get_redirectable_method?
|
43
|
+
end
|
44
|
+
|
45
|
+
def stale_inertia_get?
|
46
|
+
get? && stale_inertia_request?
|
39
47
|
end
|
40
|
-
|
48
|
+
|
49
|
+
def get?
|
50
|
+
request_method == 'GET'
|
51
|
+
end
|
52
|
+
|
53
|
+
def request_method
|
54
|
+
@env['REQUEST_METHOD']
|
55
|
+
end
|
56
|
+
|
57
|
+
def inertia_version
|
58
|
+
@env['HTTP_X_INERTIA_VERSION']
|
59
|
+
end
|
60
|
+
|
61
|
+
def inertia_request?
|
62
|
+
@env['HTTP_X_INERTIA'].present?
|
63
|
+
end
|
64
|
+
|
65
|
+
def version_stale?
|
66
|
+
sent_version != saved_version
|
67
|
+
end
|
68
|
+
|
69
|
+
def sent_version
|
70
|
+
return nil if inertia_version.nil?
|
71
|
+
InertiaRails.version.is_a?(Numeric) ? inertia_version.to_f : inertia_version
|
72
|
+
end
|
73
|
+
|
74
|
+
def saved_version
|
75
|
+
InertiaRails.version.is_a?(Numeric) ? InertiaRails.version.to_f : InertiaRails.version
|
76
|
+
end
|
77
|
+
|
41
78
|
def force_refresh(request)
|
42
79
|
request.flash.keep
|
43
80
|
Rack::Response.new('', 409, {'X-Inertia-Location' => request.original_url}).finish
|
@@ -18,7 +18,7 @@ module InertiaRails
|
|
18
18
|
if @request.headers['X-Inertia']
|
19
19
|
@response.set_header('Vary', 'Accept')
|
20
20
|
@response.set_header('X-Inertia', 'true')
|
21
|
-
@render_method.call json: page, status:
|
21
|
+
@render_method.call json: page, status: @response.status, content_type: Mime[:json]
|
22
22
|
else
|
23
23
|
@render_method.call template: 'inertia', layout: ::InertiaRails.layout, locals: (view_data).merge({page: page})
|
24
24
|
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
|
@@ -11,13 +11,7 @@ if defined?(ActionDispatch::DebugExceptions)
|
|
11
11
|
require 'patches/debug_exceptions/patch-5-1'
|
12
12
|
elsif ActionPack.version.to_s >= '5.0'
|
13
13
|
require 'patches/debug_exceptions/patch-5-0'
|
14
|
-
elsif ActionPack.version.to_s >= '4.2'
|
15
|
-
require 'patches/debug_exceptions/patch-4-2'
|
16
|
-
elsif ActionPack.version.to_s >= '4.1'
|
17
|
-
require 'patches/debug_exceptions/patch-4-1'
|
18
14
|
else
|
19
|
-
#
|
20
|
-
# XHR requests was introduced with Rails 4.1:
|
21
|
-
# https://github.com/rails/rails/pull/11960
|
15
|
+
# This gem supports Rails 5 or later
|
22
16
|
end
|
23
17
|
end
|
data/lib/patches/request.rb
CHANGED
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.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Knoles
|
@@ -10,8 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-
|
13
|
+
date: 2020-11-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '5'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '5'
|
15
29
|
- !ruby/object:Gem::Dependency
|
16
30
|
name: bundler
|
17
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -32,30 +46,30 @@ dependencies:
|
|
32
46
|
requirements:
|
33
47
|
- - "~>"
|
34
48
|
- !ruby/object:Gem::Version
|
35
|
-
version: '
|
49
|
+
version: '13.0'
|
36
50
|
type: :development
|
37
51
|
prerelease: false
|
38
52
|
version_requirements: !ruby/object:Gem::Requirement
|
39
53
|
requirements:
|
40
54
|
- - "~>"
|
41
55
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
56
|
+
version: '13.0'
|
43
57
|
- !ruby/object:Gem::Dependency
|
44
58
|
name: rspec-rails
|
45
59
|
requirement: !ruby/object:Gem::Requirement
|
46
60
|
requirements:
|
47
61
|
- - "~>"
|
48
62
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
63
|
+
version: '4.0'
|
50
64
|
type: :development
|
51
65
|
prerelease: false
|
52
66
|
version_requirements: !ruby/object:Gem::Requirement
|
53
67
|
requirements:
|
54
68
|
- - "~>"
|
55
69
|
- !ruby/object:Gem::Version
|
56
|
-
version: '
|
70
|
+
version: '4.0'
|
57
71
|
- !ruby/object:Gem::Dependency
|
58
|
-
name: rails
|
72
|
+
name: rails-controller-testing
|
59
73
|
requirement: !ruby/object:Gem::Requirement
|
60
74
|
requirements:
|
61
75
|
- - ">="
|
@@ -69,7 +83,7 @@ dependencies:
|
|
69
83
|
- !ruby/object:Gem::Version
|
70
84
|
version: '0'
|
71
85
|
- !ruby/object:Gem::Dependency
|
72
|
-
name:
|
86
|
+
name: sqlite3
|
73
87
|
requirement: !ruby/object:Gem::Requirement
|
74
88
|
requirements:
|
75
89
|
- - ">="
|
@@ -83,7 +97,7 @@ dependencies:
|
|
83
97
|
- !ruby/object:Gem::Version
|
84
98
|
version: '0'
|
85
99
|
- !ruby/object:Gem::Dependency
|
86
|
-
name:
|
100
|
+
name: appraisal
|
87
101
|
requirement: !ruby/object:Gem::Requirement
|
88
102
|
requirements:
|
89
103
|
- - ">="
|
@@ -108,6 +122,7 @@ files:
|
|
108
122
|
- ".github/workflows/push.yml"
|
109
123
|
- ".gitignore"
|
110
124
|
- ".rspec"
|
125
|
+
- Appraisals
|
111
126
|
- CHANGELOG.md
|
112
127
|
- CODE_OF_CONDUCT.md
|
113
128
|
- Gemfile
|
@@ -117,6 +132,10 @@ files:
|
|
117
132
|
- app/views/inertia.html.erb
|
118
133
|
- bin/console
|
119
134
|
- bin/setup
|
135
|
+
- gemfiles/rails_5.0.gemfile
|
136
|
+
- gemfiles/rails_5.1.gemfile
|
137
|
+
- gemfiles/rails_5.2.gemfile
|
138
|
+
- gemfiles/rails_6.0.gemfile
|
120
139
|
- inertia_rails.gemspec
|
121
140
|
- lib/inertia_rails.rb
|
122
141
|
- lib/inertia_rails/controller.rb
|
@@ -128,18 +147,16 @@ files:
|
|
128
147
|
- lib/inertia_rails/version.rb
|
129
148
|
- lib/patches/better_errors.rb
|
130
149
|
- lib/patches/debug_exceptions.rb
|
131
|
-
- lib/patches/debug_exceptions/patch-4-1.rb
|
132
|
-
- lib/patches/debug_exceptions/patch-4-2.rb
|
133
150
|
- lib/patches/debug_exceptions/patch-5-0.rb
|
134
151
|
- lib/patches/debug_exceptions/patch-5-1.rb
|
135
152
|
- lib/patches/request.rb
|
136
|
-
homepage: https://github.com/inertiajs/inertia-rails
|
153
|
+
homepage: https://github.com/inertiajs/inertia-rails
|
137
154
|
licenses:
|
138
155
|
- MIT
|
139
156
|
metadata:
|
140
|
-
homepage_uri: https://github.com/inertiajs/inertia-rails
|
141
|
-
source_code_uri: https://github.com/inertiajs/inertia-rails
|
142
|
-
changelog_uri: https://github.com/inertiajs/inertia-rails
|
157
|
+
homepage_uri: https://github.com/inertiajs/inertia-rails
|
158
|
+
source_code_uri: https://github.com/inertiajs/inertia-rails
|
159
|
+
changelog_uri: https://github.com/inertiajs/inertia-rails/CHANGELOG.md
|
143
160
|
post_install_message:
|
144
161
|
rdoc_options: []
|
145
162
|
require_paths:
|
@@ -155,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
172
|
- !ruby/object:Gem::Version
|
156
173
|
version: '0'
|
157
174
|
requirements: []
|
158
|
-
rubygems_version: 3.
|
175
|
+
rubygems_version: 3.1.4
|
159
176
|
signing_key:
|
160
177
|
specification_version: 4
|
161
178
|
summary: Inertia adapter for Rails
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests
|
2
|
-
#
|
3
|
-
# Original source:
|
4
|
-
# https://github.com/rails/rails/blob/4-1-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_exception(env, exception)
|
10
|
-
wrapper = ExceptionWrapper.new(env, exception)
|
11
|
-
log_error(env, wrapper)
|
12
|
-
|
13
|
-
if env['action_dispatch.show_detailed_exceptions']
|
14
|
-
request = Request.new(env)
|
15
|
-
template = ActionView::Base.new([RESCUES_TEMPLATE_PATH],
|
16
|
-
request: request,
|
17
|
-
exception: wrapper.exception,
|
18
|
-
application_trace: wrapper.application_trace,
|
19
|
-
framework_trace: wrapper.framework_trace,
|
20
|
-
full_trace: wrapper.full_trace,
|
21
|
-
routes_inspector: routes_inspector(exception),
|
22
|
-
source_extract: wrapper.source_extract,
|
23
|
-
line_number: wrapper.line_number,
|
24
|
-
file: wrapper.file
|
25
|
-
)
|
26
|
-
file = "rescues/#{wrapper.rescue_template}"
|
27
|
-
|
28
|
-
if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only
|
29
|
-
body = template.render(template: file, layout: false, formats: [:text])
|
30
|
-
format = "text/plain"
|
31
|
-
else
|
32
|
-
body = template.render(template: file, layout: 'rescues/layout')
|
33
|
-
format = "text/html"
|
34
|
-
end
|
35
|
-
render(wrapper.status_code, body, format)
|
36
|
-
else
|
37
|
-
raise exception
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end)
|
41
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests
|
2
|
-
#
|
3
|
-
# Original source:
|
4
|
-
# https://github.com/rails/rails/blob/4-2-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_exception(env, exception)
|
10
|
-
wrapper = ExceptionWrapper.new(env, exception)
|
11
|
-
log_error(env, wrapper)
|
12
|
-
|
13
|
-
if env['action_dispatch.show_detailed_exceptions']
|
14
|
-
request = Request.new(env)
|
15
|
-
traces = wrapper.traces
|
16
|
-
|
17
|
-
trace_to_show = 'Application Trace'
|
18
|
-
if traces[trace_to_show].empty? && wrapper.rescue_template != 'routing_error'
|
19
|
-
trace_to_show = 'Full Trace'
|
20
|
-
end
|
21
|
-
|
22
|
-
if source_to_show = traces[trace_to_show].first
|
23
|
-
source_to_show_id = source_to_show[:id]
|
24
|
-
end
|
25
|
-
|
26
|
-
template = ActionView::Base.new([RESCUES_TEMPLATE_PATH],
|
27
|
-
request: request,
|
28
|
-
exception: wrapper.exception,
|
29
|
-
traces: traces,
|
30
|
-
show_source_idx: source_to_show_id,
|
31
|
-
trace_to_show: trace_to_show,
|
32
|
-
routes_inspector: routes_inspector(exception),
|
33
|
-
source_extracts: wrapper.source_extracts,
|
34
|
-
line_number: wrapper.line_number,
|
35
|
-
file: wrapper.file
|
36
|
-
)
|
37
|
-
file = "rescues/#{wrapper.rescue_template}"
|
38
|
-
|
39
|
-
if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only
|
40
|
-
body = template.render(template: file, layout: false, formats: [:text])
|
41
|
-
format = "text/plain"
|
42
|
-
else
|
43
|
-
body = template.render(template: file, layout: 'rescues/layout')
|
44
|
-
format = "text/html"
|
45
|
-
end
|
46
|
-
render(wrapper.status_code, body, format)
|
47
|
-
else
|
48
|
-
raise exception
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end)
|
52
|
-
end
|