inertia_rails 1.7.1 → 1.10.0
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 +1 -1
- data/Appraisals +4 -0
- data/CHANGELOG.md +21 -0
- data/app/controllers/inertia_rails/static_controller.rb +7 -0
- data/gemfiles/rails_6.1.gemfile +7 -0
- data/inertia_rails.gemspec +1 -0
- data/lib/generators/inertia_rails/install/controller.rb +7 -0
- data/lib/generators/inertia_rails/install/inertia.jsx +21 -0
- data/lib/generators/inertia_rails/install/react.jsx +9 -0
- data/lib/generators/inertia_rails/install_generator.rb +62 -0
- data/lib/inertia_rails.rb +1 -0
- data/lib/inertia_rails/controller.rb +18 -4
- data/lib/inertia_rails/rspec.rb +7 -1
- data/lib/inertia_rails/version.rb +1 -1
- data/lib/patches/mapper.rb +8 -0
- data/lib/tasks/inertia_rails.rake +16 -0
- metadata +24 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c76eba9ada41f6b781b030f81b43bb87169034594127e106ec4dbee472926e8e
|
4
|
+
data.tar.gz: e9ed9115c9d6a678bdefdeeeafbeb1790c9a28f37521d71c699d5ca40989cd86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d0285ccf5284c9fb4d267d25dfc899d58be5f57b2166fc42251246398483aaf639c8dbec94181a1a5978c020ea2fb796872248dd3de7c14db165b8ab20755cb
|
7
|
+
data.tar.gz: c06d57bec2e2c4fa55b15428055684999af1d65ee226f42263cb945d17ce4f06029bc8365b2a9f52b59db924b251f34944dd96998a7933b64fe18c6e80ae3117
|
data/.github/workflows/push.yml
CHANGED
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,27 @@ 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.10.0] - 2021-03-22
|
8
|
+
|
9
|
+
* Added install generator to quickly add Inertia to existing rails apps via `rails inertia_rails:install:react`
|
10
|
+
|
11
|
+
## [1.9.2] - 2021-02-23
|
12
|
+
|
13
|
+
* Improve method for detecting whether a user used the RSpec helpers without adding `inertia: true` to the spec
|
14
|
+
* Emit a warning when expecting an Inertia response in RSpec and never reaching a `render inertia:` call
|
15
|
+
|
16
|
+
## [1.9.1] - 2021-02-10
|
17
|
+
|
18
|
+
* Define `redirect_to` and `redirect_back` as public methods for compatibility with other code using them
|
19
|
+
|
20
|
+
## [1.9.0] - 2021-01-17
|
21
|
+
|
22
|
+
* Added the same inertia awareness that redirect_to has to redirect_back
|
23
|
+
|
24
|
+
## [1.8.0] - 2020-12-08
|
25
|
+
|
26
|
+
* Add `inertia` route helper feature
|
27
|
+
|
7
28
|
## [1.7.1] - 2020-11-24
|
8
29
|
|
9
30
|
* Fix the definition for InertiaRails::Lazy to avoid an uninitialized constant error when booting an application.
|
data/inertia_rails.gemspec
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
import { App } from '@inertiajs/inertia-react';
|
2
|
+
import React from 'react';
|
3
|
+
import { render } from 'react-dom';
|
4
|
+
import axios from 'axios';
|
5
|
+
import { InertiaProgress } from '@inertiajs/progress';
|
6
|
+
|
7
|
+
document.addEventListener('DOMContentLoaded', () => {
|
8
|
+
InertiaProgress.init();
|
9
|
+
const el = document.getElementById('app')
|
10
|
+
|
11
|
+
const csrfToken = document.querySelector('meta[name=csrf-token]').content;
|
12
|
+
axios.defaults.headers.common['X-CSRF-Token'] = csrfToken;
|
13
|
+
|
14
|
+
render(
|
15
|
+
<App
|
16
|
+
initialPage={JSON.parse(el.dataset.page)}
|
17
|
+
resolveComponent={name => require(`../Pages/${name}`).default}
|
18
|
+
/>,
|
19
|
+
el
|
20
|
+
)
|
21
|
+
});
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module InertiaRails
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('./install', __dir__)
|
4
|
+
class_option :front_end, type: :string, default: 'react'
|
5
|
+
|
6
|
+
FRONT_END_INSTALLERS = [
|
7
|
+
'react',
|
8
|
+
]
|
9
|
+
|
10
|
+
def install
|
11
|
+
exit! unless installable?
|
12
|
+
|
13
|
+
install_base!
|
14
|
+
|
15
|
+
send "install_#{options[:front_end]}!"
|
16
|
+
|
17
|
+
say "You're all set! Run rails s and checkout localhost:3000/inertia-example", :green
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def installable?
|
23
|
+
unless run("./bin/rails webpacker:verify_install")
|
24
|
+
say "Sorry, you need to have webpacker installed for inertia_rails default setup.", :red
|
25
|
+
return false
|
26
|
+
end
|
27
|
+
|
28
|
+
unless options[:front_end].in? FRONT_END_INSTALLERS
|
29
|
+
say "Sorry, there is no generator for #{options[:front_end]}!\n\n", :red
|
30
|
+
say "If you are a #{options[:front_end]} developer, please help us improve inertia_rails by contributing an installer.\n\n"
|
31
|
+
say "https://github.com/inertiajs/inertia-rails/\n\n"
|
32
|
+
|
33
|
+
return false
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def install_base!
|
38
|
+
say "Adding inertia pack tag to application layout", :blue
|
39
|
+
insert_into_file Rails.root.join("app/views/layouts/application.html.erb").to_s, after: "<%= javascript_pack_tag 'application' %>\n" do
|
40
|
+
"\t\t<%= javascript_pack_tag 'inertia' %>\n"
|
41
|
+
end
|
42
|
+
|
43
|
+
say "Installing inertia client packages", :blue
|
44
|
+
run "yarn add @inertiajs/inertia @inertiajs/progress"
|
45
|
+
|
46
|
+
say "Copying example files", :blue
|
47
|
+
template "controller.rb", Rails.root.join("app/controllers/inertia_example_controller.rb").to_s
|
48
|
+
|
49
|
+
say "Adding a route for the example inertia controller...", :blue
|
50
|
+
route "get 'inertia-example', to: 'inertia_example#index'"
|
51
|
+
end
|
52
|
+
|
53
|
+
def install_react!
|
54
|
+
say "Creating a React page component...", :blue
|
55
|
+
run 'yarn add @inertiajs/inertia-react'
|
56
|
+
template "react.jsx", Rails.root.join("app/javascript/Pages/InertiaExample.js").to_s
|
57
|
+
say "Copying inertia.jsx into webpacker's packs folder...", :blue
|
58
|
+
template "inertia.jsx", Rails.root.join("app/javascript/packs/inertia.jsx").to_s
|
59
|
+
say "done!", :green
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/inertia_rails.rb
CHANGED
@@ -20,17 +20,31 @@ module InertiaRails
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
def redirect_to(options = {}, response_options = {})
|
24
|
+
capture_inertia_errors(response_options)
|
25
|
+
super(options, response_options)
|
26
|
+
end
|
27
|
+
|
28
|
+
def redirect_back(fallback_location:, allow_other_host: true, **options)
|
29
|
+
capture_inertia_errors(options)
|
30
|
+
super(
|
31
|
+
fallback_location: fallback_location,
|
32
|
+
allow_other_host: allow_other_host,
|
33
|
+
**options,
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
23
39
|
def inertia_location(url)
|
24
40
|
headers['X-Inertia-Location'] = url
|
25
41
|
head :conflict
|
26
42
|
end
|
27
43
|
|
28
|
-
def
|
29
|
-
if (inertia_errors =
|
44
|
+
def capture_inertia_errors(options)
|
45
|
+
if (inertia_errors = options.dig(:inertia, :errors))
|
30
46
|
session[:inertia_errors] = inertia_errors
|
31
47
|
end
|
32
|
-
|
33
|
-
super(options, response_options)
|
34
48
|
end
|
35
49
|
end
|
36
50
|
end
|
data/lib/inertia_rails/rspec.rb
CHANGED
@@ -35,6 +35,9 @@ module InertiaRails
|
|
35
35
|
def inertia
|
36
36
|
raise 'Inertia test helpers aren\'t set up! Make sure you add inertia: true to describe blocks using inertia tests.' unless inertia_tests_setup?
|
37
37
|
|
38
|
+
if @_inertia_render_wrapper.nil? && !::RSpec.configuration.inertia[:skip_missing_renderer_warnings]
|
39
|
+
warn 'WARNING: the test never created an Inertia renderer. Maybe the code wasn\'t able to reach a `render inertia:` call? If this was intended, or you don\'t want to see this message, set ::RSpec.configuration.inertia[:skip_missing_renderer_warnings] = true'
|
40
|
+
end
|
38
41
|
@_inertia_render_wrapper
|
39
42
|
end
|
40
43
|
|
@@ -49,7 +52,7 @@ module InertiaRails
|
|
49
52
|
protected
|
50
53
|
|
51
54
|
def inertia_tests_setup?
|
52
|
-
|
55
|
+
::RSpec.current_example.metadata.fetch(:inertia, false)
|
53
56
|
end
|
54
57
|
end
|
55
58
|
end
|
@@ -57,6 +60,9 @@ end
|
|
57
60
|
|
58
61
|
RSpec.configure do |config|
|
59
62
|
config.include ::InertiaRails::RSpec::Helpers
|
63
|
+
config.add_setting :inertia, default: {
|
64
|
+
skip_missing_renderer_warnings: false
|
65
|
+
}
|
60
66
|
|
61
67
|
config.before(:each, inertia: true) do
|
62
68
|
new_renderer = InertiaRails::Renderer.method(:new)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
namespace :inertia_rails do
|
2
|
+
namespace :install do
|
3
|
+
desc "Installs inertia_rails packages and configurations for a React based app"
|
4
|
+
task :react => :environment do
|
5
|
+
system 'rails g inertia_rails:install --front_end react'
|
6
|
+
end
|
7
|
+
desc "Installs inertia_rails packages and configurations for a Vue based app"
|
8
|
+
task vue: :environment do
|
9
|
+
system 'rails g inertia_rails:install --front_end vue'
|
10
|
+
end
|
11
|
+
desc "Installs inertia_rails packages and configurations for a Svelte based app"
|
12
|
+
task svelte: :environment do
|
13
|
+
system 'rails g inertia_rails:install --front_end svelte'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
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.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Knoles
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-03-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -110,6 +110,20 @@ dependencies:
|
|
110
110
|
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '0'
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: responders
|
115
|
+
requirement: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
type: :development
|
121
|
+
prerelease: false
|
122
|
+
version_requirements: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
113
127
|
description:
|
114
128
|
email:
|
115
129
|
- brain@bellawatt.com
|
@@ -129,6 +143,7 @@ files:
|
|
129
143
|
- LICENSE.txt
|
130
144
|
- README.md
|
131
145
|
- Rakefile
|
146
|
+
- app/controllers/inertia_rails/static_controller.rb
|
132
147
|
- app/views/inertia.html.erb
|
133
148
|
- bin/console
|
134
149
|
- bin/setup
|
@@ -136,7 +151,12 @@ files:
|
|
136
151
|
- gemfiles/rails_5.1.gemfile
|
137
152
|
- gemfiles/rails_5.2.gemfile
|
138
153
|
- gemfiles/rails_6.0.gemfile
|
154
|
+
- gemfiles/rails_6.1.gemfile
|
139
155
|
- inertia_rails.gemspec
|
156
|
+
- lib/generators/inertia_rails/install/controller.rb
|
157
|
+
- lib/generators/inertia_rails/install/inertia.jsx
|
158
|
+
- lib/generators/inertia_rails/install/react.jsx
|
159
|
+
- lib/generators/inertia_rails/install_generator.rb
|
140
160
|
- lib/inertia_rails.rb
|
141
161
|
- lib/inertia_rails/controller.rb
|
142
162
|
- lib/inertia_rails/engine.rb
|
@@ -150,7 +170,9 @@ files:
|
|
150
170
|
- lib/patches/debug_exceptions.rb
|
151
171
|
- lib/patches/debug_exceptions/patch-5-0.rb
|
152
172
|
- lib/patches/debug_exceptions/patch-5-1.rb
|
173
|
+
- lib/patches/mapper.rb
|
153
174
|
- lib/patches/request.rb
|
175
|
+
- lib/tasks/inertia_rails.rake
|
154
176
|
homepage: https://github.com/inertiajs/inertia-rails
|
155
177
|
licenses:
|
156
178
|
- MIT
|