inertia_rails 1.8.0 → 1.11.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: 0c9c8c3b0d07a467179b741d6ce1f9d79d6190f0c71ecbe3e960536929055caf
4
- data.tar.gz: 2f0f3a5ac49480f5fae1b28c771fe7bc3ea6de2953c734e0015b617fcc70a8bc
3
+ metadata.gz: 7912624c7ea6f1c71a896b969b704d8ff329ee41a3d1bc7277c28900b35a6516
4
+ data.tar.gz: 30098f0f5dd3cf41987cd40f139a12259d5501375b85685ab0d427c0e69d230e
5
5
  SHA512:
6
- metadata.gz: d696ea9c18535afb527dfead16bd271613d2bb561936ffd470e85caf78e20138109c6247d2e21724751a94acafc5548849533e50da3774d510528ed6f1221bc4
7
- data.tar.gz: 6aa06ca052045c5f27c8f1a801889cf26ed77bb5e660875e6fe74cd3c7a30eab7c306385b9707842c8a52a8131c797405741a5f34e5397a64b58da2e98c5ae62
6
+ metadata.gz: a97f62fa00d4489ff8364e6b4f9914161a1394905e5830526ba0baa9ae6888ee933a4e7739e18aeb6969f470989fb4aba9031cb62f57b68ed89065ff433d4e54
7
+ data.tar.gz: e9d7b942b9e1b7f4cdb98e9941143b0e08501586266aac08390a510126233ffeca8328e75e9b0f63aea49d1d19820d02b97e65af0fb178bb822c8bf63ad9925c
@@ -8,7 +8,7 @@ jobs:
8
8
  fail-fast: false
9
9
  matrix:
10
10
  ruby: [2.6, 2.7]
11
- rails: ['5.0', '5.1', '5.2', '6.0']
11
+ rails: ['5.0', '5.1', '5.2', '6.0', '6.1']
12
12
 
13
13
  runs-on: ubuntu-latest
14
14
  name: Test against Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}
data/Appraisals CHANGED
@@ -1,3 +1,7 @@
1
+ appraise "rails-6.1" do
2
+ gem "rails", "~> 6.1.0"
3
+ end
4
+
1
5
  appraise "rails-6.0" do
2
6
  gem "rails", "~> 6.0.3", '>= 6.0.3.2'
3
7
  end
data/CHANGELOG.md CHANGED
@@ -4,6 +4,28 @@ 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.11.0] - 2021-03-23
8
+
9
+ * Fixed the install generator. `installable?` was always returning false, preventing it from actually running.
10
+ * Added an install generator for Vue.
11
+
12
+ ## [1.10.0] - 2021-03-22
13
+
14
+ * Added install generator to quickly add Inertia to existing rails apps via `rails inertia_rails:install:react`
15
+
16
+ ## [1.9.2] - 2021-02-23
17
+
18
+ * Improve method for detecting whether a user used the RSpec helpers without adding `inertia: true` to the spec
19
+ * Emit a warning when expecting an Inertia response in RSpec and never reaching a `render inertia:` call
20
+
21
+ ## [1.9.1] - 2021-02-10
22
+
23
+ * Define `redirect_to` and `redirect_back` as public methods for compatibility with other code using them
24
+
25
+ ## [1.9.0] - 2021-01-17
26
+
27
+ * Added the same inertia awareness that redirect_to has to redirect_back
28
+
7
29
  ## [1.8.0] - 2020-12-08
8
30
 
9
31
  * Add `inertia` route helper feature
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.1.0"
6
+
7
+ gemspec path: "../"
@@ -33,4 +33,5 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency "rails-controller-testing"
34
34
  spec.add_development_dependency "sqlite3"
35
35
  spec.add_development_dependency "appraisal"
36
+ spec.add_development_dependency "responders"
36
37
  end
