inertia_rails 1.2.1 → 1.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85021602526f07e26abfe34c9fec6e2a6e7dfd30723c5a95691c5973a28960cc
4
- data.tar.gz: 8e57db120b7b33f1205b06793baf7c6dfce435f006b70ab8b6f9a9a3b6d48921
3
+ metadata.gz: 9cd358fa9c397d7899a6d5856840c8a2d3f9d375ebfb080cc8255a7c8fdeb9e6
4
+ data.tar.gz: 7fbc5d37523fda2f27781b6d39765319d8bb5cba876fd0b5a02af7ea7ece80f5
5
5
  SHA512:
6
- metadata.gz: 7f4c8715da18542911ef0dea66e97935b8c3322d28d497c655ef62b2372394f4c4eb392dbdafafd5212c0e6fb2e92eb8980e444223de84f888673e32057780a7
7
- data.tar.gz: c23988c55e8ce4b454bfdfe77b8c7f6e31e0fa6fe0260aa11f73e8051f5e0673828ff4b91ce26184b85b85891698d0bfbd067433a9e0e062f95fe2a43a1ff4dd
6
+ metadata.gz: d22c0fa1f8ce6f8f069e9dc72705f46f9a4ea7cf02540967aed17dbd8f548e11e096ed85c8f0cd3dd1b0ff28071c18c1687f22b8ec7cc847be355fbbe588930b
7
+ data.tar.gz: a7bb964c860efa67cd9c3647a38eb981eba239facea5578c6250b3c611ccb727c1691baeefd7357392f81300166d2a475cbda21cf2fa955238ede06ee1bdaa06
@@ -1,21 +1,27 @@
1
1
  name: Testing
2
2
 
3
- on: [push]
3
+ on: [push, pull_request]
4
4
 
5
5
  jobs:
6
6
  test:
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ ruby: [2.6, 2.7]
11
+
7
12
  runs-on: ubuntu-latest
13
+ name: Test against Ruby ${{ matrix.ruby }}
8
14
 
9
15
  steps:
10
- - uses: actions/checkout@v1
16
+ - uses: actions/checkout@v2
11
17
 
12
18
  - name: Setup System
13
19
  run: sudo apt-get install libsqlite3-dev
14
20
 
15
- - name: Set up Ruby 2.6
16
- uses: actions/setup-ruby@v1
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
17
23
  with:
18
- ruby-version: 2.6.x
24
+ ruby-version: ${{ matrix.ruby }}
19
25
 
20
26
  - name: Install gems
21
27
  run: |
@@ -4,6 +4,34 @@ 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.4.1] - 2020-08-06
8
+
9
+ * Fixed a bug involving threadsafe versions and layouts
10
+
11
+ ## [1.4.0] - 2020-07-09
12
+
13
+ * Fixed Ruby 2.7 deprecation warnings
14
+ * Added `inertia_partial?` method
15
+ * Fixed homepage in the gemspec
16
+ * Make the InertiaRails module data threadsafe
17
+
18
+ ## [1.3.1] - 2020-02-20
19
+
20
+ * Fix a typo in the README (inertia only has 1 t!)
21
+
22
+ ## [1.3.0] - 2020-01-28
23
+
24
+ ### Added
25
+
26
+ * Added request.inertia? method
27
+
28
+ ## [1.2.2] - 2020-01-21
29
+
30
+ ### Fixed
31
+
32
+ * Added patches to allow Rails errors to show properly in the inertia modal
33
+ * Fixed a middleware issue caused by a breaking change in Rack v2.1.*
34
+
7
35
  ## [1.2.1] - 2019-12-6
8
36
 
9
37
  ### Fixed
