inertia_rails 3.6.0 → 3.7.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.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/LICENSE.txt +1 -1
  4. data/lib/generators/inertia/install/install_generator.rb +5 -8
  5. data/lib/generators/inertia/install/templates/react/InertiaExample.tsx +1 -1
  6. data/lib/generators/inertia/install/templates/react/inertia.ts +3 -3
  7. data/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte +1 -1
  8. data/lib/generators/inertia/install/templates/svelte/InertiaExample.ts.svelte +1 -1
  9. data/lib/generators/inertia/install/templates/svelte/inertia.js +3 -3
  10. data/lib/generators/inertia/install/templates/svelte/inertia.ts.tt +4 -4
  11. data/lib/generators/inertia/install/templates/svelte4/InertiaExample.svelte +1 -1
  12. data/lib/generators/inertia/install/templates/svelte4/InertiaExample.ts.svelte +1 -1
  13. data/lib/generators/inertia/install/templates/svelte4/inertia.js +3 -3
  14. data/lib/generators/inertia/install/templates/svelte4/inertia.ts.tt +4 -4
  15. data/lib/generators/inertia/install/templates/tailwind/application.css +3 -12
  16. data/lib/generators/inertia/install/templates/vue/InertiaExample.ts.vue +1 -1
  17. data/lib/generators/inertia/install/templates/vue/InertiaExample.vue +1 -1
  18. data/lib/generators/inertia/install/templates/vue/inertia.ts +3 -3
  19. data/lib/inertia_rails/configuration.rb +30 -14
  20. data/lib/inertia_rails/generators/helper.rb +9 -7
  21. data/lib/inertia_rails/renderer.rb +38 -28
  22. data/lib/inertia_rails/rspec.rb +5 -6
  23. data/lib/inertia_rails/version.rb +1 -1
  24. data/lib/inertia_rails.rb +3 -1
  25. data/lib/patches/mapper.rb +19 -4
  26. metadata +3 -8
  27. data/lib/generators/inertia/install/templates/tailwind/postcss.config.js +0 -6
  28. data/lib/generators/inertia/install/templates/tailwind/tailwind.config.js.tt +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1703f19fcb6d8f3d2c580e6e7bd80ff999cda8f55f72f7ea915001279577386c
4
- data.tar.gz: d5ff27be81328583e03aa7eb4473f1a4a966139993a3d856c54c0b6ae447b122
3
+ metadata.gz: 0f5f574a84809fccf65c7db0f58d34cb622b2ea4d403d05519736d2c44865f69
4
+ data.tar.gz: f62406133f1fa0698a8d2d24418a98f75e01d0400de356e879b86bbb4f657317
5
5
  SHA512:
6
- metadata.gz: 9cdd9eebf261e555bc09d237272852c4c59cf08618462f5deb5aaa314e09538e121a8c116e989c9c66632f38d2bcf14617d0d0f6ca9f5fe152e7b646a5a652f3
7
- data.tar.gz: 4fea8b1605262d6d80ccec45fe68368b9f62ae4cd96cca7768b58b0b65e5a690877216f6f10f7d4e93915cbba8003b4635b99ea4b3af3f2100bceda8c572cd73
6
+ metadata.gz: 691824db56620d1812c14db827f9dbffb2e6da89ba4c46f688ef8aa177afa8dc8db1e08a329559fc07e395d22adef18e30ead862e422a4a32001999767b3429f
7
+ data.tar.gz: e2331144a98cafd06a09e6019477265915638d328ac006868e3ea2922f513330af5241e28702d4aeb0b52a4e4cb077a77788954c924fcdcccde86bd18198f52d
data/CHANGELOG.md CHANGED
@@ -4,6 +4,22 @@ 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
+ ## [3.7.0] - 2025-03-17
8
+
9
+ * Docs updates
10
+ * Configuration via ENV variables (#196, @skryukov)
11
+ * Routing improvements for the inertia routes helper (#195, @skryukov)
12
+ * When automatically determining the component path, the component name can now be omitted, instead of requiring `render inertia: true` (#199, @skryukov)
13
+
14
+ ## [3.6.1] - 2025-02-04
15
+
16
+ * Install generator tweaks @skryukov
17
+ * Performance improvement for oj serialization users @alexspeller
18
+ * Doc updates @youyoumu
19
+ * Doc updates @pedroaugustoramalhoduarte
20
+ * Tailwind v4 support in install generators @arandilopez
21
+ * Various CI fixes @bknoles / @skryukov
22
+
7
23
  ## [3.6.0] - 2024-12-13
8
24
 
9
25
  Support for the v2.0 Inertia.js release! It's a minor bump because there are no breaking changes!
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2019 TODO: Bellawatt
3
+ Copyright (c) 2025 Bellawatt
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -78,8 +78,7 @@ module Inertia
78
78
  template 'initializer.rb', file_path('config/initializers/inertia_rails.rb')
79
79
 
80
80
  say 'Installing Inertia npm packages'
81
- add_dependencies(*FRAMEWORKS[framework]['packages'])
82
- add_dependencies(inertia_package)
81
+ add_dependencies(inertia_package, *FRAMEWORKS[framework]['packages'])
83
82
 
84
83
  unless File.read(vite_config_path).include?(FRAMEWORKS[framework]['vite_plugin_import'])
85
84
  say "Adding Vite plugin for #{framework}"
@@ -152,11 +151,9 @@ module Inertia
152
151
 
153
152
  def install_tailwind
154
153
  say 'Installing Tailwind CSS'
155
- add_dependencies(%w[tailwindcss postcss autoprefixer @tailwindcss/forms @tailwindcss/typography
156
- @tailwindcss/container-queries])
157
-
158
- template 'tailwind/tailwind.config.js', file_path('tailwind.config.js')
159
- copy_file 'tailwind/postcss.config.js', file_path('postcss.config.js')
154
+ add_dependencies(%w[tailwindcss @tailwindcss/vite @tailwindcss/forms @tailwindcss/typography])
155
+ prepend_file vite_config_path, "import tailwindcss from '@tailwindcss/vite'\n"
156
+ insert_into_file vite_config_path, "\n tailwindcss(),", after: 'plugins: ['
160
157
  copy_file 'tailwind/application.css', js_file_path('entrypoints/application.css')
161
158
 
162
159
  if application_layout.exist?
@@ -266,7 +263,7 @@ module Inertia
266
263
 
267
264
  def inertia_resolved_version
268
265
  @inertia_resolved_version ||= Gem::Version.new(
269
- `npm show @inertiajs/core@#{options[:inertia_version]} version`.strip
266
+ `npm show @inertiajs/core@#{options[:inertia_version]} version --json | tail -n2 | head -n1 | tr -d '", '`.strip
270
267
  )
271
268
  end
272
269
 
@@ -18,7 +18,7 @@ export default function InertiaExample({ name }: { name: string }) {
18
18
  <h1 className={cs.h1}>Hello {name}!</h1>
19
19
 
20
20
  <div>
21
- <a href="https://inertia-rails.netlify.app" target="_blank">
21
+ <a href="https://inertia-rails.dev" target="_blank">
22
22
  <img className={cs.logo} src={inertiaSvg} alt="Inertia logo" />
23
23
  </a>
24
24
  <a href="https://vite-ruby.netlify.app" target="_blank">
@@ -10,13 +10,13 @@ type ResolvedComponent = {
10
10
 
11
11
  createInertiaApp({
12
12
  // Set default page title
13
- // see https://inertia-rails.netlify.app/guide/title-and-meta
13
+ // see https://inertia-rails.dev/guide/title-and-meta
14
14
  //
15
15
  // title: title => title ? `${title} - App` : 'App',
16
16
 
17
17
  // Disable progress bar
18
18
  //
19
- // see https://inertia-rails.netlify.app/guide/progress-indicators
19
+ // see https://inertia-rails.dev/guide/progress-indicators
20
20
  // progress: false,
21
21
 
22
22
  resolve: (name) => {
@@ -30,7 +30,7 @@ createInertiaApp({
30
30
 
31
31
  // To use a default layout, import the Layout component
32
32
  // and use the following line.
33
- // see https://inertia-rails.netlify.app/guide/pages#default-layouts
33
+ // see https://inertia-rails.dev/guide/pages#default-layouts
34
34
  //
35
35
  // page.default.layout ||= (page) => createElement(Layout, null, page)
36
36
 
@@ -16,7 +16,7 @@
16
16
  <h1>Hello {name}!</h1>
17
17
 
18
18
  <div>
19
- <a href="https://inertia-rails.netlify.app" target="_blank">
19
+ <a href="https://inertia-rails.dev" target="_blank">
20
20
  <img class="logo" src={inertiaSvg} alt="Inertia logo" />
21
21
  </a>
22
22
  <a href="https://vite-ruby.netlify.app" target="_blank">
@@ -16,7 +16,7 @@
16
16
  <h1>Hello {name}!</h1>
17
17
 
18
18
  <div>
19
- <a href="https://inertia-rails.netlify.app" target="_blank">
19
+ <a href="https://inertia-rails.dev" target="_blank">
20
20
  <img class="logo" src={inertiaSvg} alt="Inertia logo" />
21
21
  </a>
22
22
  <a href="https://vite-ruby.netlify.app" target="_blank">
@@ -3,13 +3,13 @@ import { mount } from 'svelte';
3
3
 
4
4
  createInertiaApp({
5
5
  // Set default page title
6
- // see https://inertia-rails.netlify.app/guide/title-and-meta
6
+ // see https://inertia-rails.dev/guide/title-and-meta
7
7
  //
8
8
  // title: title => title ? `${title} - App` : 'App',
9
9
 
10
10
  // Disable progress bar
11
11
  //
12
- // see https://inertia-rails.netlify.app/guide/progress-indicators
12
+ // see https://inertia-rails.dev/guide/progress-indicators
13
13
  // progress: false,
14
14
 
15
15
  resolve: (name) => {
@@ -23,7 +23,7 @@ createInertiaApp({
23
23
 
24
24
  // To use a default layout, import the Layout component
25
25
  // and use the following line.
26
- // see https://inertia-rails.netlify.app/guide/pages#default-layouts
26
+ // see https://inertia-rails.dev/guide/pages#default-layouts
27
27
  //
28
28
  // return { default: page.default, layout: page.layout || Layout }
29
29
 
@@ -3,13 +3,13 @@ import { mount } from 'svelte'
3
3
 
4
4
  createInertiaApp({
5
5
  // Set default page title
6
- // see https://inertia-rails.netlify.app/guide/title-and-meta
6
+ // see https://inertia-rails.dev/guide/title-and-meta
7
7
  //
8
8
  // title: title => title ? `${title} - App` : 'App',
9
9
 
10
10
  // Disable progress bar
11
11
  //
12
- // see https://inertia-rails.netlify.app/guide/progress-indicators
12
+ // see https://inertia-rails.dev/guide/progress-indicators
13
13
  // progress: false,
14
14
 
15
15
  resolve: (name) => {
@@ -23,7 +23,7 @@ createInertiaApp({
23
23
 
24
24
  // To use a default layout, import the Layout component
25
25
  // and use the following line.
26
- // see https://inertia-rails.netlify.app/guide/pages#default-layouts
26
+ // see https://inertia-rails.dev/guide/pages#default-layouts
27
27
  //
28
28
  // return { default: page.default, layout: page.layout || Layout }
29
29
 
@@ -32,7 +32,7 @@ createInertiaApp({
32
32
 
33
33
  setup({ el, App, props }) {
34
34
  if (el) {
35
- <%= " // @ts-expect-error 1.3.0 beta contains types mismatch\n" if inertia_resolved_version == Gem::Version.new('1.3.0-beta.2') -%>
35
+ <%= " // @ts-expect-error 1.3.0 contains types mismatch\n" if inertia_resolved_version.release == Gem::Version.new('1.3.0') -%>
36
36
  mount(App, { target: el, props })
37
37
  } else {
38
38
  console.error(
@@ -20,7 +20,7 @@
20
20
  <h1>Hello {name}!</h1>
21
21
 
22
22
  <div>
23
- <a href="https://inertia-rails.netlify.app" target="_blank">
23
+ <a href="https://inertia-rails.dev/" target="_blank">
24
24
  <img class="logo" src={inertiaSvg} alt="Inertia logo" />
25
25
  </a>
26
26
  <a href="https://vite-ruby.netlify.app" target="_blank">
@@ -20,7 +20,7 @@
20
20
  <h1>Hello {name}!</h1>
21
21
 
22
22
  <div>
23
- <a href="https://inertia-rails.netlify.app" target="_blank">
23
+ <a href="https://inertia-rails.dev" target="_blank">
24
24
  <img class="logo" src={inertiaSvg} alt="Inertia logo" />
25
25
  </a>
26
26
  <a href="https://vite-ruby.netlify.app" target="_blank">
@@ -2,13 +2,13 @@ import { createInertiaApp } from '@inertiajs/svelte'
2
2
 
3
3
  createInertiaApp({
4
4
  // Set default page title
5
- // see https://inertia-rails.netlify.app/guide/title-and-meta
5
+ // see https://inertia-rails.dev/guide/title-and-meta
6
6
  //
7
7
  // title: title => title ? `${title} - App` : 'App',
8
8
 
9
9
  // Disable progress bar
10
10
  //
11
- // see https://inertia-rails.netlify.app/guide/progress-indicators
11
+ // see https://inertia-rails.dev/guide/progress-indicators
12
12
  // progress: false,
13
13
 
14
14
  resolve: (name) => {
@@ -22,7 +22,7 @@ createInertiaApp({
22
22
 
23
23
  // To use a default layout, import the Layout component
24
24
  // and use the following lines.
25
- // see https://inertia-rails.netlify.app/guide/pages#default-layouts
25
+ // see https://inertia-rails.dev/guide/pages#default-layouts
26
26
  //
27
27
  // return { default: page.default, layout: page.layout || Layout }
28
28
 
@@ -2,13 +2,13 @@ import { createInertiaApp, type ResolvedComponent } from '@inertiajs/svelte'
2
2
 
3
3
  createInertiaApp({
4
4
  // Set default page title
5
- // see https://inertia-rails.netlify.app/guide/title-and-meta
5
+ // see https://inertia-rails.dev/guide/title-and-meta
6
6
  //
7
7
  // title: title => title ? `${title} - App` : 'App',
8
8
 
9
9
  // Disable progress bar
10
10
  //
11
- // see https://inertia-rails.netlify.app/guide/progress-indicators
11
+ // see https://inertia-rails.dev/guide/progress-indicators
12
12
  // progress: false,
13
13
 
14
14
  resolve: (name) => {
@@ -22,7 +22,7 @@ createInertiaApp({
22
22
 
23
23
  // To use a default layout, import the Layout component
24
24
  // and use the following line.
25
- // see https://inertia-rails.netlify.app/guide/pages#default-layouts
25
+ // see https://inertia-rails.dev/guide/pages#default-layouts
26
26
  //
27
27
  // return { default: page.default, layout: page.layout || Layout }
28
28
 
@@ -31,7 +31,7 @@ createInertiaApp({
31
31
 
32
32
  setup({ el, App, props }) {
33
33
  if (el) {
34
- <%= "// @ts-expect-error 1.3.0 beta contains types mismatch\n" if inertia_resolved_version == Gem::Version.new('1.3.0-beta.2') -%>
34
+ <%= "// @ts-expect-error 1.3.0 beta contains types mismatch\n" if inertia_resolved_version.release == Gem::Version.new('1.3.0') -%>
35
35
  new App({ target: el, props })
36
36
  } else {
37
37
  console.error(
@@ -1,13 +1,4 @@
1
- @tailwind base;
2
- @tailwind components;
3
- @tailwind utilities;
1
+ @import "tailwindcss";
4
2
 
5
- /*
6
-
7
- @layer components {
8
- .btn-primary {
9
- @apply py-2 px-4 bg-blue-200;
10
- }
11
- }
12
-
13
- */
3
+ @plugin "@tailwindcss/typography";
4
+ @plugin "@tailwindcss/forms";
@@ -5,7 +5,7 @@
5
5
  <h1 class="h1">Hello {{ name }}!</h1>
6
6
 
7
7
  <div>
8
- <a href="https://inertia-rails.netlify.app" target="_blank">
8
+ <a href="https://inertia-rails.dev" target="_blank">
9
9
  <img class="logo" :src="inertiaSvg" alt="Inertia logo" />
10
10
  </a>
11
11
  <a href="https://vite-ruby.netlify.app" target="_blank">
@@ -5,7 +5,7 @@
5
5
  <h1 class="h1">Hello {{ name }}!</h1>
6
6
 
7
7
  <div>
8
- <a href="https://inertia-rails.netlify.app" target="_blank">
8
+ <a href="https://inertia-rails.dev" target="_blank">
9
9
  <img class="logo" :src="inertiaSvg" alt="Inertia logo" />
10
10
  </a>
11
11
  <a href="https://vite-ruby.netlify.app" target="_blank">
@@ -3,13 +3,13 @@ import { createApp, DefineComponent, h } from 'vue'
3
3
 
4
4
  createInertiaApp({
5
5
  // Set default page title
6
- // see https://inertia-rails.netlify.app/guide/title-and-meta
6
+ // see https://inertia-rails.dev/guide/title-and-meta
7
7
  //
8
8
  // title: title => title ? `${title} - App` : 'App',
9
9
 
10
10
  // Disable progress bar
11
11
  //
12
- // see https://inertia-rails.netlify.app/guide/progress-indicators
12
+ // see https://inertia-rails.dev/guide/progress-indicators
13
13
  // progress: false,
14
14
 
15
15
  resolve: (name) => {
@@ -20,7 +20,7 @@ createInertiaApp({
20
20
 
21
21
  // To use a default layout, import the Layout component
22
22
  // and use the following lines.
23
- // see https://inertia-rails.netlify.app/guide/pages#default-layouts
23
+ // see https://inertia-rails.dev/guide/pages#default-layouts
24
24
  //
25
25
  // const page = pages[`../pages/${name}.vue`]
26
26
  // page.default.layout = page.default.layout || Layout
@@ -29,6 +29,23 @@ module InertiaRails
29
29
 
30
30
  OPTION_NAMES = DEFAULTS.keys.freeze
31
31
 
32
+ class << self
33
+ def default
34
+ new(**DEFAULTS, **env_options)
35
+ end
36
+
37
+ private
38
+
39
+ def env_options
40
+ DEFAULTS.keys.each_with_object({}) do |key, hash|
41
+ value = ENV.fetch("INERTIA_#{key.to_s.upcase}", nil)
42
+ next if value.nil?
43
+
44
+ hash[key] = %w[true false].include?(value) ? value == 'true' : value
45
+ end
46
+ end
47
+ end
48
+
32
49
  protected attr_reader :controller
33
50
  protected attr_reader :options
34
51
 
@@ -36,9 +53,9 @@ module InertiaRails
36
53
  @controller = controller
37
54
  @options = attrs.extract!(*OPTION_NAMES)
38
55
 
39
- unless attrs.empty?
40
- raise ArgumentError, "Unknown options for #{self.class}: #{attrs.keys}"
41
- end
56
+ return if attrs.empty?
57
+
58
+ raise ArgumentError, "Unknown options for #{self.class}: #{attrs.keys}"
42
59
  end
43
60
 
44
61
  def bind_controller(controller)
@@ -56,7 +73,7 @@ module InertiaRails
56
73
  end
57
74
 
58
75
  def merge(config)
59
- Configuration.new(**@options.merge(config.options))
76
+ Configuration.new(**@options, **config.options)
60
77
  end
61
78
 
62
79
  # Internal: Finalizes the configuration for a specific controller.
@@ -70,23 +87,22 @@ module InertiaRails
70
87
  end
71
88
 
72
89
  OPTION_NAMES.each do |option|
73
- define_method(option) {
74
- evaluate_option @options[option]
75
- } unless method_defined?(option)
76
- define_method("#{option}=") { |value|
90
+ unless method_defined?(option)
91
+ define_method(option) do
92
+ evaluate_option options[option]
93
+ end
94
+ end
95
+ define_method("#{option}=") do |value|
77
96
  @options[option] = value
78
- }
79
- end
80
-
81
- def self.default
82
- new(**DEFAULTS)
97
+ end
83
98
  end
84
99
 
85
- private
100
+ private
86
101
 
87
102
  def evaluate_option(value)
88
103
  return value unless value.respond_to?(:call)
89
104
  return value.call unless controller
105
+
90
106
  controller.instance_exec(&value)
91
107
  end
92
108
  end
@@ -4,14 +4,16 @@ module InertiaRails
4
4
  module Generators
5
5
  module Helper
6
6
  class << self
7
- def guess_the_default_framework
8
- package = Rails.root.join('package.json').read
9
- case package
10
- when %r{@inertiajs/react}
7
+ def guess_the_default_framework(package_json_path = Rails.root.join('package.json'))
8
+ package_json = JSON.parse(package_json_path.read)
9
+ dependencies = package_json['dependencies'] || {}
10
+
11
+ if dependencies['@inertiajs/react']
11
12
  'react'
12
- when %r{@inertiajs/svelte}
13
- package.match?(/"svelte": "\^5/) ? 'svelte' : 'svelte4'
14
- when %r{@inertiajs/vue3}
13
+ elsif dependencies['@inertiajs/svelte']
14
+ version = dependencies['svelte'].gsub(/[\^~]/, '') # Remove ^ or ~ from version
15
+ version.start_with?('5') ? 'svelte' : 'svelte4'
16
+ elsif dependencies['@inertiajs/vue3']
15
17
  'vue'
16
18
  else
17
19
  Thor::Shell::Basic.new.say_error 'Could not determine the Inertia.js framework you are using.'
@@ -19,31 +19,41 @@ module InertiaRails
19
19
  :clear_history
20
20
  )
21
21
 
22
- def initialize(component, controller, request, response, render_method, props: nil, view_data: nil, deep_merge: nil, encrypt_history: nil, clear_history: nil)
22
+ def initialize(component, controller, request, response, render_method, props: nil, view_data: nil,
23
+ deep_merge: nil, encrypt_history: nil, clear_history: nil)
24
+ if component.is_a?(Hash) && !props.nil?
25
+ raise ArgumentError,
26
+ 'Parameter `props` is not allowed when passing a Hash as the first argument'
27
+ end
28
+
23
29
  @controller = controller
24
30
  @configuration = controller.__send__(:inertia_configuration)
25
31
  @component = resolve_component(component)
26
32
  @request = request
27
33
  @response = response
28
34
  @render_method = render_method
29
- @props = props || controller.__send__(:inertia_view_assigns)
35
+ @props = props || (component.is_a?(Hash) ? component : controller.__send__(:inertia_view_assigns))
30
36
  @view_data = view_data || {}
31
- @deep_merge = !deep_merge.nil? ? deep_merge : configuration.deep_merge_shared_data
32
- @encrypt_history = !encrypt_history.nil? ? encrypt_history : configuration.encrypt_history
37
+ @deep_merge = deep_merge.nil? ? configuration.deep_merge_shared_data : deep_merge
38
+ @encrypt_history = encrypt_history.nil? ? configuration.encrypt_history : encrypt_history
33
39
  @clear_history = clear_history || controller.session[:inertia_clear_history] || false
34
40
  end
35
41
 
36
42
  def render
37
- if @response.headers["Vary"].blank?
38
- @response.headers["Vary"] = 'X-Inertia'
39
- else
40
- @response.headers["Vary"] = "#{@response.headers["Vary"]}, X-Inertia"
41
- end
43
+ @response.headers['Vary'] = if @response.headers['Vary'].blank?
44
+ 'X-Inertia'
45
+ else
46
+ "#{@response.headers['Vary']}, X-Inertia"
47
+ end
42
48
  if @request.headers['X-Inertia']
43
49
  @response.set_header('X-Inertia', 'true')
44
- @render_method.call json: page, status: @response.status, content_type: Mime[:json]
50
+ @render_method.call json: page.to_json, status: @response.status, content_type: Mime[:json]
45
51
  else
46
- return render_ssr if configuration.ssr_enabled rescue nil
52
+ begin
53
+ return render_ssr if configuration.ssr_enabled
54
+ rescue StandardError
55
+ nil
56
+ end
47
57
  @render_method.call template: 'inertia', layout: layout, locals: view_data.merge(page: page)
48
58
  end
49
59
  end
@@ -54,13 +64,13 @@ module InertiaRails
54
64
  uri = URI("#{configuration.ssr_url}/render")
55
65
  res = JSON.parse(Net::HTTP.post(uri, page.to_json, 'Content-Type' => 'application/json').body)
56
66
 
57
- controller.instance_variable_set("@_inertia_ssr_head", res['head'].join.html_safe)
67
+ controller.instance_variable_set('@_inertia_ssr_head', res['head'].join.html_safe)
58
68
  @render_method.call html: res['body'].html_safe, layout: layout, locals: view_data.merge(page: page)
59
69
  end
60
70
 
61
71
  def layout
62
72
  layout = configuration.layout
63
- layout.nil? ? true : layout
73
+ layout.nil? || layout
64
74
  end
65
75
 
66
76
  def shared_data
@@ -81,19 +91,19 @@ module InertiaRails
81
91
  end
82
92
 
83
93
  def computed_props
84
- _props = merge_props(shared_data, props)
94
+ merged_props = merge_props(shared_data, props)
85
95
 
86
- deep_transform_props _props do |prop, path|
96
+ deep_transform_props merged_props do |prop, path|
87
97
  next [DONT_KEEP_PROP] unless keep_prop?(prop, path)
88
98
 
89
99
  transformed_prop = case prop
90
- when BaseProp
91
- prop.call(controller)
92
- when Proc
93
- controller.instance_exec(&prop)
94
- else
95
- prop
96
- end
100
+ when BaseProp
101
+ prop.call(controller)
102
+ when Proc
103
+ controller.instance_exec(&prop)
104
+ else
105
+ prop
106
+ end
97
107
 
98
108
  [KEEP_PROP, transformed_prop]
99
109
  end
@@ -119,7 +129,7 @@ module InertiaRails
119
129
  end
120
130
 
121
131
  def deep_transform_props(props, parent_path = [], &block)
122
- props.reduce({}) do |transformed_props, (key, prop)|
132
+ props.each_with_object({}) do |(key, prop), transformed_props|
123
133
  current_path = parent_path + [key]
124
134
 
125
135
  if prop.is_a?(Hash) && prop.any?
@@ -129,8 +139,6 @@ module InertiaRails
129
139
  action, transformed_prop = block.call(prop, current_path)
130
140
  transformed_props.merge!(key => transformed_prop) if action == KEEP_PROP
131
141
  end
132
-
133
- transformed_props
134
142
  end
135
143
  end
136
144
 
@@ -165,9 +173,11 @@ module InertiaRails
165
173
  end
166
174
 
167
175
  def resolve_component(component)
168
- return component unless component.is_a? TrueClass
169
-
170
- configuration.component_path_resolver(path: controller.controller_path, action: controller.action_name)
176
+ if component == true || component.is_a?(Hash)
177
+ configuration.component_path_resolver(path: controller.controller_path, action: controller.action_name)
178
+ else
179
+ component
180
+ end
171
181
  end
172
182
 
173
183
  def keep_prop?(prop, path)
@@ -32,8 +32,9 @@ module InertiaRails
32
32
  else
33
33
  # Sequential Inertia request
34
34
  @view_data = {}
35
- @props = params[:json][:props]
36
- @component = params[:json][:component]
35
+ json = JSON.parse(params[:json])
36
+ @props = json["props"]
37
+ @component = json["component"]
37
38
  end
38
39
  end
39
40
  end
@@ -81,8 +82,7 @@ end
81
82
 
82
83
  RSpec::Matchers.define :have_exact_props do |expected_props|
83
84
  match do |inertia|
84
- # Computed props have symbolized keys.
85
- expect(inertia.props).to eq expected_props.deep_symbolize_keys
85
+ expect(inertia.props).to eq expected_props
86
86
  end
87
87
 
88
88
  failure_message do |inertia|
@@ -92,8 +92,7 @@ end
92
92
 
93
93
  RSpec::Matchers.define :include_props do |expected_props|
94
94
  match do |inertia|
95
- # Computed props have symbolized keys.
96
- expect(inertia.props).to include expected_props.deep_symbolize_keys
95
+ expect(inertia.props).to include expected_props
97
96
  end
98
97
 
99
98
  failure_message do |inertia|
@@ -1,3 +1,3 @@
1
1
  module InertiaRails
2
- VERSION = "3.6.0"
2
+ VERSION = "3.7.0"
3
3
  end
data/lib/inertia_rails.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'inertia_rails/renderer'
2
4
  require 'inertia_rails/engine'
3
5
 
@@ -17,7 +19,7 @@ ActionController::Renderers.add :inertia do |component, options|
17
19
  view_data: options[:view_data],
18
20
  deep_merge: options[:deep_merge],
19
21
  encrypt_history: options[:encrypt_history],
20
- clear_history: options[:clear_history],
22
+ clear_history: options[:clear_history]
21
23
  ).render
22
24
  end
23
25
 
@@ -1,10 +1,25 @@
1
1
  module InertiaRails
2
2
  module InertiaMapper
3
- def inertia(args, &block)
4
- route = args.keys.first
5
- component = args.values.first
3
+ def inertia(*args, **options)
4
+ path = args.any? ? args.first : options
5
+ route, component = extract_route_and_component(path)
6
+ scope module: nil do
7
+ get(route, to: 'inertia_rails/static#static', defaults: { component: component }, **options)
8
+ end
9
+ end
10
+
11
+ private
6
12
 
7
- get(route => 'inertia_rails/static#static', defaults: { component: component })
13
+ def extract_route_and_component(path)
14
+ if path.is_a?(Hash)
15
+ path.first
16
+ elsif resource_scope?
17
+ [path, InertiaRails.configuration.component_path_resolver(path: [@scope[:module], @scope[:controller]].compact.join('/'), action: path)]
18
+ elsif @scope[:module].blank?
19
+ [path, path]
20
+ else
21
+ [path, InertiaRails.configuration.component_path_resolver(path: @scope[:module], action: path)]
22
+ end
8
23
  end
9
24
  end
10
25
  end
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inertia_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 3.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Knoles
8
8
  - Brandon Shar
9
9
  - Eugene Granovsky
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2024-12-13 00:00:00.000000000 Z
12
+ date: 2025-03-18 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: railties
@@ -81,8 +80,6 @@ files:
81
80
  - lib/generators/inertia/install/templates/svelte4/tsconfig.node.json
82
81
  - lib/generators/inertia/install/templates/svelte4/vite-env.d.ts
83
82
  - lib/generators/inertia/install/templates/tailwind/application.css
84
- - lib/generators/inertia/install/templates/tailwind/postcss.config.js
85
- - lib/generators/inertia/install/templates/tailwind/tailwind.config.js.tt
86
83
  - lib/generators/inertia/install/templates/vue/InertiaExample.ts.vue
87
84
  - lib/generators/inertia/install/templates/vue/InertiaExample.vue
88
85
  - lib/generators/inertia/install/templates/vue/inertia.js
@@ -250,7 +247,6 @@ metadata:
250
247
  homepage_uri: https://github.com/inertiajs/inertia-rails
251
248
  source_code_uri: https://github.com/inertiajs/inertia-rails
252
249
  rubygems_mfa_required: 'true'
253
- post_install_message:
254
250
  rdoc_options: []
255
251
  require_paths:
256
252
  - lib
@@ -265,8 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
265
261
  - !ruby/object:Gem::Version
266
262
  version: '0'
267
263
  requirements: []
268
- rubygems_version: 3.5.22
269
- signing_key:
264
+ rubygems_version: 3.6.2
270
265
  specification_version: 4
271
266
  summary: Inertia.js adapter for Rails
272
267
  test_files: []
@@ -1,6 +0,0 @@
1
- export default {
2
- plugins: {
3
- tailwindcss: {},
4
- autoprefixer: {},
5
- },
6
- }
@@ -1,18 +0,0 @@
1
- /** @type {import('tailwindcss').Config} */
2
-
3
- module.exports = {
4
- content: [
5
- './public/*.html',
6
- './app/helpers/**/*.rb',
7
- './<%= js_destination_path %>/**/*.{js,ts,jsx,tsx,vue,svelte}',
8
- './app/views/**/*.{erb,haml,html,slim}'
9
- ],
10
- theme: {
11
- extend: {},
12
- },
13
- plugins: [
14
- require('@tailwindcss/forms'),
15
- require('@tailwindcss/typography'),
16
- require('@tailwindcss/container-queries'),
17
- ]
18
- }