inertia_rails 1.2.2 → 1.5.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: 0536ef39b6fe79eef541a105295cd99516701bc54feb5d0b1e323d58e28da62e
4
- data.tar.gz: 219c6c1b1109edca4282233e94b2b429827f1c88da172d90084c8d02b0c5ef74
3
+ metadata.gz: ca1386958c2d3e3c0b0dfbab50c7e59f5a21144c1fc879e62493dcd54bc11ef5
4
+ data.tar.gz: de0fc529f805b096ea8c567c2f9c78b9d30cd730aa2a8439f03b976d6e4e9a82
5
5
  SHA512:
6
- metadata.gz: 13fab1b82e088b1917748c5d2547c59723680a253e9268b9f29753afac8b83df89fe952cc4125ad0ccfea8ec2c6b848a901207596fcbb94ee7563c09c7a5d91b
7
- data.tar.gz: 024b161f76d4cced631537f3454092b53cf5ee48e72723a6825a9aa20bdf2ad59eaeeef72537d1971889ebac8652e6b29c8a9ed9bcd4123b11736814a39d08cf
6
+ metadata.gz: bb44ba24fb2f5ef1e020824a31b806840be221da969d73b19404db03c537ff1cb38cb8500b15dbe456ede6e0aec451fa06652b1b7bfa387f5ab6f0f007972f18
7
+ data.tar.gz: 1db014d57a1a78a505e26b70b18f67e365b40829e7c8a847de29cd428ccb2882d6fb87a664758f6e77918cd7570132c05aecd102d5ed97eed5a72d73e68913cd
@@ -1,24 +1,34 @@
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
+ rails: ['5.0', '5.1', '5.2', '6.0']
12
+
7
13
  runs-on: ubuntu-latest
14
+ name: Test against Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }}
8
15
 
9
16
  steps:
10
- - uses: actions/checkout@v1
17
+ - uses: actions/checkout@v2
11
18
 
12
19
  - name: Setup System
13
20
  run: sudo apt-get install libsqlite3-dev
14
21
 
15
- - name: Set up Ruby 2.6
16
- uses: actions/setup-ruby@v1
22
+ - name: Set up Ruby
23
+ uses: ruby/setup-ruby@v1
17
24
  with:
18
- ruby-version: 2.6.x
25
+ ruby-version: ${{ matrix.ruby }}
19
26
 
20
27
  - name: Install gems
28
+ env:
29
+ MATRIX_RAILS_VERSION: ${{ matrix.rails }}
21
30
  run: |
31
+ export BUNDLE_GEMFILE="${GITHUB_WORKSPACE}/gemfiles/rails_${MATRIX_RAILS_VERSION}.gemfile"
22
32
  gem install bundler
23
33
  bundle install --jobs 4 --retry 3
24
34
 
data/.gitignore CHANGED
@@ -17,3 +17,6 @@
17
17
 
18
18
  # rspec failure tracking
19
19
  .rspec_status
