inertia_rails 1.12.1 → 2.0.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: 168a95bf6f07afa800c4886e447a035e765a5d7247b0ba2341c9c9b700a46ef9
4
- data.tar.gz: ff006c26b44dff8e5f6f2d0e0477a2af6322958d1ea55dd65da7bb19e79be14a
3
+ metadata.gz: ac66be3f6a11b3caa5d6fec8057f75e4be257e154b3ce77f3f2c7b8ddb38d4bc
4
+ data.tar.gz: cd9891492a338447f41f10016656c369d8870dd71eacd55ce8d4c6be92f08464
5
5
  SHA512:
6
- metadata.gz: 9d1afe94e402b67a10836b1508b55c14c18891dc132dd4cc9d548d759f5097855e685e76c733709bafb0eb42a88142fae9f282074122f820d5b44e039b952d88
7
- data.tar.gz: 9c98cb05d7b30919073788cc7ee81ebd8d72b623a24e67d9c3c3e5d0d3cab71ec870e9c457fc1ce30508c72869b1182bd749cb4fa54d21470049b706cefd1ed0
6
+ metadata.gz: '09beccfde8d305ae45d9afa84d9ace59337e7ae6521984f3047c10723c2ff70dcf01fe66667e51b4ab3bdd52c6d09a915d9edaace24d5aab83db571aa60fca10'
7
+ data.tar.gz: 7f25e813e9bec9bd513f2608bd5892728a504b76b2cab5fb43d2067af78411a12fe02baab6f0dded2591fb095536d6dda5ee7f65d6c4691c1affdce767458c80
@@ -8,7 +8,10 @@ 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', '6.1']
11
+ rails: ['5.1', '5.2', '6.0', '6.1', '7.0']
12
+ exclude:
13
+ - rails: '7.0'
14
+ ruby: 2.6
12
15
 
13
16
  runs-on: ubuntu-latest
14
17
  name: Test against Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}
data/Appraisals CHANGED
@@ -1,3 +1,7 @@
1
+ appraise "rails-7.0" do
2
+ gem "rails", "~> 7.0"
3
+ end
4
+
1
5
  appraise "rails-6.1" do
2
6
  gem "rails", "~> 6.1.0"
3
7
  end
@@ -13,7 +17,3 @@ end
13
17
  appraise "rails-5.1" do
14
18
  gem "rails", "~> 5.1.7"
15
19
  end
16
-
17
- appraise "rails-5.0" do
18
- gem "rails", "~> 5.0.7", '>= 5.0.7.2'
19
- end
data/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ 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
+ ## [2.0.0] - 2022-06-20
8
+
9
+ * Fix an issue with Rails 7.0. Thanks @0xDing and @aviemet!
10
+ * Drop support for Rails 5.0 (and mentally, though not literally drop support for Rails < 6)
11
+
7
12
  ## [1.12.1] - 2022-05-09
8
13
 
9
14
  * Allow inertia to take over after initial pageload when using ssr. Thanks @99monkey!
data/README.md CHANGED
@@ -3,7 +3,136 @@
3
3
 
4
4
  # Inertia.js Rails Adapter
5
5
 
6
- Visit [inertiajs.com](https://inertiajs.com/) for installation instructions, documentation, and to learn more.
6
+ ## Installation
7
+
8
+ ### Backend
9
+
10
+ Just add the inertia rails gem to your Gemfile
11
+ ```ruby
12
+ gem 'inertia_rails'
13
+ ```
14
+
15
+ ### Frontend
16
+
17
+ Rails 7 specific frontend docs coming soon. For now, check out the official Inertia docs at https://inertiajs.com/
18
+
19
+ ## Usage
20
+
21
+ ### Responses
22
+
23
+ Render Inertia responses is simple, just use the inertia renderer in your controller methods. The renderer accepts two arguments, the first is the name of the component you want to render from within your pages directory (without extension). The second argument is an options hash where you can provide `props` to your components. This options hash also allows you to pass `view_data` to your layout, but this is much less common.
24
+
25
+ ```ruby
26
+ def index
27
+ render inertia: 'Event/Index', props: {
28
+ events: Event.all,
29
+ }
30
+ end
31
+ ```
32
+
33
+ ### Shared Data
34
+
35
+ If you have data that you want to be provided as a prop to every component (a common use-case is informationa about the authenticated user) you can use the `shared_data` controller method.
36
+
37
+ ```ruby
38
+ class EventsController < ApplicationController
39
+ # share syncronously
40
+ inertia_share app_name: env['app.name']
41
+
42
+ # share lazily, evaluated at render time
43
+ inertia_share do
44
+ if logged_in?
45
+ {
46
+ user: logged_in_user,
47
+ }
48
+ end
49
+ end
50
+
51
+ # share lazily alternate syntax
52
+ inertia_share user_count: lambda { User.count }
53
+
54
+ end
55
+ ```
56
+
57
+ ### Routing
58
+
59
+ If you don't need a controller to handle a static component, you can route directly to a component with the inertia route helper
60
+
61
+ ```ruby
62
+ inertia 'about' => 'AboutComponent'
63
+ ```
64
+
65
+ ## Configuration
66
+
67
+ Inertia Rails has a few different configuration options that can be set anywhere, but the most common location is from within an initializer.
68
+
69
+ The default config is shown below
70
+ ```ruby
71
+ InertiaRails.configure do |config|
72
+
73
+ # set the current version for automatic asset refreshing. A string value should be used if any.
74
+ config.version = nil
75
+
76
+ # set the layout you want inertia components to be rendered within. This layout must include any required inertia javascript.
77
+ config.layout = 'application'
78
+
79
+ # ssr specific options
80
+ config.ssr_enabled = false
81
+ config.ssr_url = 'http://localhost:13714'
82
+
83
+ end
84
+ ```
85
+
86
+ ## Testing
87
+
88
+ If you're using Rspec, Inertia Rails comes with some nice test helpers to make things simple.
89
+
90
+ To use these helpers, just add the following require statement to your `spec/rails_helper.rb`
91
+
92
+ ```ruby
93
+ require 'inertia_rails/rspec'
94
+ ```
95
+
96
+ And in any test you want to use the inertia helpers, add the inertia flag to the describe block
97
+
98
+ ```ruby
99
+ RSpec.describe EventController, type: :request do
100
+ describe '#index', inertia: true do
101
+ # ...
102
+ end
103
+ end
104
+ ```
105
+
106
+ ### Assertions
107
+
108
+ ```ruby
109
+ RSpec.describe EventController, type: :request do
110
+ describe '#index', inertia: true do
111
+
112
+ # check the component
113
+ expect_inertia.to render_component 'Event/Index'
114
+
115
+ # access the component name
116
+ expect(inertia.component).to eq 'TestComponent'
117
+
118
+ # props (including shared props)
119
+ expect_inertia.to have_exact_props({name: 'Brandon', sport: 'hockey'})
120
+ expect_inertia.to include_props({sport: 'hockey'})
121
+
122
+ # access props
123
+ expect(inertia.props[:name]).to eq 'Brandon'
124
+
125
+ # view data
126
+ expect_inertia.to have_exact_view_data({name: 'Brian', sport: 'basketball'})
127
+ expect_inertia.to include_view_data({sport: 'basketball'})
128
+
129
+ # access view data
130
+ expect(inertia.view_data[:name]).to eq 'Brian'
131
+
132
+ end
133
+ end
134
+
135
+ ```
7
136
 
8
137
  *Maintained and sponsored by the team at [bellaWatt](https://bellawatt.com/)*
9
138
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", "~> 5.0.7", ">= 5.0.7.2"
5
+ gem "rails", "~> 7.0"
6
6
 
7
7
  gemspec path: "../"
@@ -8,7 +8,7 @@ module InertiaRails
8
8
  end
9
9
 
10
10
  initializer "inertia_rails.action_controller" do
11
- ActiveSupport.on_load(:action_controller) do
11
+ ActiveSupport.on_load(:action_controller_base) do
12
12
  include ::InertiaRails::Controller
13
13
  end
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module InertiaRails
2
- VERSION = "1.12.1"
2
+ VERSION = "2.0.0"
3
3
  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.12.1
4
+ version: 2.0.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: 2022-05-09 00:00:00.000000000 Z
13
+ date: 2022-06-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -147,11 +147,11 @@ files:
147
147
  - app/views/inertia.html.erb
148
148
  - bin/console
149
149
  - bin/setup
150
- - gemfiles/rails_5.0.gemfile
151
150
  - gemfiles/rails_5.1.gemfile
152
151
  - gemfiles/rails_5.2.gemfile
153
152
  - gemfiles/rails_6.0.gemfile
154
153
  - gemfiles/rails_6.1.gemfile
154
+ - gemfiles/rails_7.0.gemfile
155
155
  - inertia_rails.gemspec
156
156
  - lib/generators/inertia_rails/install/controller.rb
157
157
  - lib/generators/inertia_rails/install/react/InertiaExample.jsx