inertia_rails 1.6.0 → 1.9.1

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: b889c5a06cf6c9310b1d64c1e19a5e979aea7ba874c3014867a462386dd28937
4
- data.tar.gz: c5e1bf21eb3ff8dc1e14ebadedf43bb82f8b1af6aa46680610ad4b0054d90b3b
3
+ metadata.gz: 8b998cadfc3e3285f53cee917e812536b2d735099b738cde2c6aa215480d0a78
4
+ data.tar.gz: e4bbfbdfafbb994db348d3ef7d6c6082227b54a92f2f5588e0eaa72b833b7491
5
5
  SHA512:
6
- metadata.gz: 65a66ab26b16808a9b88467a6b579074f68ba68877c055b8d2e333422454041f3461ff4ab0a947f2a52572edd8bf1c88d62d6d32ec7a1c8bd6ca776158f756c0
7
- data.tar.gz: 724961702c0bd5ffb53e427d8791f1064dcc080c4cbc253297f30207c0017065b0f2c12b4822c5969401582972810c8960fbc494884bebb32fe1df907e6a7d79
6
+ metadata.gz: 3afe130f99ae9d4c22976c4aca5ab5309aa407da431551432c2d150066c8f8914a8f6a30995f36bf70326f6880cdaafe9727183dcd7b63dc77c130039ecfc06c
7
+ data.tar.gz: 7d68480b6f781ae9533d40a891f470dbb0478b9db6b037abe267c5b32ac661152790a4ae6c7b904356dd597e1aed6804ef0609c9f96064275b91a9cde89835af
@@ -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,26 @@ 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.9.1] - 2021-02-10
8
+
9
+ * Define `redirect_to` and `redirect_back` as public methods for compatibility with other code using them
10
+
11
+ ## [1.9.0] - 2021-01-17
12
+
13
+ * Added the same inertia awareness that redirect_to has to redirect_back
14
+
15
+ ## [1.8.0] - 2020-12-08
16
+
17
+ * Add `inertia` route helper feature
18
+
19
+ ## [1.7.1] - 2020-11-24
20
+
21
+ * Fix the definition for InertiaRails::Lazy to avoid an uninitialized constant error when booting an application.
22
+
23
+ ## [1.7.0] - 2020-11-24
24
+
25
+ * Add support for "lazy" props while rendering. These are props that never compute on the initial page load. The only render during a partial update that calls for them explicitly.
26
+
7
27
  ## [1.6.0] - 2020-11-20
8
28
 
9
29
  * Built in error sharing across redirects! adding `{ inertia: { errors: 'errors go here' } }` as an option in `redirect_to` will automatically feed an `errors` prop to whatever is rendered after the redirect.
@@ -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
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
@@ -1,5 +1,6 @@
1
1
  # Needed for `thread_mattr_accessor`
2
2
  require 'active_support/core_ext/module/attribute_accessors_per_thread'
3
+ require 'inertia_rails/lazy'
3
4
 
4
5
  module InertiaRails
5
6
  thread_mattr_accessor :threadsafe_shared_plain_data
@@ -36,6 +37,10 @@ module InertiaRails
36
37
  self.shared_blocks = []
37
38
  end
38
39
 
40
+ def self.lazy(value = nil, &block)
41
+ InertiaRails::Lazy.new(value, &block)
42
+ end
43
+
39
44
  private
40
45
 
41
46
  module Configuration
@@ -0,0 +1,28 @@
1
+ module InertiaRails
2
+ class Lazy
3
+ def initialize(value = nil, &block)
4
+ @value = value
5
+ @block = block
6
+ end
7
+
8
+ def call
9
+ to_proc.call
10
+ end
11
+
12
+ def to_proc
13
+ # This is called by controller.instance_exec, which changes self to the
14
+ # controller instance. That makes the instance variables unavailable to the
15
+ # proc via closure. Copying the instance variables to local variables before
16
+ # the proc is returned keeps them in scope for the returned proc.
17
+ value = @value
18
+ block = @block
19
+ if value.respond_to?(:call)
20
+ value
21
+ elsif value
22
+ Proc.new { value }
23
+ else
24
+ block
25
+ end
26
+ end
27
+ end
28
+ end
@@ -27,13 +27,13 @@ module InertiaRails
27
27
  private
28
28
 
29
29
  def props
30
- only = (@request.headers['X-Inertia-Partial-Data'] || '').split(',').compact.map(&:to_sym)
31
-
32
- _props = ::InertiaRails.shared_data(@controller).merge(@props)
33
-
34
- _props = (only.any? && @request.headers['X-Inertia-Partial-Component'] == component) ?
35
- _props.select {|key| key.in? only} :
36
- _props
30
+ _props = ::InertiaRails.shared_data(@controller).merge(@props).select do |key, prop|
31
+ if rendering_partial_component?
32
+ key.in? partial_keys
33
+ else
34
+ !prop.is_a?(InertiaRails::Lazy)
35
+ end
36
+ end
37
37
 
38
38
  deep_transform_values(_props, lambda {|prop| prop.respond_to?(:call) ? @controller.instance_exec(&prop) : prop })
39
39
  end
@@ -52,5 +52,13 @@ module InertiaRails
52
52
 
53
53
  hash.transform_values {|value| deep_transform_values(value, proc)}
54
54
  end
55
+
56
+ def partial_keys
57
+ (@request.headers['X-Inertia-Partial-Data'] || '').split(',').compact.map(&:to_sym)
58
+ end
59
+
60
+ def rendering_partial_component?
61
+ @request.inertia_partial? && @request.headers['X-Inertia-Partial-Component'] == component
62
+ end
55
63
  end
56
64
  end
@@ -1,3 +1,3 @@
1
1
  module InertiaRails
2
- VERSION = "1.6.0"
2
+ VERSION = "1.9.1"
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
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.6.0
4
+ version: 1.9.1
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-20 00:00:00.000000000 Z
13
+ date: 2021-02-10 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,11 +151,13 @@ 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
140
156
  - lib/inertia_rails.rb
141
157
  - lib/inertia_rails/controller.rb
142
158
  - lib/inertia_rails/engine.rb
143
159
  - lib/inertia_rails/inertia_rails.rb
160
+ - lib/inertia_rails/lazy.rb
144
161
  - lib/inertia_rails/middleware.rb
145
162
  - lib/inertia_rails/renderer.rb
146
163
  - lib/inertia_rails/rspec.rb
@@ -149,6 +166,7 @@ files:
149
166
  - lib/patches/debug_exceptions.rb
150
167
  - lib/patches/debug_exceptions/patch-5-0.rb
151
168
  - lib/patches/debug_exceptions/patch-5-1.rb
169
+ - lib/patches/mapper.rb
152
170
  - lib/patches/request.rb
153
171
  homepage: https://github.com/inertiajs/inertia-rails
154
172
  licenses: