inertia_rails 3.4.0 → 3.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +17 -13
- data/lib/generators/inertia/controller/controller_generator.rb +18 -0
- data/lib/generators/inertia/controller/templates/controller.rb.tt +10 -0
- data/lib/generators/inertia/install/frameworks.yml +98 -0
- data/lib/generators/inertia/install/helpers.rb +51 -0
- data/lib/generators/inertia/install/install_generator.rb +291 -0
- data/lib/generators/inertia/install/js_package_manager.rb +50 -0
- data/lib/generators/inertia/install/templates/assets/inertia.svg +1 -0
- data/lib/generators/inertia/install/templates/assets/react.svg +1 -0
- data/lib/generators/inertia/install/templates/assets/svelte.svg +1 -0
- data/lib/generators/inertia/install/templates/assets/vite_ruby.svg +1 -0
- data/lib/generators/inertia/install/templates/assets/vue.svg +1 -0
- data/lib/generators/{inertia_rails/install → inertia/install/templates}/controller.rb +3 -1
- data/lib/generators/inertia/install/templates/dev +23 -0
- data/lib/generators/inertia/install/templates/initializer.rb +6 -0
- data/lib/generators/inertia/install/templates/react/InertiaExample.jsx +60 -0
- data/lib/generators/inertia/install/templates/react/InertiaExample.module.css +80 -0
- data/lib/generators/inertia/install/templates/react/InertiaExample.tsx +60 -0
- data/lib/generators/inertia/install/templates/react/inertia.js +45 -0
- data/lib/generators/inertia/install/templates/react/inertia.ts +51 -0
- data/lib/generators/inertia/install/templates/react/tsconfig.app.json +27 -0
- data/lib/generators/inertia/install/templates/react/tsconfig.json +11 -0
- data/lib/generators/inertia/install/templates/react/tsconfig.node.json +13 -0
- data/lib/generators/inertia/install/templates/react/vite-env.d.ts +1 -0
- data/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte +112 -0
- data/lib/generators/inertia/install/templates/svelte/InertiaExample.ts.svelte +112 -0
- data/lib/generators/inertia/install/templates/svelte/inertia.js +44 -0
- data/lib/generators/inertia/install/templates/svelte/inertia.ts.tt +45 -0
- data/lib/generators/inertia/install/templates/svelte/svelte.config.js +7 -0
- data/lib/generators/inertia/install/templates/svelte/tsconfig.json +21 -0
- data/lib/generators/inertia/install/templates/svelte/tsconfig.node.json +12 -0
- data/lib/generators/inertia/install/templates/svelte/vite-env.d.ts +2 -0
- data/lib/generators/inertia/install/templates/svelte4/InertiaExample.svelte +116 -0
- data/lib/generators/inertia/install/templates/svelte4/InertiaExample.ts.svelte +116 -0
- data/lib/generators/inertia/install/templates/svelte4/inertia.js +43 -0
- data/lib/generators/inertia/install/templates/svelte4/inertia.ts.tt +44 -0
- data/lib/generators/inertia/install/templates/svelte4/svelte.config.js +7 -0
- data/lib/generators/inertia/install/templates/svelte4/tsconfig.json +21 -0
- data/lib/generators/inertia/install/templates/svelte4/tsconfig.node.json +12 -0
- data/lib/generators/inertia/install/templates/svelte4/vite-env.d.ts +2 -0
- data/lib/generators/inertia/install/templates/tailwind/application.css +13 -0
- data/lib/generators/inertia/install/templates/tailwind/postcss.config.js +6 -0
- data/lib/generators/inertia/install/templates/tailwind/tailwind.config.js.tt +18 -0
- data/lib/generators/inertia/install/templates/vue/InertiaExample.ts.vue +117 -0
- data/lib/generators/inertia/install/templates/vue/InertiaExample.vue +117 -0
- data/lib/generators/inertia/install/templates/vue/inertia.js +35 -0
- data/lib/generators/inertia/install/templates/vue/inertia.ts +35 -0
- data/lib/generators/inertia/install/templates/vue/tsconfig.app.json +24 -0
- data/lib/generators/inertia/install/templates/vue/tsconfig.json +11 -0
- data/lib/generators/inertia/install/templates/vue/tsconfig.node.json +22 -0
- data/lib/generators/inertia/install/templates/vue/vite-env.d.ts +1 -0
- data/lib/generators/inertia/scaffold/scaffold_generator.rb +16 -0
- data/lib/generators/inertia/scaffold_controller/scaffold_controller_generator.rb +60 -0
- data/lib/generators/inertia/scaffold_controller/templates/controller.rb.tt +100 -0
- data/lib/generators/inertia_templates/controller/controller_generator.rb +12 -0
- data/lib/generators/inertia_templates/controller/templates/react/view.jsx.tt +8 -0
- data/lib/generators/inertia_templates/controller/templates/react/view.tsx.tt +8 -0
- data/lib/generators/inertia_templates/controller/templates/svelte/view.svelte.tt +2 -0
- data/lib/generators/inertia_templates/controller/templates/svelte4/view.svelte.tt +2 -0
- data/lib/generators/inertia_templates/controller/templates/vue/view.vue.tt +4 -0
- data/lib/generators/inertia_templates/scaffold/scaffold_generator.rb +12 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Edit.jsx.tt +35 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Edit.tsx.tt +40 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Form.jsx.tt +111 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Form.tsx.tt +130 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Index.jsx.tt +26 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Index.tsx.tt +32 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/New.jsx.tt +27 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/New.tsx.tt +32 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/One.jsx.tt +26 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/One.tsx.tt +32 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Show.jsx.tt +32 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Show.tsx.tt +38 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/types.ts.tt +19 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Edit.svelte.tt +36 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Edit.ts.svelte.tt +37 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Form.svelte.tt +97 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Form.ts.svelte.tt +102 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Index.svelte.tt +35 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Index.ts.svelte.tt +39 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/New.svelte.tt +29 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/New.ts.svelte.tt +30 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/One.svelte.tt +28 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/One.ts.svelte.tt +30 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Show.svelte.tt +35 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Show.ts.svelte.tt +39 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/types.ts.tt +19 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.svelte.tt +37 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.ts.svelte.tt +38 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.svelte.tt +96 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.ts.svelte.tt +106 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.svelte.tt +36 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.ts.svelte.tt +37 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/New.svelte.tt +30 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/New.ts.svelte.tt +31 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/One.svelte.tt +28 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/One.ts.svelte.tt +30 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.svelte.tt +39 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.ts.svelte.tt +40 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/types.ts.tt +19 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Edit.ts.vue.tt +37 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Edit.vue.tt +36 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Form.ts.vue.tt +101 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Form.vue.tt +94 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Index.ts.vue.tt +35 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Index.vue.tt +31 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/New.ts.vue.tt +30 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/New.vue.tt +29 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/One.ts.vue.tt +28 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/One.vue.tt +26 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Show.ts.vue.tt +41 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Show.vue.tt +37 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/types.ts.tt +19 -0
- data/lib/generators/inertia_tw_templates/controller/controller_generator.rb +12 -0
- data/lib/generators/inertia_tw_templates/controller/templates/react/view.jsx.tt +8 -0
- data/lib/generators/inertia_tw_templates/controller/templates/react/view.tsx.tt +8 -0
- data/lib/generators/inertia_tw_templates/controller/templates/svelte/view.svelte.tt +2 -0
- data/lib/generators/inertia_tw_templates/controller/templates/svelte4/view.svelte.tt +2 -0
- data/lib/generators/inertia_tw_templates/controller/templates/vue/view.vue.tt +4 -0
- data/lib/generators/inertia_tw_templates/scaffold/scaffold_generator.rb +12 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Edit.jsx.tt +42 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Edit.tsx.tt +47 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Form.jsx.tt +122 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Form.tsx.tt +142 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Index.jsx.tt +43 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Index.tsx.tt +49 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/New.jsx.tt +30 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/New.tsx.tt +35 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/One.jsx.tt +26 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/One.tsx.tt +32 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Show.jsx.tt +47 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Show.tsx.tt +53 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/types.ts.tt +19 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Edit.svelte.tt +44 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Edit.ts.svelte.tt +45 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Form.svelte.tt +118 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Form.ts.svelte.tt +123 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Index.svelte.tt +42 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Index.ts.svelte.tt +46 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/New.svelte.tt +32 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/New.ts.svelte.tt +33 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/One.svelte.tt +28 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/One.ts.svelte.tt +30 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Show.svelte.tt +50 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Show.ts.svelte.tt +54 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/types.ts.tt +19 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Edit.svelte.tt +45 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Edit.ts.svelte.tt +46 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Form.svelte.tt +120 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Form.ts.svelte.tt +130 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Index.svelte.tt +43 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Index.ts.svelte.tt +44 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/New.svelte.tt +33 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/New.ts.svelte.tt +34 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/One.svelte.tt +28 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/One.ts.svelte.tt +30 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Show.svelte.tt +51 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Show.ts.svelte.tt +52 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/types.ts.tt +19 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Edit.ts.vue.tt +45 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Edit.vue.tt +44 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Form.ts.vue.tt +134 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Form.vue.tt +127 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Index.ts.vue.tt +47 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Index.vue.tt +43 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/New.ts.vue.tt +33 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/New.vue.tt +32 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/One.ts.vue.tt +28 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/One.vue.tt +26 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Show.ts.vue.tt +53 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Show.vue.tt +49 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/types.ts.tt +19 -0
- data/lib/inertia_rails/always_prop.rb +6 -0
- data/lib/inertia_rails/base_prop.rb +14 -0
- data/lib/inertia_rails/configuration.rb +4 -1
- data/lib/inertia_rails/controller.rb +16 -4
- data/lib/inertia_rails/defer_prop.rb +21 -0
- data/lib/inertia_rails/generators/controller_template_base.rb +63 -0
- data/lib/inertia_rails/generators/helper.rb +139 -0
- data/lib/inertia_rails/generators/scaffold_template_base.rb +45 -0
- data/lib/inertia_rails/ignore_on_first_load_prop.rb +6 -0
- data/lib/inertia_rails/inertia_rails.rb +34 -12
- data/lib/inertia_rails/lazy_prop.rb +24 -0
- data/lib/inertia_rails/merge_prop.rb +14 -0
- data/lib/inertia_rails/middleware.rb +7 -2
- data/lib/inertia_rails/optional_prop.rb +6 -0
- data/lib/inertia_rails/renderer.rb +106 -20
- data/lib/inertia_rails/version.rb +1 -1
- data/lib/inertia_rails.rb +2 -0
- data/lib/patches/better_errors.rb +10 -8
- data/lib/patches/debug_exceptions/patch-5-0.rb +7 -3
- data/lib/patches/debug_exceptions/patch-5-1.rb +7 -3
- data/lib/patches/mapper.rb +9 -5
- data/lib/patches/request.rb +10 -6
- metadata +185 -13
- data/lib/generators/inertia_rails/install/react/InertiaExample.jsx +0 -9
- data/lib/generators/inertia_rails/install/react/inertia.jsx +0 -17
- data/lib/generators/inertia_rails/install/svelte/InertiaExample.svelte +0 -11
- data/lib/generators/inertia_rails/install/svelte/inertia.js +0 -14
- data/lib/generators/inertia_rails/install/vue/InertiaExample.vue +0 -11
- data/lib/generators/inertia_rails/install/vue/inertia.js +0 -20
- data/lib/generators/inertia_rails/install_generator.rb +0 -84
- data/lib/inertia_rails/lazy.rb +0 -28
@@ -1,20 +1,42 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
require 'inertia_rails/
|
1
|
+
require 'inertia_rails/base_prop'
|
2
|
+
require 'inertia_rails/ignore_on_first_load_prop'
|
3
|
+
require 'inertia_rails/always_prop'
|
4
|
+
require 'inertia_rails/lazy_prop'
|
5
|
+
require 'inertia_rails/optional_prop'
|
6
|
+
require 'inertia_rails/defer_prop'
|
7
|
+
require 'inertia_rails/merge_prop'
|
4
8
|
require 'inertia_rails/configuration'
|
5
9
|
|
6
10
|
module InertiaRails
|
7
|
-
|
11
|
+
class << self
|
12
|
+
CONFIGURATION = Configuration.default
|
8
13
|
|
9
|
-
|
10
|
-
|
11
|
-
|
14
|
+
def configure
|
15
|
+
yield(CONFIGURATION)
|
16
|
+
end
|
12
17
|
|
13
|
-
|
14
|
-
|
15
|
-
|
18
|
+
def configuration
|
19
|
+
CONFIGURATION
|
20
|
+
end
|
21
|
+
|
22
|
+
def lazy(value = nil, &block)
|
23
|
+
LazyProp.new(value, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
def optional(&block)
|
27
|
+
OptionalProp.new(&block)
|
28
|
+
end
|
29
|
+
|
30
|
+
def always(&block)
|
31
|
+
AlwaysProp.new(&block)
|
32
|
+
end
|
33
|
+
|
34
|
+
def merge(&block)
|
35
|
+
MergeProp.new(&block)
|
36
|
+
end
|
16
37
|
|
17
|
-
|
18
|
-
|
38
|
+
def defer(group: nil, merge: nil, &block)
|
39
|
+
DeferProp.new(group: group, merge: merge, &block)
|
40
|
+
end
|
19
41
|
end
|
20
42
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module InertiaRails
|
4
|
+
class LazyProp < IgnoreOnFirstLoadProp
|
5
|
+
def initialize(value = nil, &block)
|
6
|
+
raise ArgumentError, 'You must provide either a value or a block, not both' if value && block
|
7
|
+
|
8
|
+
InertiaRails.deprecator.warn(
|
9
|
+
'`lazy` is deprecated and will be removed in InertiaRails 4.0, use `optional` instead.'
|
10
|
+
)
|
11
|
+
|
12
|
+
@value = value
|
13
|
+
@block = block
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(controller)
|
17
|
+
value.respond_to?(:call) ? controller.instance_exec(&value) : value
|
18
|
+
end
|
19
|
+
|
20
|
+
def value
|
21
|
+
@value.nil? ? @block : @value
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module InertiaRails
|
2
4
|
class Middleware
|
3
5
|
def initialize(app)
|
@@ -20,7 +22,10 @@ module InertiaRails
|
|
20
22
|
request = ActionDispatch::Request.new(@env)
|
21
23
|
|
22
24
|
# Inertia errors are added to the session via redirect_to
|
23
|
-
|
25
|
+
unless keep_inertia_session_options?(status)
|
26
|
+
request.session.delete(:inertia_errors)
|
27
|
+
request.session.delete(:inertia_clear_history)
|
28
|
+
end
|
24
29
|
|
25
30
|
status = 303 if inertia_non_post_redirect?(status)
|
26
31
|
|
@@ -29,7 +34,7 @@ module InertiaRails
|
|
29
34
|
|
30
35
|
private
|
31
36
|
|
32
|
-
def
|
37
|
+
def keep_inertia_session_options?(status)
|
33
38
|
redirect_status?(status) || stale_inertia_request?
|
34
39
|
end
|
35
40
|
|
@@ -1,18 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'net/http'
|
2
4
|
require 'json'
|
3
|
-
require_relative
|
5
|
+
require_relative 'inertia_rails'
|
4
6
|
|
5
7
|
module InertiaRails
|
6
8
|
class Renderer
|
9
|
+
KEEP_PROP = :keep
|
10
|
+
DONT_KEEP_PROP = :dont_keep
|
11
|
+
|
7
12
|
attr_reader(
|
8
13
|
:component,
|
9
14
|
:configuration,
|
10
15
|
:controller,
|
11
16
|
:props,
|
12
17
|
:view_data,
|
18
|
+
:encrypt_history,
|
19
|
+
:clear_history
|
13
20
|
)
|
14
21
|
|
15
|
-
def initialize(component, controller, request, response, render_method, props: nil, view_data: nil, deep_merge: nil)
|
22
|
+
def initialize(component, controller, request, response, render_method, props: nil, view_data: nil, deep_merge: nil, encrypt_history: nil, clear_history: nil)
|
16
23
|
@controller = controller
|
17
24
|
@configuration = controller.__send__(:inertia_configuration)
|
18
25
|
@component = resolve_component(component)
|
@@ -22,6 +29,8 @@ module InertiaRails
|
|
22
29
|
@props = props || controller.__send__(:inertia_view_assigns)
|
23
30
|
@view_data = view_data || {}
|
24
31
|
@deep_merge = !deep_merge.nil? ? deep_merge : configuration.deep_merge_shared_data
|
32
|
+
@encrypt_history = !encrypt_history.nil? ? encrypt_history : configuration.encrypt_history
|
33
|
+
@clear_history = clear_history || controller.session[:inertia_clear_history] || false
|
25
34
|
end
|
26
35
|
|
27
36
|
def render
|
@@ -64,47 +73,95 @@ module InertiaRails
|
|
64
73
|
# Functionally, this permits using either string or symbol keys in the controller. Since the results
|
65
74
|
# is cast to json, we should treat string/symbol keys as identical.
|
66
75
|
def merge_props(shared_data, props)
|
67
|
-
|
76
|
+
if @deep_merge
|
77
|
+
shared_data.deep_symbolize_keys.deep_merge!(props.deep_symbolize_keys)
|
78
|
+
else
|
79
|
+
shared_data.symbolize_keys.merge(props.symbolize_keys)
|
80
|
+
end
|
68
81
|
end
|
69
82
|
|
70
83
|
def computed_props
|
71
|
-
_props = merge_props(shared_data, props)
|
72
|
-
|
73
|
-
|
84
|
+
_props = merge_props(shared_data, props)
|
85
|
+
|
86
|
+
deep_transform_props _props do |prop, path|
|
87
|
+
next [DONT_KEEP_PROP] unless keep_prop?(prop, path)
|
88
|
+
|
89
|
+
transformed_prop = case prop
|
90
|
+
when BaseProp
|
91
|
+
prop.call(controller)
|
92
|
+
when Proc
|
93
|
+
controller.instance_exec(&prop)
|
74
94
|
else
|
75
|
-
|
95
|
+
prop
|
76
96
|
end
|
77
|
-
end
|
78
97
|
|
79
|
-
|
80
|
-
|
81
|
-
lambda do |prop|
|
82
|
-
prop.respond_to?(:call) ? controller.instance_exec(&prop) : prop
|
83
|
-
end
|
84
|
-
)
|
98
|
+
[KEEP_PROP, transformed_prop]
|
99
|
+
end
|
85
100
|
end
|
86
101
|
|
87
102
|
def page
|
88
|
-
{
|
103
|
+
default_page = {
|
89
104
|
component: component,
|
90
105
|
props: computed_props,
|
91
106
|
url: @request.original_fullpath,
|
92
107
|
version: configuration.version,
|
108
|
+
encryptHistory: encrypt_history,
|
109
|
+
clearHistory: clear_history,
|
93
110
|
}
|
111
|
+
|
112
|
+
deferred_props = deferred_props_keys
|
113
|
+
default_page[:deferredProps] = deferred_props if deferred_props.present?
|
114
|
+
|
115
|
+
merge_props = merge_props_keys
|
116
|
+
default_page[:mergeProps] = merge_props if merge_props.present?
|
117
|
+
|
118
|
+
default_page
|
119
|
+
end
|
120
|
+
|
121
|
+
def deep_transform_props(props, parent_path = [], &block)
|
122
|
+
props.reduce({}) do |transformed_props, (key, prop)|
|
123
|
+
current_path = parent_path + [key]
|
124
|
+
|
125
|
+
if prop.is_a?(Hash) && prop.any?
|
126
|
+
nested = deep_transform_props(prop, current_path, &block)
|
127
|
+
transformed_props.merge!(key => nested) unless nested.empty?
|
128
|
+
else
|
129
|
+
action, transformed_prop = block.call(prop, current_path)
|
130
|
+
transformed_props.merge!(key => transformed_prop) if action == KEEP_PROP
|
131
|
+
end
|
132
|
+
|
133
|
+
transformed_props
|
134
|
+
end
|
94
135
|
end
|
95
136
|
|
96
|
-
def
|
97
|
-
return
|
137
|
+
def deferred_props_keys
|
138
|
+
return if rendering_partial_component?
|
139
|
+
|
140
|
+
@props.each_with_object({}) do |(key, prop), result|
|
141
|
+
(result[prop.group] ||= []) << key if prop.is_a?(DeferProp)
|
142
|
+
end
|
143
|
+
end
|
98
144
|
|
99
|
-
|
145
|
+
def merge_props_keys
|
146
|
+
@props.each_with_object([]) do |(key, prop), result|
|
147
|
+
result << key if prop.try(:merge?) && reset_keys.exclude?(key)
|
148
|
+
end
|
100
149
|
end
|
101
150
|
|
102
151
|
def partial_keys
|
103
|
-
(@request.headers['X-Inertia-Partial-Data'] || '').split(',').compact
|
152
|
+
@partial_keys ||= (@request.headers['X-Inertia-Partial-Data'] || '').split(',').compact
|
153
|
+
end
|
154
|
+
|
155
|
+
def reset_keys
|
156
|
+
(@request.headers['X-Inertia-Reset'] || '').split(',').compact.map(&:to_sym)
|
157
|
+
end
|
158
|
+
|
159
|
+
def partial_except_keys
|
160
|
+
(@request.headers['X-Inertia-Partial-Except'] || '').split(',').compact
|
104
161
|
end
|
105
162
|
|
106
163
|
def rendering_partial_component?
|
107
|
-
@request.
|
164
|
+
@request.headers['X-Inertia-Partial-Component'] == component
|
108
165
|
end
|
109
166
|
|
110
167
|
def resolve_component(component)
|
@@ -112,5 +169,34 @@ module InertiaRails
|
|
112
169
|
|
113
170
|
configuration.component_path_resolver(path: controller.controller_path, action: controller.action_name)
|
114
171
|
end
|
172
|
+
|
173
|
+
def keep_prop?(prop, path)
|
174
|
+
return true if prop.is_a?(AlwaysProp)
|
175
|
+
|
176
|
+
if rendering_partial_component?
|
177
|
+
path_with_prefixes = path_prefixes(path)
|
178
|
+
return false if excluded_by_only_partial_keys?(path_with_prefixes)
|
179
|
+
return false if excluded_by_except_partial_keys?(path_with_prefixes)
|
180
|
+
end
|
181
|
+
|
182
|
+
# Precedence: Evaluate IgnoreOnFirstLoadProp only after partial keys have been checked
|
183
|
+
return false if prop.is_a?(IgnoreOnFirstLoadProp) && !rendering_partial_component?
|
184
|
+
|
185
|
+
true
|
186
|
+
end
|
187
|
+
|
188
|
+
def path_prefixes(parts)
|
189
|
+
(0...parts.length).map do |i|
|
190
|
+
parts[0..i].join('.')
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def excluded_by_only_partial_keys?(path_with_prefixes)
|
195
|
+
partial_keys.present? && (path_with_prefixes & partial_keys).empty?
|
196
|
+
end
|
197
|
+
|
198
|
+
def excluded_by_except_partial_keys?(path_with_prefixes)
|
199
|
+
partial_except_keys.present? && (path_with_prefixes & partial_except_keys).any?
|
200
|
+
end
|
115
201
|
end
|
116
202
|
end
|
data/lib/inertia_rails.rb
CHANGED
@@ -16,6 +16,8 @@ ActionController::Renderers.add :inertia do |component, options|
|
|
16
16
|
props: options[:props],
|
17
17
|
view_data: options[:view_data],
|
18
18
|
deep_merge: options[:deep_merge],
|
19
|
+
encrypt_history: options[:encrypt_history],
|
20
|
+
clear_history: options[:clear_history],
|
19
21
|
).render
|
20
22
|
end
|
21
23
|
|
@@ -4,14 +4,16 @@
|
|
4
4
|
# https://github.com/BetterErrors/better_errors/blob/v2.5.1/lib/better_errors/middleware.rb
|
5
5
|
#
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
return false if env["HTTP_X_INERTIA"]
|
7
|
+
module InertiaRails
|
8
|
+
module InertiaBetterErrors
|
9
|
+
def text?(env)
|
10
|
+
return false if env["HTTP_X_INERTIA"]
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
end)
|
12
|
+
super
|
13
|
+
end
|
16
14
|
end
|
17
15
|
end
|
16
|
+
|
17
|
+
if defined?(BetterErrors)
|
18
|
+
BetterErrors::Middleware.include InertiaRails::InertiaBetterErrors
|
19
|
+
end
|
@@ -4,8 +4,8 @@
|
|
4
4
|
# https://github.com/rails/rails/blob/5-0-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
|
5
5
|
#
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
module InertiaRails
|
8
|
+
module InertiaDebugExceptions
|
9
9
|
def render_for_default_application(request, wrapper)
|
10
10
|
template = create_template(request, wrapper)
|
11
11
|
file = "rescues/#{wrapper.rescue_template}"
|
@@ -19,5 +19,9 @@ ActionDispatch::DebugExceptions.class_eval do
|
|
19
19
|
end
|
20
20
|
render(wrapper.status_code, body, format)
|
21
21
|
end
|
22
|
-
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
if defined?(ActionDispatch::DebugExceptions)
|
26
|
+
ActionDispatch::DebugExceptions.prepend InertiaRails::InertiaDebugExceptions
|
23
27
|
end
|
@@ -6,8 +6,8 @@
|
|
6
6
|
# https://github.com/rails/rails/blob/6-0-stable/actionpack/lib/action_dispatch/middleware/debug_exceptions.rb
|
7
7
|
#
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
module InertiaRails
|
10
|
+
module InertiaDebugExceptions
|
11
11
|
def render_for_browser_request(request, wrapper)
|
12
12
|
template = create_template(request, wrapper)
|
13
13
|
file = "rescues/#{wrapper.rescue_template}"
|
@@ -22,5 +22,9 @@ ActionDispatch::DebugExceptions.class_eval do
|
|
22
22
|
|
23
23
|
render(wrapper.status_code, body, format)
|
24
24
|
end
|
25
|
-
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
if defined?(ActionDispatch::DebugExceptions)
|
29
|
+
ActionDispatch::DebugExceptions.prepend InertiaRails::InertiaDebugExceptions
|
26
30
|
end
|
data/lib/patches/mapper.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module InertiaRails
|
2
|
+
module InertiaMapper
|
3
|
+
def inertia(args, &block)
|
4
|
+
route = args.keys.first
|
5
|
+
component = args.values.first
|
5
6
|
|
6
|
-
|
7
|
+
get(route => 'inertia_rails/static#static', defaults: { component: component })
|
8
|
+
end
|
7
9
|
end
|
8
10
|
end
|
11
|
+
|
12
|
+
ActionDispatch::Routing::Mapper.include InertiaRails::InertiaMapper
|
data/lib/patches/request.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module InertiaRails
|
2
|
+
module InertiaRequest
|
3
|
+
def inertia?
|
4
|
+
key? 'HTTP_X_INERTIA'
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
def inertia_partial?
|
8
|
+
key?('HTTP_X_INERTIA_PARTIAL_COMPONENT')
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
12
|
+
|
13
|
+
ActionDispatch::Request.include InertiaRails::InertiaRequest
|