data/README.md CHANGED
@@ -6,7 +6,7 @@ Visit [inertiajs.com](https://inertiajs.com/) to learn more.
6
6
 
7
7
  The initial version of the gem was named `inertia`; however, that name was not available on Rubygems.
8
8
 
9
- The 1.0.0 version release on Rubygems is `intertia_rails`.
9
+ The 1.0.0 version release on Rubygems is `inertia_rails`.
10
10
 
11
11
  The changes required are:
12
12
 
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ["brain@bellawatt.com", "brandon@bellawatt.com", "eugene@bellawatt.com"]
10
10
 
11
11
  spec.summary = %q{Inertia adapter for Rails}
12
- spec.homepage = "https://github.com/inertiajs/inertia-rails/"
12
+ spec.homepage = "https://github.com/inertiajs/inertia-rails"
13
13
  spec.license = "MIT"
14
14
 
15
15
  spec.metadata["homepage_uri"] = spec.homepage
@@ -25,10 +25,11 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
27
 
28
+ spec.add_runtime_dependency "rails", '>= 5'
29
+
28
30
  spec.add_development_dependency "bundler", "~> 2.0"
29
- spec.add_development_dependency "rake", "~> 10.0"
30
- spec.add_development_dependency "rspec-rails", "~> 3.0"
31
- spec.add_development_dependency "rails"
31
+ spec.add_development_dependency "rake", "~> 13.0"
32
+ spec.add_development_dependency "rspec-rails", "~> 4.0"
32
33
  spec.add_development_dependency "rails-controller-testing"
33
34
  spec.add_development_dependency "sqlite3"
34
35
  end
@@ -1,6 +1,10 @@
1
1
  require 'inertia_rails/renderer'
2
2
  require 'inertia_rails/engine'
3
3
 
4
+ require 'patches/debug_exceptions'
5
+ require 'patches/better_errors'
6
+ require 'patches/request'
7
+
4
8
  ActionController::Renderers.add :inertia do |component, options|
5
9
  InertiaRails::Renderer.new(
6
10
  component,
@@ -7,7 +7,7 @@ module InertiaRails
7
7
  module ClassMethods
8
8
  def inertia_share(**args, &block)
9
9
  before_action do
10
- InertiaRails.share(args) if args
10
+ InertiaRails.share(**args) if args
11
11
  InertiaRails.share_block(block) if block
12
12
  end
13
13
  end
@@ -1,6 +1,9 @@
1
+ # Needed for `thread_mattr_accessor`
2
+ require 'active_support/core_ext/module/attribute_accessors_per_thread'
3
+
1
4
  module InertiaRails
2
- mattr_accessor(:shared_plain_data) { Hash.new }
3
- mattr_accessor(:shared_blocks) { [] }
5
+ thread_mattr_accessor :threadsafe_shared_plain_data
6
+ thread_mattr_accessor :threadsafe_shared_blocks
4
7
 
5
8
  def self.configure
6
9
  yield(Configuration)
@@ -21,11 +24,11 @@ module InertiaRails
21
24
 
22
25
  # "Setters"
23
26
  def self.share(**args)
24
- shared_plain_data.merge!(args)
27
+ self.shared_plain_data = self.shared_plain_data.merge(args)
25
28
  end
26
29
 
27
30
  def self.share_block(block)
28
- shared_blocks.push(block)
31
+ self.shared_blocks = self.shared_blocks + [block]
29
32
  end
30
33
 
31
34
  def self.reset!
@@ -44,6 +47,23 @@ module InertiaRails
44
47
  end
45
48
  end
46
49
 
50
+ # Getters and setters to provide default values for the threadsafe attributes
51
+ def self.shared_plain_data
52
+ self.threadsafe_shared_plain_data || {}
53
+ end
54
+
55
+ def self.shared_plain_data=(val)
56
+ self.threadsafe_shared_plain_data = val
57
+ end
58
+
59
+ def self.shared_blocks
60
+ self.threadsafe_shared_blocks || []
61
+ end
62
+
63
+ def self.shared_blocks=(val)
64
+ self.threadsafe_shared_blocks = val
65
+ end
66
+
47
67
  def self.evaluated_blocks(controller, blocks)
48
68
  blocks.flat_map { |block| controller.instance_exec(&block) }.reduce(&:merge) || {}
49
69
  end
@@ -40,7 +40,7 @@ module InertiaRails
40
40
 
41
41
  def force_refresh(request)
42
42
  request.flash.keep
43
- Rack::Response.new('', 409, {'X-Inertia-Location' => request.original_url})
43
+ Rack::Response.new('', 409, {'X-Inertia-Location' => request.original_url}).finish
44
44
  end
45
45
  end
46
46
  end
@@ -61,7 +61,7 @@ RSpec.configure do |config|
61
61
  config.before(:each, inertia: true) do
62
62
  new_renderer = InertiaRails::Renderer.method(:new)
63
63
  allow(InertiaRails::Renderer).to receive(:new) do |component, controller, request, response, render, named_args|
64
- new_renderer.call(component, controller, request, response, inertia_wrap_render(render), named_args)
64
+ new_renderer.call(component, controller, request, response, inertia_wrap_render(render), **named_args)
65
65
  end
66
66
  end
67
67
  end
@@ -1,3 +1,3 @@
1
1
  module InertiaRails
2
- VERSION = "1.2.1"
2
+ VERSION = "1.4.1"
3
3
  end
@@ -0,0 +1,17 @@
1
+ # Patch BetterErrors::Middleware to render HTML for Inertia requests
2
+ #
3
+ # Original source:
4
+ # https://github.com/BetterErrors/better_errors/blob/v2.5.1/lib/better_errors/middleware.rb
5
+ #
6
+
7
+ if defined?(BetterErrors)
8
+ BetterErrors::Middleware.class_eval do
9
+ prepend(InertiaBetterErrors = Module.new do
10
+ def text?(env)
11
+ return false if env["HTTP_X_INERTIA"]
12
+
13
+ super
14
+ end
15
+ end)
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests
2
+ #
3
+ # Rails has introduced text rendering for XHR requests with Rails 4.1 and
4
+ # changed the implementation in 4.2, 5.0 and 5.1 (unchanged since then).
5
+ #
6
+ # The original source needs to be patched, so that Inertia requests are
7
+ # NOT responded with plain text, but with HTML.
8
+
9
+ if defined?(ActionDispatch::DebugExceptions)
10
+ if ActionPack.version.to_s >= '5.1'
11
+ require 'patches/debug_exceptions/patch-5-1'
12
+ elsif ActionPack.version.to_s >= '5.0'
13
+ require 'patches/debug_exceptions/patch-5-0'
14
+ else
15
+ # This gem supports Rails 5 or later
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ # Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests
2
+ #
3
+ # Original source:
4
+ # https://github.com/rails/rails/blob/5-0-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
5
+ #
6
+
7
+ ActionDispatch::DebugExceptions.class_eval do
8
+ prepend(InertiaDebugExceptions = Module.new do
9
+ def render_for_default_application(request, wrapper)
10
+ template = create_template(request, wrapper)
11
+ file = "rescues/#{wrapper.rescue_template}"
12
+
13
+ if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only
14
+ body = template.render(template: file, layout: false, formats: [:text])
15
+ format = "text/plain"
16
+ else
17
+ body = template.render(template: file, layout: 'rescues/layout')
18
+ format = "text/html"
19
+ end
20
+ render(wrapper.status_code, body, format)
21
+ end
22
+ end)
23
+ end
@@ -0,0 +1,26 @@
1
+ # Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests
2
+ #
3
+ # Original source (unchanged since Rails 5.1):
4
+ # https://github.com/rails/rails/blob/5-1-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
5
+ # https://github.com/rails/rails/blob/5-2-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
6
+ # https://github.com/rails/rails/blob/6-0-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
7
+ #
8
+
9
+ ActionDispatch::DebugExceptions.class_eval do
10
+ prepend(InertiaDebugExceptions = Module.new do
11
+ def render_for_browser_request(request, wrapper)
12
+ template = create_template(request, wrapper)
13
+ file = "rescues/#{wrapper.rescue_template}"
14
+
15
+ if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only
16
+ body = template.render(template: file, layout: false, formats: [:text])
17
+ format = "text/plain"
18
+ else
19
+ body = template.render(template: file, layout: "rescues/layout")
20
+ format = "text/html"
21
+ end
22
+
23
+ render(wrapper.status_code, body, format)
24
+ end
25
+ end)
26
+ end
@@ -0,0 +1,9 @@
1
+ ActionDispatch::Request.class_eval do
2
+ def inertia?
3
+ key? 'HTTP_X_INERTIA'
4
+ end
5
+
6
+ def inertia_partial?
7
+ key? 'HTTP_X_INERTIA_PARTIAL_DATA'
8
+ end
9
+ 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.2.1
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Knoles
@@ -10,64 +10,64 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2019-12-06 00:00:00.000000000 Z
13
+ date: 2020-08-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: bundler
16
+ name: rails
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '2.0'
22
- type: :development
21
+ version: '5'
22
+ type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - "~>"
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: '2.0'
28
+ version: '5'
29
29
  - !ruby/object:Gem::Dependency
30
- name: rake
30
+ name: bundler
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: '10.0'
35
+ version: '2.0'
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '10.0'
42
+ version: '2.0'
43
43
  - !ruby/object:Gem::Dependency
44
- name: rspec-rails
44
+ name: rake
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '3.0'
49
+ version: '13.0'
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: '3.0'
56
+ version: '13.0'
57
57
  - !ruby/object:Gem::Dependency
58
- name: rails
58
+ name: rspec-rails
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ">="
61
+ - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: '0'
63
+ version: '4.0'
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ">="
68
+ - - "~>"
69
69
  - !ruby/object:Gem::Version
70
- version: '0'
70
+ version: '4.0'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rails-controller-testing
73
73
  requirement: !ruby/object:Gem::Requirement
@@ -126,13 +126,18 @@ files:
126
126
  - lib/inertia_rails/renderer.rb
127
127
  - lib/inertia_rails/rspec.rb
128
128
  - lib/inertia_rails/version.rb
129
- homepage: https://github.com/inertiajs/inertia-rails/
129
+ - lib/patches/better_errors.rb
130
+ - lib/patches/debug_exceptions.rb
131
+ - lib/patches/debug_exceptions/patch-5-0.rb
132
+ - lib/patches/debug_exceptions/patch-5-1.rb
133
+ - lib/patches/request.rb
134
+ homepage: https://github.com/inertiajs/inertia-rails
130
135
  licenses:
131
136
  - MIT
132
137
  metadata:
133
- homepage_uri: https://github.com/inertiajs/inertia-rails/
134
- source_code_uri: https://github.com/inertiajs/inertia-rails/
135
- changelog_uri: https://github.com/inertiajs/inertia-rails//CHANGELOG.md
138
+ homepage_uri: https://github.com/inertiajs/inertia-rails
139
+ source_code_uri: https://github.com/inertiajs/inertia-rails
140
+ changelog_uri: https://github.com/inertiajs/inertia-rails/CHANGELOG.md
136
141
  post_install_message:
137
142
  rdoc_options: []
138
143
  require_paths: