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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3300d5a0d8ba1a4a433151b232dc06a2fbbdc337f8c1948b6a1fd52dbc20b4d
4
- data.tar.gz: 3a62632643c8761c00fe3b462f2710d094a9adb06df0d7942b516c669eec7515
3
+ metadata.gz: c76eba9ada41f6b781b030f81b43bb87169034594127e106ec4dbee472926e8e
4
+ data.tar.gz: e9ed9115c9d6a678bdefdeeeafbeb1790c9a28f37521d71c699d5ca40989cd86
5
5
  SHA512:
6
- metadata.gz: 29d82e990a312f2392f14b209c10d6cb198d1f335d0b0e33b2d6821d8bcbc51adeb6d489362fbf2f124bc0b3605d152eb8470221c061eaf6dcae5083f5e86a79
7
- data.tar.gz: 44565a5b1b36086a7baf965671fd09d5b1e75f3ed393c7de459e5a3c4a7a2d17bd5f485f0f9b68261631cd47cd371439357cd1a852ed2d6a82aa71268c51aaf8
6
+ metadata.gz: 5d0285ccf5284c9fb4d267d25dfc899d58be5f57b2166fc42251246398483aaf639c8dbec94181a1a5978c020ea2fb796872248dd3de7c14db165b8ab20755cb
7
+ data.tar.gz: c06d57bec2e2c4fa55b15428055684999af1d65ee226f42263cb945d17ce4f06029bc8365b2a9f52b59db924b251f34944dd96998a7933b64fe18c6e80ae3117
@@ -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,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.
@@ -0,0 +1,7 @@
1
+ module InertiaRails
2
+ class StaticController < ::ApplicationController
3
+ def static
4
+ render inertia: params[:component]
5
+ end
6
+ end
7
+ end
@@ -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,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,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,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
@@ -4,6 +4,7 @@ require 'inertia_rails/engine'
4
4
  require 'patches/debug_exceptions'
5
5
  require 'patches/better_errors'
6
6
  require 'patches/request'
7
+ require 'patches/mapper'
7
8
 
8
9
  ActionController::Renderers.add :inertia do |component, options|
9
10
  InertiaRails::Renderer.new(
@@ -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.7.1"
2
+ VERSION = "1.10.0"
3
3
  end
@@ -0,0 +1,8 @@
1
+ ActionDispatch::Routing::Mapper.class_eval do
2
+ def inertia(args, &block)
3
+ route = args.keys.first
4
+ component = args.values.first
5
+
6
+ get(route => 'inertia_rails/static#static', defaults: {component: component})
7
+ end
8
+ 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.7.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: 2020-11-24 00:00:00.000000000 Z
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