inertia_rails-contrib 0.4.0 → 0.5.0
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 +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +31 -0
- data/lib/inertia_rails_contrib/configuration.rb +10 -0
- data/lib/inertia_rails_contrib/engine.rb +9 -0
- data/lib/inertia_rails_contrib/inertia_ui_modal/inertia_rails_patch.rb +20 -0
- data/lib/inertia_rails_contrib/inertia_ui_modal/redirect.rb +16 -0
- data/lib/inertia_rails_contrib/inertia_ui_modal/renderer.rb +57 -0
- data/lib/inertia_rails_contrib/inertia_ui_modal.rb +27 -0
- data/lib/inertia_rails_contrib/version.rb +1 -1
- data/lib/inertia_rails_contrib.rb +14 -1
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eff1b41b96c46c48c582218d5a3337a26f7e6ee5bb94a1bf32ddca65d86ff8d9
|
4
|
+
data.tar.gz: 1d6ffdd2a0aeb3de9f90e364a260f53a80f14b98a4d0a8c685c5181b9132eb39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 757b700b44d096aef10748596026b81f3b7fb337ce894ec8e877f5d1d0994a925e56c8541062593177dd32e2c3d8bbd2970a77b48d9fb4c456ecd242f81a806a
|
7
|
+
data.tar.gz: 2edff2c7ebfcd93b35bb130d3166a3aba3be16fea99bb5c4113049e54033e4004c05c6887c7850abe3d54ea5b34c7737747917a4795441cc5477caeed217c0d5
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning].
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.5.0] - 2025-06-11
|
11
|
+
|
12
|
+
Added:
|
13
|
+
|
14
|
+
- [InertiaUI Modal](https://github.com/inertiaui/modal) support ([@skryukov])
|
15
|
+
|
10
16
|
## [0.4.0] - 2024-12-23
|
11
17
|
|
12
18
|
Changed:
|
@@ -78,7 +84,9 @@ Added:
|
|
78
84
|
[@Shaglock]: https://github.com/Shaglock
|
79
85
|
[@skryukov]: https://github.com/skryukov
|
80
86
|
|
81
|
-
[Unreleased]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.
|
87
|
+
[Unreleased]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.5.0...HEAD
|
88
|
+
[0.5.0]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.4.0...v0.5.0
|
89
|
+
[0.4.0]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.3.0...v0.4.0
|
82
90
|
[0.3.0]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.2.2...v0.3.0
|
83
91
|
[0.2.2]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.2.1...v0.2.2
|
84
92
|
[0.2.1]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.2.0...v0.2.1
|
data/README.md
CHANGED
@@ -27,6 +27,37 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
27
27
|
|
28
28
|
$ gem install inertia_rails-contrib
|
29
29
|
|
30
|
+
## InertiaUI Modal Support
|
31
|
+
|
32
|
+
`InertiaRailsContrib` provides support for [InertiaUI Modal](https://github.com/inertiaui/modal) in the Rails application.
|
33
|
+
|
34
|
+
With InertiaUI Modal, you can easily open any route in a Modal or Slideover without having to change anything about your existing routes or controllers.
|
35
|
+
|
36
|
+
By default, InertiaUI Modal doesn't require anything from the Inertia Server Adapters, since it just opens modals without changing the URL.
|
37
|
+
However, InertiaUI Modal also supports updating the URL when opening a modal (see the docs on why you might want that: https://inertiaui.com/inertia-modal/docs/base-route-url).
|
38
|
+
|
39
|
+
### Setup
|
40
|
+
|
41
|
+
1. Follow the NPM installation instructions from the [InertiaUI Modal documentation](https://inertiaui.com/inertia-modal/docs/installation#npm-installation).
|
42
|
+
|
43
|
+
2. Enable InertiaUI Modal, turn on the `enable_inertia_ui_modal` option in the `inertia_rails_contrib.rb` initializer:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
InertiaRailsContrib.configure do |config|
|
47
|
+
config.enable_inertia_ui_modal = true
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
This will add a new render method `inertia_modal` that can be used in the controller actions:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
class PostsController < ApplicationController
|
55
|
+
def new
|
56
|
+
render inertia_modal: 'Post/New', props: { post: Post.new }, base_url: posts_path
|
57
|
+
end
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
30
61
|
## Development
|
31
62
|
|
32
63
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module InertiaRailsContrib
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
initializer "inertia_rails_contrib.inertia_ui_modal" do
|
6
|
+
require_relative "inertia_ui_modal" if InertiaRailsContrib.configuration.enable_inertia_ui_modal
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "inertia_rails/renderer"
|
4
|
+
|
5
|
+
module InertiaRailsContrib
|
6
|
+
module InertiaUIModal
|
7
|
+
module RendererPatch
|
8
|
+
def page
|
9
|
+
super.tap do |modal|
|
10
|
+
if @request.env[:_inertiaui_modal]
|
11
|
+
modal[:props][:_inertiaui_modal] = @request.env[:_inertiaui_modal]
|
12
|
+
modal[:url] = modal[:props][:_inertiaui_modal][:url]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
InertiaRails::Renderer.prepend(InertiaRailsContrib::InertiaUIModal::RendererPatch)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module InertiaRailsContrib
|
4
|
+
module InertiaUIModal
|
5
|
+
module Redirect
|
6
|
+
def redirect_back_or_to(fallback_location, allow_other_host: _allow_other_host, **options)
|
7
|
+
inertia_modal_referer = request.headers[HEADER_BASE_URL]
|
8
|
+
if inertia_modal_referer && (allow_other_host || _url_host_allowed?(inertia_modal_referer))
|
9
|
+
redirect_to inertia_modal_referer, allow_other_host: allow_other_host, **options
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module InertiaRailsContrib
|
4
|
+
module InertiaUIModal
|
5
|
+
class Renderer
|
6
|
+
KNOWN_KEYWORDS = %i[props view_data deep_merge encrypt_history clear_history].freeze
|
7
|
+
|
8
|
+
def initialize(component, controller, request, response, render_method, base_url: nil, **options)
|
9
|
+
@request = request
|
10
|
+
@response = response
|
11
|
+
@base_url = base_url
|
12
|
+
@inertia_renderer = InertiaRails::Renderer.new(component, controller, request, response, render_method, **options.slice(*KNOWN_KEYWORDS))
|
13
|
+
end
|
14
|
+
|
15
|
+
def render
|
16
|
+
if @request.headers[HEADER_USE_ROUTER] == "0" || base_url.blank?
|
17
|
+
return @inertia_renderer.render
|
18
|
+
end
|
19
|
+
|
20
|
+
page = @inertia_renderer.page
|
21
|
+
page[:baseUrl] = base_url
|
22
|
+
page[:meta] = {
|
23
|
+
deferredProps: page.delete(:deferredProps),
|
24
|
+
mergeProps: page.delete(:mergeProps)
|
25
|
+
}
|
26
|
+
|
27
|
+
@request.env[:_inertiaui_modal] = page
|
28
|
+
|
29
|
+
render_base_url
|
30
|
+
end
|
31
|
+
|
32
|
+
def base_url
|
33
|
+
@request.headers[HEADER_BASE_URL] || @base_url
|
34
|
+
end
|
35
|
+
|
36
|
+
def render_base_url
|
37
|
+
original_env = Rack::MockRequest.env_for(
|
38
|
+
base_url,
|
39
|
+
method: @request.method,
|
40
|
+
params: @request.params
|
41
|
+
)
|
42
|
+
@request.each_header do |k, v|
|
43
|
+
original_env[k] ||= v
|
44
|
+
end
|
45
|
+
|
46
|
+
original_request = ActionDispatch::Request.new(original_env)
|
47
|
+
|
48
|
+
path = ActionDispatch::Journey::Router::Utils.normalize_path(original_request.path_info)
|
49
|
+
Rails.application.routes.recognize_path_with_request(original_request, path, {})
|
50
|
+
controller = original_request.controller_class.new
|
51
|
+
controller.request = @request
|
52
|
+
controller.response = @response
|
53
|
+
controller.process(original_request.path_parameters[:action])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "inertia_ui_modal/renderer"
|
4
|
+
require_relative "inertia_ui_modal/redirect"
|
5
|
+
require_relative "inertia_ui_modal/inertia_rails_patch"
|
6
|
+
|
7
|
+
module InertiaRailsContrib
|
8
|
+
module InertiaUIModal
|
9
|
+
HEADER_BASE_URL = "X-InertiaUI-Modal-Base-Url"
|
10
|
+
HEADER_USE_ROUTER = "X-InertiaUI-Modal-Use-Router"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
ActionController::Renderers.add :inertia_modal do |component, options|
|
15
|
+
InertiaRailsContrib::InertiaUIModal::Renderer.new(
|
16
|
+
component,
|
17
|
+
self,
|
18
|
+
request,
|
19
|
+
response,
|
20
|
+
method(:render),
|
21
|
+
**options
|
22
|
+
).render
|
23
|
+
end
|
24
|
+
|
25
|
+
ActiveSupport.on_load(:action_controller_base) do
|
26
|
+
prepend ::InertiaRailsContrib::InertiaUIModal::Redirect
|
27
|
+
end
|
@@ -1,8 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
if defined?(Rails)
|
4
|
+
require "inertia_rails"
|
5
|
+
require_relative "inertia_rails_contrib/engine"
|
6
|
+
end
|
4
7
|
|
5
8
|
require_relative "inertia_rails_contrib/version"
|
9
|
+
require_relative "inertia_rails_contrib/configuration"
|
6
10
|
|
7
11
|
module InertiaRailsContrib
|
12
|
+
class << self
|
13
|
+
def configuration
|
14
|
+
@configuration ||= Configuration.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def configure
|
18
|
+
yield(configuration)
|
19
|
+
end
|
20
|
+
end
|
8
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inertia_rails-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Svyatoslav Kryukov
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: inertia_rails
|
@@ -36,6 +35,12 @@ files:
|
|
36
35
|
- README.md
|
37
36
|
- lib/inertia_rails-contrib.rb
|
38
37
|
- lib/inertia_rails_contrib.rb
|
38
|
+
- lib/inertia_rails_contrib/configuration.rb
|
39
|
+
- lib/inertia_rails_contrib/engine.rb
|
40
|
+
- lib/inertia_rails_contrib/inertia_ui_modal.rb
|
41
|
+
- lib/inertia_rails_contrib/inertia_ui_modal/inertia_rails_patch.rb
|
42
|
+
- lib/inertia_rails_contrib/inertia_ui_modal/redirect.rb
|
43
|
+
- lib/inertia_rails_contrib/inertia_ui_modal/renderer.rb
|
39
44
|
- lib/inertia_rails_contrib/version.rb
|
40
45
|
homepage: https://github.com/skryukov/inertia_rails-contrib
|
41
46
|
licenses:
|
@@ -47,7 +52,6 @@ metadata:
|
|
47
52
|
homepage_uri: https://github.com/skryukov/inertia_rails-contrib
|
48
53
|
source_code_uri: https://github.com/skryukov/inertia_rails-contrib
|
49
54
|
rubygems_mfa_required: 'true'
|
50
|
-
post_install_message:
|
51
55
|
rdoc_options: []
|
52
56
|
require_paths:
|
53
57
|
- lib
|
@@ -62,8 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
66
|
- !ruby/object:Gem::Version
|
63
67
|
version: '0'
|
64
68
|
requirements: []
|
65
|
-
rubygems_version: 3.
|
66
|
-
signing_key:
|
69
|
+
rubygems_version: 3.6.7
|
67
70
|
specification_version: 4
|
68
71
|
summary: A collection of extensions and developer tools for Rails Inertia adapter
|
69
72
|
test_files: []
|