@@ -0,0 +1,7 @@
1
+ class InertiaExampleController < ApplicationController
2
+ def index
3
+ render inertia: 'InertiaExample', props: {
4
+ name: 'World',
5
+ }
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+
3
+ const InertiaExample = ({name}) => (
4
+ <>
5
+ <h1>Hello {name}!</h1>
6
+ </>
7
+ );
8
+
9
+ export default InertiaExample;
@@ -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,11 @@
1
+ <template>
2
+ <h1 :style="{ 'text-align': 'center' }">Hello {{name}}!</h1>
3
+ </template>
4
+
5
+ <script>
6
+ export default {
7
+ props: {
8
+ name: { type: String, required: true },
9
+ },
10
+ }
11
+ </script>
@@ -0,0 +1,24 @@
1
+ import axios from 'axios'
2
+ import Vue from 'vue'
3
+
4
+ import { app, plugin } from '@inertiajs/inertia-vue'
5
+ import { InertiaProgress } from '@inertiajs/progress'
6
+
7
+ document.addEventListener('DOMContentLoaded', () => {
8
+ const csrfToken = document.querySelector('meta[name=csrf-token]').content
9
+ axios.defaults.headers.common['X-CSRF-Token'] = csrfToken
10
+
11
+ InertiaProgress.init();
12
+ const el = document.getElementById('app')
13
+
14
+ Vue.use(plugin)
15
+
16
+ new Vue({
17
+ render: h => h(app, {
18
+ props: {
19
+ initialPage: JSON.parse(el.dataset.page),
20
+ resolveComponent: name => require(`../Pages/${name}`).default,
21
+ },
22
+ }),
23
+ }).$mount(el)
24
+ })
@@ -0,0 +1,74 @@
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
+ 'vue',
9
+ ]
10
+
11
+ def install
12
+ exit! unless installable?
13
+
14
+ install_base!
15
+
16
+ send "install_#{options[:front_end]}!"
17
+
18
+ say "You're all set! Run rails s and checkout localhost:3000/inertia-example", :green
19
+ end
20
+
21
+ protected
22
+
23
+ def installable?
24
+ unless run("./bin/rails webpacker:verify_install")
25
+ say "Sorry, you need to have webpacker installed for inertia_rails default setup.", :red
26
+ return false
27
+ end
28
+
29
+ unless options[:front_end].in? FRONT_END_INSTALLERS
30
+ say "Sorry, there is no generator for #{options[:front_end]}!\n\n", :red
31
+ say "If you are a #{options[:front_end]} developer, please help us improve inertia_rails by contributing an installer.\n\n"
32
+ say "https://github.com/inertiajs/inertia-rails/\n\n"
33
+
34
+ return false
35
+ end
36
+
37
+ true
38
+ end
39
+
40
+ def install_base!
41
+ say "Adding inertia pack tag to application layout", :blue
42
+ insert_into_file Rails.root.join("app/views/layouts/application.html.erb").to_s, after: "<%= javascript_pack_tag 'application' %>\n" do
43
+ "\t\t<%= javascript_pack_tag 'inertia' %>\n"
44
+ end
45
+
46
+ say "Installing inertia client packages", :blue
47
+ run "yarn add @inertiajs/inertia @inertiajs/progress"
48
+
49
+ say "Copying example files", :blue
50
+ template "controller.rb", Rails.root.join("app/controllers/inertia_example_controller.rb").to_s
51
+
52
+ say "Adding a route for the example inertia controller...", :blue
53
+ route "get 'inertia-example', to: 'inertia_example#index'"
54
+ end
55
+
56
+ def install_react!
57
+ say "Creating a React page component...", :blue
58
+ run 'yarn add @inertiajs/inertia-react'
59
+ template "react/InertiaExample.jsx", Rails.root.join("app/javascript/Pages/InertiaExample.js").to_s
60
+ say "Copying inertia.jsx into webpacker's packs folder...", :blue
61
+ template "react/inertia.jsx", Rails.root.join("app/javascript/packs/inertia.jsx").to_s
62
+ say "done!", :green
63
+ end
64
+
65
+ def install_vue!
66
+ say "Creating a Vue page component...", :blue
67
+ run 'yarn add @inertiajs/inertia-vue'
68
+ template "vue/InertiaExample.vue", Rails.root.join("app/javascript/Pages/InertiaExample.vue").to_s
69
+ say "Copying inertia.js into webpacker's packs folder...", :blue
70
+ template "vue/inertia.js", Rails.root.join("app/javascript/packs/inertia.js").to_s
71
+ say "done!", :green
72
+ end
73
+ end
74
+ end
@@ -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 redirect_to(options = {}, response_options = {})
29
- if (inertia_errors = response_options.fetch(:inertia, {}).fetch(:errors, nil))
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
@@ -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
- @_inertia_render_wrapper.present?
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)
@@ -1,3 +1,3 @@
1
1
  module InertiaRails
2
- VERSION = "1.8.0"
2
+ VERSION = "1.11.0"
3
3
  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.8.0
4
+ version: 1.11.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: 2020-12-08 00:00:00.000000000 Z
13
+ date: 2021-03-23 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
@@ -137,7 +151,14 @@ files:
137
151
  - gemfiles/rails_5.1.gemfile
138
152
  - gemfiles/rails_5.2.gemfile
139
153
  - gemfiles/rails_6.0.gemfile
154
+ - gemfiles/rails_6.1.gemfile
140
155
  - inertia_rails.gemspec
156
+ - lib/generators/inertia_rails/install/controller.rb
157
+ - lib/generators/inertia_rails/install/react/InertiaExample.jsx
158
+ - lib/generators/inertia_rails/install/react/inertia.jsx
159
+ - lib/generators/inertia_rails/install/vue/InertiaExample.vue
160
+ - lib/generators/inertia_rails/install/vue/inertia.js
161
+ - lib/generators/inertia_rails/install_generator.rb
141
162
  - lib/inertia_rails.rb
142
163
  - lib/inertia_rails/controller.rb
143
164
  - lib/inertia_rails/engine.rb
@@ -153,6 +174,7 @@ files:
153
174
  - lib/patches/debug_exceptions/patch-5-1.rb
154
175
  - lib/patches/mapper.rb
155
176
  - lib/patches/request.rb
177
+ - lib/tasks/inertia_rails.rake
156
178
  homepage: https://github.com/inertiajs/inertia-rails
157
179
  licenses:
158
180
  - MIT