inertia_rails 1.9.2 → 1.10.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/CHANGELOG.md +4 -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/version.rb +1 -1
- data/lib/tasks/inertia_rails.rake +16 -0
- metadata +7 -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/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.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
|
+
|
7
11
|
## [1.9.2] - 2021-02-23
|
8
12
|
|
9
13
|
* Improve method for detecting whether a user used the RSpec helpers without adding `inertia: true` to the spec
|
@@ -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
|
@@ -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: 2021-
|
13
|
+
date: 2021-03-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -153,6 +153,10 @@ files:
|
|
153
153
|
- gemfiles/rails_6.0.gemfile
|
154
154
|
- gemfiles/rails_6.1.gemfile
|
155
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
|
156
160
|
- lib/inertia_rails.rb
|
157
161
|
- lib/inertia_rails/controller.rb
|
158
162
|
- lib/inertia_rails/engine.rb
|
@@ -168,6 +172,7 @@ files:
|
|
168
172
|
- lib/patches/debug_exceptions/patch-5-1.rb
|
169
173
|
- lib/patches/mapper.rb
|
170
174
|
- lib/patches/request.rb
|
175
|
+
- lib/tasks/inertia_rails.rake
|
171
176
|
homepage: https://github.com/inertiajs/inertia-rails
|
172
177
|
licenses:
|
173
178
|
- MIT
|