20
+
21
+ # Appraisal
22
+ gemfiles/*.gemfile.lock
@@ -0,0 +1,15 @@
1
+ appraise "rails-6.0" do
2
+ gem "rails", "~> 6.0.3", '>= 6.0.3.2'
3
+ end
4
+
5
+ appraise "rails-5.2" do
6
+ gem "rails", "~> 5.2.4", '>= 5.2.4.3'
7
+ end
8
+
9
+ appraise "rails-5.1" do
10
+ gem "rails", "~> 5.1.7"
11
+ end
12
+
13
+ appraise "rails-5.0" do
14
+ gem "rails", "~> 5.0.7", '>= 5.0.7.2'
15
+ end
@@ -4,6 +4,32 @@ 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.5.0] - 2020-10-07
8
+
9
+ * Test against multiple Rails versions in Github Actions
10
+ * Add the `inertia_location` controller method that forces a full page refresh
11
+
12
+ ## [1.4.1] - 2020-08-06
13
+
14
+ * Fixed a bug involving threadsafe versions and layouts
15
+
16
+ ## [1.4.0] - 2020-07-09
17
+
18
+ * Fixed Ruby 2.7 deprecation warnings
19
+ * Added `inertia_partial?` method
20
+ * Fixed homepage in the gemspec
21
+ * Make the InertiaRails module data threadsafe
22
+
23
+ ## [1.3.1] - 2020-02-20
24
+
25
+ * Fix a typo in the README (inertia only has 1 t!)
26
+
27
+ ## [1.3.0] - 2020-01-28
28
+
29
+ ### Added
30
+
31
+ * Added request.inertia? method
32
+
7
33
  ## [1.2.2] - 2020-01-21
8
34
 
9
35
  ### 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
 
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.0.7", ">= 5.0.7.2"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.1.7"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.2.4", ">= 5.2.4.3"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 6.0.3", ">= 6.0.3.2"
6
+
7
+ gemspec path: "../"
@@ -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,12 @@ 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"
35
+ spec.add_development_dependency "appraisal"
34
36
  end
@@ -3,6 +3,7 @@ require 'inertia_rails/engine'
3
3
 
4
4
  require 'patches/debug_exceptions'
5
5
  require 'patches/better_errors'
6
+ require 'patches/request'
6
7
 
7
8
  ActionController::Renderers.add :inertia do |component, options|
8
9
  InertiaRails::Renderer.new(
@@ -7,10 +7,15 @@ 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
14
14
  end
15
+
16
+ def inertia_location(url)
17
+ headers['X-Inertia-Location'] = url
18
+ head :conflict
19
+ end
15
20
  end
16
21
  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
@@ -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.2"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -11,13 +11,7 @@ if defined?(ActionDispatch::DebugExceptions)
11
11
  require 'patches/debug_exceptions/patch-5-1'
12
12
  elsif ActionPack.version.to_s >= '5.0'
13
13
  require 'patches/debug_exceptions/patch-5-0'
14
- elsif ActionPack.version.to_s >= '4.2'
15
- require 'patches/debug_exceptions/patch-4-2'
16
- elsif ActionPack.version.to_s >= '4.1'
17
- require 'patches/debug_exceptions/patch-4-1'
18
14
  else
19
- # No patch required, because text rendering for
20
- # XHR requests was introduced with Rails 4.1:
21
- # https://github.com/rails/rails/pull/11960
15
+ # This gem supports Rails 5 or later
22
16
  end
23
17
  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.2
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Knoles
@@ -10,8 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-01-22 00:00:00.000000000 Z
13
+ date: 2020-10-07 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '5'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '5'
15
29
  - !ruby/object:Gem::Dependency
16
30
  name: bundler
17
31
  requirement: !ruby/object:Gem::Requirement
@@ -32,30 +46,30 @@ dependencies:
32
46
  requirements:
33
47
  - - "~>"
34
48
  - !ruby/object:Gem::Version
35
- version: '10.0'
49
+ version: '13.0'
36
50
  type: :development
37
51
  prerelease: false
38
52
  version_requirements: !ruby/object:Gem::Requirement
39
53
  requirements:
40
54
  - - "~>"
41
55
  - !ruby/object:Gem::Version
42
- version: '10.0'
56
+ version: '13.0'
43
57
  - !ruby/object:Gem::Dependency
44
58
  name: rspec-rails
45
59
  requirement: !ruby/object:Gem::Requirement
46
60
  requirements:
47
61
  - - "~>"
48
62
  - !ruby/object:Gem::Version
49
- version: '3.0'
63
+ version: '4.0'
50
64
  type: :development
51
65
  prerelease: false
52
66
  version_requirements: !ruby/object:Gem::Requirement
53
67
  requirements:
54
68
  - - "~>"
55
69
  - !ruby/object:Gem::Version
56
- version: '3.0'
70
+ version: '4.0'
57
71
  - !ruby/object:Gem::Dependency
58
- name: rails
72
+ name: rails-controller-testing
59
73
  requirement: !ruby/object:Gem::Requirement
60
74
  requirements:
61
75
  - - ">="
@@ -69,7 +83,7 @@ dependencies:
69
83
  - !ruby/object:Gem::Version
70
84
  version: '0'
71
85
  - !ruby/object:Gem::Dependency
72
- name: rails-controller-testing
86
+ name: sqlite3
73
87
  requirement: !ruby/object:Gem::Requirement
74
88
  requirements:
75
89
  - - ">="
@@ -83,7 +97,7 @@ dependencies:
83
97
  - !ruby/object:Gem::Version
84
98
  version: '0'
85
99
  - !ruby/object:Gem::Dependency
86
- name: sqlite3
100
+ name: appraisal
87
101
  requirement: !ruby/object:Gem::Requirement
88
102
  requirements:
89
103
  - - ">="
@@ -108,6 +122,7 @@ files:
108
122
  - ".github/workflows/push.yml"
109
123
  - ".gitignore"
110
124
  - ".rspec"
125
+ - Appraisals
111
126
  - CHANGELOG.md
112
127
  - CODE_OF_CONDUCT.md
113
128
  - Gemfile
@@ -117,6 +132,10 @@ files:
117
132
  - app/views/inertia.html.erb
118
133
  - bin/console
119
134
  - bin/setup
135
+ - gemfiles/rails_5.0.gemfile
136
+ - gemfiles/rails_5.1.gemfile
137
+ - gemfiles/rails_5.2.gemfile
138
+ - gemfiles/rails_6.0.gemfile
120
139
  - inertia_rails.gemspec
121
140
  - lib/inertia_rails.rb
122
141
  - lib/inertia_rails/controller.rb
@@ -128,17 +147,16 @@ files:
128
147
  - lib/inertia_rails/version.rb
129
148
  - lib/patches/better_errors.rb
130
149
  - lib/patches/debug_exceptions.rb
131
- - lib/patches/debug_exceptions/patch-4-1.rb
132
- - lib/patches/debug_exceptions/patch-4-2.rb
133
150
  - lib/patches/debug_exceptions/patch-5-0.rb
134
151
  - lib/patches/debug_exceptions/patch-5-1.rb
135
- homepage: https://github.com/inertiajs/inertia-rails/
152
+ - lib/patches/request.rb
153
+ homepage: https://github.com/inertiajs/inertia-rails
136
154
  licenses:
137
155
  - MIT
138
156
  metadata:
139
- homepage_uri: https://github.com/inertiajs/inertia-rails/
140
- source_code_uri: https://github.com/inertiajs/inertia-rails/
141
- changelog_uri: https://github.com/inertiajs/inertia-rails//CHANGELOG.md
157
+ homepage_uri: https://github.com/inertiajs/inertia-rails
158
+ source_code_uri: https://github.com/inertiajs/inertia-rails
159
+ changelog_uri: https://github.com/inertiajs/inertia-rails/CHANGELOG.md
142
160
  post_install_message:
143
161
  rdoc_options: []
144
162
  require_paths:
@@ -1,41 +0,0 @@
1
- # Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests
2
- #
3
- # Original source:
4
- # https://github.com/rails/rails/blob/4-1-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_exception(env, exception)
10
- wrapper = ExceptionWrapper.new(env, exception)
11
- log_error(env, wrapper)
12
-
13
- if env['action_dispatch.show_detailed_exceptions']
14
- request = Request.new(env)
15
- template = ActionView::Base.new([RESCUES_TEMPLATE_PATH],
16
- request: request,
17
- exception: wrapper.exception,
18
- application_trace: wrapper.application_trace,
19
- framework_trace: wrapper.framework_trace,
20
- full_trace: wrapper.full_trace,
21
- routes_inspector: routes_inspector(exception),
22
- source_extract: wrapper.source_extract,
23
- line_number: wrapper.line_number,
24
- file: wrapper.file
25
- )
26
- file = "rescues/#{wrapper.rescue_template}"
27
-
28
- if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only
29
- body = template.render(template: file, layout: false, formats: [:text])
30
- format = "text/plain"
31
- else
32
- body = template.render(template: file, layout: 'rescues/layout')
33
- format = "text/html"
34
- end
35
- render(wrapper.status_code, body, format)
36
- else
37
- raise exception
38
- end
39
- end
40
- end)
41
- end
@@ -1,52 +0,0 @@
1
- # Patch ActionDispatch::DebugExceptions to render HTML for Inertia requests
2
- #
3
- # Original source:
4
- # https://github.com/rails/rails/blob/4-2-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_exception(env, exception)
10
- wrapper = ExceptionWrapper.new(env, exception)
11
- log_error(env, wrapper)
12
-
13
- if env['action_dispatch.show_detailed_exceptions']
14
- request = Request.new(env)
15
- traces = wrapper.traces
16
-
17
- trace_to_show = 'Application Trace'
18
- if traces[trace_to_show].empty? && wrapper.rescue_template != 'routing_error'
19
- trace_to_show = 'Full Trace'
20
- end
21
-
22
- if source_to_show = traces[trace_to_show].first
23
- source_to_show_id = source_to_show[:id]
24
- end
25
-
26
- template = ActionView::Base.new([RESCUES_TEMPLATE_PATH],
27
- request: request,
28
- exception: wrapper.exception,
29
- traces: traces,
30
- show_source_idx: source_to_show_id,
31
- trace_to_show: trace_to_show,
32
- routes_inspector: routes_inspector(exception),
33
- source_extracts: wrapper.source_extracts,
34
- line_number: wrapper.line_number,
35
- file: wrapper.file
36
- )
37
- file = "rescues/#{wrapper.rescue_template}"
38
-
39
- if request.xhr? && !request.headers['X-Inertia'] # <<<< this line is changed only
40
- body = template.render(template: file, layout: false, formats: [:text])
41
- format = "text/plain"
42
- else
43
- body = template.render(template: file, layout: 'rescues/layout')
44
- format = "text/html"
45
- end
46
- render(wrapper.status_code, body, format)
47
- else
48
- raise exception
49
- end
50
- end
51
- end)
52
- end