inertia_rails 3.3.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/README.md +6 -7
  4. data/lib/generators/inertia/controller/controller_generator.rb +18 -0
  5. data/lib/generators/inertia/controller/templates/controller.rb.tt +10 -0
  6. data/lib/generators/inertia/install/frameworks.yml +98 -0
  7. data/lib/generators/inertia/install/helpers.rb +51 -0
  8. data/lib/generators/inertia/install/install_generator.rb +291 -0
  9. data/lib/generators/inertia/install/js_package_manager.rb +50 -0
  10. data/lib/generators/inertia/install/templates/assets/inertia.svg +1 -0
  11. data/lib/generators/inertia/install/templates/assets/react.svg +1 -0
  12. data/lib/generators/inertia/install/templates/assets/svelte.svg +1 -0
  13. data/lib/generators/inertia/install/templates/assets/vite_ruby.svg +1 -0
  14. data/lib/generators/inertia/install/templates/assets/vue.svg +1 -0
  15. data/lib/generators/{inertia_rails/install → inertia/install/templates}/controller.rb +3 -1
  16. data/lib/generators/inertia/install/templates/dev +23 -0
  17. data/lib/generators/inertia/install/templates/initializer.rb +6 -0
  18. data/lib/generators/inertia/install/templates/react/InertiaExample.jsx +60 -0
  19. data/lib/generators/inertia/install/templates/react/InertiaExample.module.css +80 -0
  20. data/lib/generators/inertia/install/templates/react/InertiaExample.tsx +60 -0
  21. data/lib/generators/inertia/install/templates/react/inertia.js +45 -0
  22. data/lib/generators/inertia/install/templates/react/inertia.ts +51 -0
  23. data/lib/generators/inertia/install/templates/react/tsconfig.app.json +27 -0
  24. data/lib/generators/inertia/install/templates/react/tsconfig.json +11 -0
  25. data/lib/generators/inertia/install/templates/react/tsconfig.node.json +13 -0
  26. data/lib/generators/inertia/install/templates/react/vite-env.d.ts +1 -0
  27. data/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte +112 -0
  28. data/lib/generators/inertia/install/templates/svelte/InertiaExample.ts.svelte +112 -0
  29. data/lib/generators/inertia/install/templates/svelte/inertia.js +44 -0
  30. data/lib/generators/inertia/install/templates/svelte/inertia.ts.tt +45 -0
  31. data/lib/generators/inertia/install/templates/svelte/svelte.config.js +7 -0
  32. data/lib/generators/inertia/install/templates/svelte/tsconfig.json +21 -0
  33. data/lib/generators/inertia/install/templates/svelte/tsconfig.node.json +12 -0
  34. data/lib/generators/inertia/install/templates/svelte/vite-env.d.ts +2 -0
  35. data/lib/generators/inertia/install/templates/svelte4/InertiaExample.svelte +116 -0
  36. data/lib/generators/inertia/install/templates/svelte4/InertiaExample.ts.svelte +116 -0
  37. data/lib/generators/inertia/install/templates/svelte4/inertia.js +43 -0
  38. data/lib/generators/inertia/install/templates/svelte4/inertia.ts.tt +44 -0
  39. data/lib/generators/inertia/install/templates/svelte4/svelte.config.js +7 -0
  40. data/lib/generators/inertia/install/templates/svelte4/tsconfig.json +21 -0
  41. data/lib/generators/inertia/install/templates/svelte4/tsconfig.node.json +12 -0
  42. data/lib/generators/inertia/install/templates/svelte4/vite-env.d.ts +2 -0
  43. data/lib/generators/inertia/install/templates/tailwind/application.css +13 -0
  44. data/lib/generators/inertia/install/templates/tailwind/postcss.config.js +6 -0
  45. data/lib/generators/inertia/install/templates/tailwind/tailwind.config.js.tt +18 -0
  46. data/lib/generators/inertia/install/templates/vue/InertiaExample.ts.vue +117 -0
  47. data/lib/generators/inertia/install/templates/vue/InertiaExample.vue +117 -0
  48. data/lib/generators/inertia/install/templates/vue/inertia.js +35 -0
  49. data/lib/generators/inertia/install/templates/vue/inertia.ts +35 -0
  50. data/lib/generators/inertia/install/templates/vue/tsconfig.app.json +24 -0
  51. data/lib/generators/inertia/install/templates/vue/tsconfig.json +11 -0
  52. data/lib/generators/inertia/install/templates/vue/tsconfig.node.json +22 -0
  53. data/lib/generators/inertia/install/templates/vue/vite-env.d.ts +1 -0
  54. data/lib/generators/inertia/scaffold/scaffold_generator.rb +16 -0
  55. data/lib/generators/inertia/scaffold_controller/scaffold_controller_generator.rb +60 -0
  56. data/lib/generators/inertia/scaffold_controller/templates/controller.rb.tt +100 -0
  57. data/lib/generators/inertia_templates/controller/controller_generator.rb +12 -0
  58. data/lib/generators/inertia_templates/controller/templates/react/view.jsx.tt +8 -0
  59. data/lib/generators/inertia_templates/controller/templates/react/view.tsx.tt +8 -0
  60. data/lib/generators/inertia_templates/controller/templates/svelte/view.svelte.tt +2 -0
  61. data/lib/generators/inertia_templates/controller/templates/svelte4/view.svelte.tt +2 -0
  62. data/lib/generators/inertia_templates/controller/templates/vue/view.vue.tt +4 -0
  63. data/lib/generators/inertia_templates/scaffold/scaffold_generator.rb +12 -0
  64. data/lib/generators/inertia_templates/scaffold/templates/react/Edit.jsx.tt +35 -0
  65. data/lib/generators/inertia_templates/scaffold/templates/react/Edit.tsx.tt +40 -0
  66. data/lib/generators/inertia_templates/scaffold/templates/react/Form.jsx.tt +111 -0
  67. data/lib/generators/inertia_templates/scaffold/templates/react/Form.tsx.tt +130 -0
  68. data/lib/generators/inertia_templates/scaffold/templates/react/Index.jsx.tt +26 -0
  69. data/lib/generators/inertia_templates/scaffold/templates/react/Index.tsx.tt +32 -0
  70. data/lib/generators/inertia_templates/scaffold/templates/react/New.jsx.tt +27 -0
  71. data/lib/generators/inertia_templates/scaffold/templates/react/New.tsx.tt +32 -0
  72. data/lib/generators/inertia_templates/scaffold/templates/react/One.jsx.tt +26 -0
  73. data/lib/generators/inertia_templates/scaffold/templates/react/One.tsx.tt +32 -0
  74. data/lib/generators/inertia_templates/scaffold/templates/react/Show.jsx.tt +32 -0
  75. data/lib/generators/inertia_templates/scaffold/templates/react/Show.tsx.tt +38 -0
  76. data/lib/generators/inertia_templates/scaffold/templates/react/types.ts.tt +19 -0
  77. data/lib/generators/inertia_templates/scaffold/templates/svelte/Edit.svelte.tt +36 -0
  78. data/lib/generators/inertia_templates/scaffold/templates/svelte/Edit.ts.svelte.tt +37 -0
  79. data/lib/generators/inertia_templates/scaffold/templates/svelte/Form.svelte.tt +97 -0
  80. data/lib/generators/inertia_templates/scaffold/templates/svelte/Form.ts.svelte.tt +102 -0
  81. data/lib/generators/inertia_templates/scaffold/templates/svelte/Index.svelte.tt +35 -0
  82. data/lib/generators/inertia_templates/scaffold/templates/svelte/Index.ts.svelte.tt +39 -0
  83. data/lib/generators/inertia_templates/scaffold/templates/svelte/New.svelte.tt +29 -0
  84. data/lib/generators/inertia_templates/scaffold/templates/svelte/New.ts.svelte.tt +30 -0
  85. data/lib/generators/inertia_templates/scaffold/templates/svelte/One.svelte.tt +28 -0
  86. data/lib/generators/inertia_templates/scaffold/templates/svelte/One.ts.svelte.tt +30 -0
  87. data/lib/generators/inertia_templates/scaffold/templates/svelte/Show.svelte.tt +35 -0
  88. data/lib/generators/inertia_templates/scaffold/templates/svelte/Show.ts.svelte.tt +39 -0
  89. data/lib/generators/inertia_templates/scaffold/templates/svelte/types.ts.tt +19 -0
  90. data/lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.svelte.tt +37 -0
  91. data/lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.ts.svelte.tt +38 -0
  92. data/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.svelte.tt +96 -0
  93. data/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.ts.svelte.tt +106 -0
  94. data/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.svelte.tt +36 -0
  95. data/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.ts.svelte.tt +37 -0
  96. data/lib/generators/inertia_templates/scaffold/templates/svelte4/New.svelte.tt +30 -0
  97. data/lib/generators/inertia_templates/scaffold/templates/svelte4/New.ts.svelte.tt +31 -0
  98. data/lib/generators/inertia_templates/scaffold/templates/svelte4/One.svelte.tt +28 -0
  99. data/lib/generators/inertia_templates/scaffold/templates/svelte4/One.ts.svelte.tt +30 -0
  100. data/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.svelte.tt +39 -0
  101. data/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.ts.svelte.tt +40 -0
  102. data/lib/generators/inertia_templates/scaffold/templates/svelte4/types.ts.tt +19 -0
  103. data/lib/generators/inertia_templates/scaffold/templates/vue/Edit.ts.vue.tt +37 -0
  104. data/lib/generators/inertia_templates/scaffold/templates/vue/Edit.vue.tt +36 -0
  105. data/lib/generators/inertia_templates/scaffold/templates/vue/Form.ts.vue.tt +101 -0
  106. data/lib/generators/inertia_templates/scaffold/templates/vue/Form.vue.tt +94 -0
  107. data/lib/generators/inertia_templates/scaffold/templates/vue/Index.ts.vue.tt +35 -0
  108. data/lib/generators/inertia_templates/scaffold/templates/vue/Index.vue.tt +31 -0
  109. data/lib/generators/inertia_templates/scaffold/templates/vue/New.ts.vue.tt +30 -0
  110. data/lib/generators/inertia_templates/scaffold/templates/vue/New.vue.tt +29 -0
  111. data/lib/generators/inertia_templates/scaffold/templates/vue/One.ts.vue.tt +28 -0
  112. data/lib/generators/inertia_templates/scaffold/templates/vue/One.vue.tt +26 -0
  113. data/lib/generators/inertia_templates/scaffold/templates/vue/Show.ts.vue.tt +41 -0
  114. data/lib/generators/inertia_templates/scaffold/templates/vue/Show.vue.tt +37 -0
  115. data/lib/generators/inertia_templates/scaffold/templates/vue/types.ts.tt +19 -0
  116. data/lib/generators/inertia_tw_templates/controller/controller_generator.rb +12 -0
  117. data/lib/generators/inertia_tw_templates/controller/templates/react/view.jsx.tt +8 -0
  118. data/lib/generators/inertia_tw_templates/controller/templates/react/view.tsx.tt +8 -0
  119. data/lib/generators/inertia_tw_templates/controller/templates/svelte/view.svelte.tt +2 -0
  120. data/lib/generators/inertia_tw_templates/controller/templates/svelte4/view.svelte.tt +2 -0
  121. data/lib/generators/inertia_tw_templates/controller/templates/vue/view.vue.tt +4 -0
  122. data/lib/generators/inertia_tw_templates/scaffold/scaffold_generator.rb +12 -0
  123. data/lib/generators/inertia_tw_templates/scaffold/templates/react/Edit.jsx.tt +42 -0
  124. data/lib/generators/inertia_tw_templates/scaffold/templates/react/Edit.tsx.tt +47 -0
  125. data/lib/generators/inertia_tw_templates/scaffold/templates/react/Form.jsx.tt +122 -0
  126. data/lib/generators/inertia_tw_templates/scaffold/templates/react/Form.tsx.tt +142 -0
  127. data/lib/generators/inertia_tw_templates/scaffold/templates/react/Index.jsx.tt +43 -0
  128. data/lib/generators/inertia_tw_templates/scaffold/templates/react/Index.tsx.tt +49 -0
  129. data/lib/generators/inertia_tw_templates/scaffold/templates/react/New.jsx.tt +30 -0
  130. data/lib/generators/inertia_tw_templates/scaffold/templates/react/New.tsx.tt +35 -0
  131. data/lib/generators/inertia_tw_templates/scaffold/templates/react/One.jsx.tt +26 -0
  132. data/lib/generators/inertia_tw_templates/scaffold/templates/react/One.tsx.tt +32 -0
  133. data/lib/generators/inertia_tw_templates/scaffold/templates/react/Show.jsx.tt +47 -0
  134. data/lib/generators/inertia_tw_templates/scaffold/templates/react/Show.tsx.tt +53 -0
  135. data/lib/generators/inertia_tw_templates/scaffold/templates/react/types.ts.tt +19 -0
  136. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Edit.svelte.tt +44 -0
  137. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Edit.ts.svelte.tt +45 -0
  138. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Form.svelte.tt +118 -0
  139. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Form.ts.svelte.tt +123 -0
  140. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Index.svelte.tt +42 -0
  141. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Index.ts.svelte.tt +46 -0
  142. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/New.svelte.tt +32 -0
  143. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/New.ts.svelte.tt +33 -0
  144. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/One.svelte.tt +28 -0
  145. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/One.ts.svelte.tt +30 -0
  146. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Show.svelte.tt +50 -0
  147. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Show.ts.svelte.tt +54 -0
  148. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/types.ts.tt +19 -0
  149. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Edit.svelte.tt +45 -0
  150. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Edit.ts.svelte.tt +46 -0
  151. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Form.svelte.tt +120 -0
  152. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Form.ts.svelte.tt +130 -0
  153. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Index.svelte.tt +43 -0
  154. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Index.ts.svelte.tt +44 -0
  155. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/New.svelte.tt +33 -0
  156. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/New.ts.svelte.tt +34 -0
  157. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/One.svelte.tt +28 -0
  158. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/One.ts.svelte.tt +30 -0
  159. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Show.svelte.tt +51 -0
  160. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Show.ts.svelte.tt +52 -0
  161. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/types.ts.tt +19 -0
  162. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Edit.ts.vue.tt +45 -0
  163. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Edit.vue.tt +44 -0
  164. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Form.ts.vue.tt +134 -0
  165. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Form.vue.tt +127 -0
  166. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Index.ts.vue.tt +47 -0
  167. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Index.vue.tt +43 -0
  168. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/New.ts.vue.tt +33 -0
  169. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/New.vue.tt +32 -0
  170. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/One.ts.vue.tt +28 -0
  171. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/One.vue.tt +26 -0
  172. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Show.ts.vue.tt +53 -0
  173. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Show.vue.tt +49 -0
  174. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/types.ts.tt +19 -0
  175. data/lib/inertia_rails/action_filter.rb +27 -0
  176. data/lib/inertia_rails/always_prop.rb +6 -0
  177. data/lib/inertia_rails/base_prop.rb +14 -0
  178. data/lib/inertia_rails/configuration.rb +1 -1
  179. data/lib/inertia_rails/controller.rb +70 -15
  180. data/lib/inertia_rails/generators/controller_template_base.rb +63 -0
  181. data/lib/inertia_rails/generators/helper.rb +139 -0
  182. data/lib/inertia_rails/generators/scaffold_template_base.rb +45 -0
  183. data/lib/inertia_rails/inertia_rails.rb +18 -12
  184. data/lib/inertia_rails/lazy_prop.rb +20 -0
  185. data/lib/inertia_rails/renderer.rb +71 -17
  186. data/lib/inertia_rails/version.rb +1 -1
  187. data/lib/patches/better_errors.rb +10 -8
  188. data/lib/patches/debug_exceptions/patch-5-0.rb +7 -3
  189. data/lib/patches/debug_exceptions/patch-5-1.rb +7 -3
  190. data/lib/patches/mapper.rb +9 -5
  191. data/lib/patches/request.rb +10 -6
  192. metadata +192 -126
  193. data/.github/workflows/push.yml +0 -33
  194. data/.gitignore +0 -25
  195. data/.rspec +0 -3
  196. data/CODE_OF_CONDUCT.md +0 -74
  197. data/Gemfile +0 -7
  198. data/Rakefile +0 -6
  199. data/bin/console +0 -13
  200. data/bin/setup +0 -8
  201. data/inertia_rails.gemspec +0 -37
  202. data/lib/generators/inertia_rails/install/react/InertiaExample.jsx +0 -9
  203. data/lib/generators/inertia_rails/install/react/inertia.jsx +0 -17
  204. data/lib/generators/inertia_rails/install/svelte/InertiaExample.svelte +0 -11
  205. data/lib/generators/inertia_rails/install/svelte/inertia.js +0 -14
  206. data/lib/generators/inertia_rails/install/vue/InertiaExample.vue +0 -11
  207. data/lib/generators/inertia_rails/install/vue/inertia.js +0 -20
  208. data/lib/generators/inertia_rails/install_generator.rb +0 -84
  209. data/lib/inertia_rails/lazy.rb +0 -28
@@ -0,0 +1,35 @@
1
+ import { createInertiaApp } from '@inertiajs/vue3'
2
+ import { createApp, h } from 'vue'
3
+
4
+ createInertiaApp({
5
+ // Set default page title
6
+ // see https://inertia-rails.netlify.app/guide/title-and-meta
7
+ //
8
+ // title: title => title ? `${title} - App` : 'App',
9
+
10
+ // Disable progress bar
11
+ //
12
+ // see https://inertia-rails.netlify.app/guide/progress-indicators
13
+ // progress: false,
14
+
15
+ resolve: (name) => {
16
+ const pages = import.meta.glob('../pages/**/*.vue', {
17
+ eager: true,
18
+ })
19
+ return pages[`../pages/${name}.vue`]
20
+
21
+ // To use a default layout, import the Layout component
22
+ // and use the following lines.
23
+ // see https://inertia-rails.netlify.app/guide/pages#default-layouts
24
+ //
25
+ // const page = pages[`../pages/${name}.vue`]
26
+ // page.default.layout = page.default.layout || Layout
27
+ // return page
28
+ },
29
+
30
+ setup({ el, App, props, plugin }) {
31
+ createApp({ render: () => h(App, props) })
32
+ .use(plugin)
33
+ .mount(el)
34
+ },
35
+ })
@@ -0,0 +1,35 @@
1
+ import { createInertiaApp } from '@inertiajs/vue3'
2
+ import { createApp, DefineComponent, h } from 'vue'
3
+
4
+ createInertiaApp({
5
+ // Set default page title
6
+ // see https://inertia-rails.netlify.app/guide/title-and-meta
7
+ //
8
+ // title: title => title ? `${title} - App` : 'App',
9
+
10
+ // Disable progress bar
11
+ //
12
+ // see https://inertia-rails.netlify.app/guide/progress-indicators
13
+ // progress: false,
14
+
15
+ resolve: (name) => {
16
+ const pages = import.meta.glob<DefineComponent>('../pages/**/*.vue', {
17
+ eager: true,
18
+ })
19
+ return pages[`../pages/${name}.vue`]
20
+
21
+ // To use a default layout, import the Layout component
22
+ // and use the following lines.
23
+ // see https://inertia-rails.netlify.app/guide/pages#default-layouts
24
+ //
25
+ // const page = pages[`../pages/${name}.vue`]
26
+ // page.default.layout = page.default.layout || Layout
27
+ // return page
28
+ },
29
+
30
+ setup({ el, App, props, plugin }) {
31
+ createApp({ render: () => h(App, props) })
32
+ .use(plugin)
33
+ .mount(el)
34
+ },
35
+ })
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "module": "ESNext",
6
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
7
+ "skipLibCheck": true,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "bundler",
11
+ "allowImportingTsExtensions": true,
12
+ "isolatedModules": true,
13
+ "moduleDetection": "force",
14
+ "noEmit": true,
15
+ "jsx": "preserve",
16
+
17
+ /* Linting */
18
+ "strict": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "noFallthroughCasesInSwitch": true
22
+ },
23
+ "include": ["<%= js_destination_path %>/**/*.ts", "<%= js_destination_path %>/**/*.tsx", "<%= js_destination_path %>/**/*.vue"]
24
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "files": [],
3
+ "references": [
4
+ {
5
+ "path": "./tsconfig.app.json"
6
+ },
7
+ {
8
+ "path": "./tsconfig.node.json"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["ES2023"],
5
+ "module": "ESNext",
6
+ "skipLibCheck": true,
7
+
8
+ /* Bundler mode */
9
+ "moduleResolution": "bundler",
10
+ "allowImportingTsExtensions": true,
11
+ "isolatedModules": true,
12
+ "moduleDetection": "force",
13
+ "noEmit": true,
14
+
15
+ /* Linting */
16
+ "strict": true,
17
+ "noUnusedLocals": true,
18
+ "noUnusedParameters": true,
19
+ "noFallthroughCasesInSwitch": true
20
+ },
21
+ "include": ["vite.config.ts"]
22
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/rails/resource/resource_generator'
4
+
5
+ module Inertia
6
+ module Generators
7
+ class ScaffoldGenerator < Rails::Generators::ResourceGenerator # :nodoc:
8
+ remove_hook_for :resource_controller
9
+ remove_class_option :actions
10
+
11
+ class_option :resource_route, type: :boolean
12
+
13
+ hook_for :scaffold_controller, required: true
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/resource_helpers'
4
+ require 'inertia_rails/generators/helper'
5
+
6
+ module Inertia
7
+ module Generators
8
+ # This class is a modified copy of Rails::Generators::ScaffoldControllerGenerator.
9
+ # We don't use inheritance because some gems (i.e. jsbuilder) monkey-patch it.
10
+ class ScaffoldControllerGenerator < Rails::Generators::NamedBase
11
+ include InertiaRails::Generators::Helper
12
+ include Rails::Generators::ResourceHelpers
13
+
14
+ source_root File.expand_path('./templates', __dir__)
15
+
16
+ check_class_collision suffix: 'Controller'
17
+
18
+ class_option :helper, type: :boolean
19
+ class_option :orm, banner: 'NAME', type: :string, required: true,
20
+ desc: 'ORM to generate the controller for'
21
+
22
+ class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
23
+
24
+ argument :attributes, type: :array, default: [], banner: 'field:type field:type'
25
+
26
+ def create_controller_files
27
+ template 'controller.rb',
28
+ File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
29
+ end
30
+
31
+ hook_for :inertia_templates, as: :scaffold, required: true,
32
+ default: InertiaRails::Generators::Helper.guess_inertia_template
33
+
34
+ hook_for :resource_route, in: :rails, required: true do |route|
35
+ invoke route unless options.skip_routes?
36
+ end
37
+
38
+ hook_for :test_framework, in: :rails, as: :scaffold
39
+
40
+ # Invoke the helper using the controller name (pluralized)
41
+ hook_for :helper, in: :rails, as: :scaffold do |invoked|
42
+ invoke invoked, [controller_name]
43
+ end
44
+
45
+ private
46
+
47
+ def permitted_params
48
+ attachments, others = attributes_names.partition { |name| attachments?(name) }
49
+ params = others.map { |name| ":#{name}" }
50
+ params += attachments.map { |name| "#{name}: []" }
51
+ params.join(', ')
52
+ end
53
+
54
+ def attachments?(name)
55
+ attribute = attributes.find { |attr| attr.name == name }
56
+ attribute&.attachments?
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,100 @@
1
+ <% module_namespacing do -%>
2
+ class <%= controller_class_name %>Controller < ApplicationController
3
+ before_action :set_<%= singular_table_name %>, only: %i[ show edit update destroy ]
4
+
5
+ <% if regular_class_path.any? -%>
6
+ wrap_parameters :<%= singular_table_name %>
7
+
8
+ <% end -%>
9
+ inertia_share flash: -> { flash.to_hash }
10
+
11
+ # GET <%= route_url %>
12
+ def index
13
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
14
+ render inertia: '<%= "#{inertia_base_path}/Index" %>', props: {
15
+ <%= plural_table_name %>: @<%= plural_table_name %>.map do |<%= singular_table_name %>|
16
+ <%= "serialize_#{singular_table_name}" %>(<%= singular_table_name %>)
17
+ end
18
+ }
19
+ end
20
+
21
+ # GET <%= route_url %>/1
22
+ def show
23
+ render inertia: '<%= "#{inertia_base_path}/Show" %>', props: {
24
+ <%= singular_table_name %>: <%= "serialize_#{singular_table_name}" %>(@<%= singular_table_name %>)
25
+ }
26
+ end
27
+
28
+ # GET <%= route_url %>/new
29
+ def new
30
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
31
+ render inertia: '<%= "#{inertia_base_path}/New" %>', props: {
32
+ <%= singular_table_name %>: <%= "serialize_#{singular_table_name}" %>(@<%= singular_table_name %>)
33
+ }
34
+ end
35
+
36
+ # GET <%= route_url %>/1/edit
37
+ def edit
38
+ render inertia: '<%= "#{inertia_base_path}/Edit" %>', props: {
39
+ <%= singular_table_name %>: <%= "serialize_#{singular_table_name}" %>(@<%= singular_table_name %>)
40
+ }
41
+ end
42
+
43
+ # POST <%= route_url %>
44
+ def create
45
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
46
+
47
+ if @<%= orm_instance.save %>
48
+ redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully created.") %>
49
+ else
50
+ redirect_to <%= new_helper %>, inertia: { errors: @<%= singular_table_name %>.errors }
51
+ end
52
+ end
53
+
54
+ # PATCH/PUT <%= route_url %>/1
55
+ def update
56
+ if @<%= orm_instance.update("#{singular_table_name}_params") %>
57
+ redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully updated.") %>
58
+ else
59
+ redirect_to <%= edit_helper %>, inertia: { errors: @<%= singular_table_name %>.errors }
60
+ end
61
+ end
62
+
63
+ # DELETE <%= route_url %>/1
64
+ def destroy
65
+ @<%= orm_instance.destroy %>
66
+ redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %>
67
+ end
68
+
69
+ private
70
+ # Use callbacks to share common setup or constraints between actions.
71
+ def set_<%= singular_table_name %>
72
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
73
+ end
74
+
75
+ # Only allow a list of trusted parameters through.
76
+ def <%= "#{singular_table_name}_params" %>
77
+ <%- if attributes_names.empty? -%>
78
+ params.fetch(:<%= singular_table_name %>, {})
79
+ <%- else -%>
80
+ params.require(:<%= singular_table_name %>).permit(<%= permitted_params %>)
81
+ <%- end -%>
82
+ end
83
+
84
+ def <%= "serialize_#{singular_table_name}" %>(<%= singular_table_name %>)
85
+ <%= singular_table_name %>.as_json(only: [
86
+ <%= attributes_to_serialize.map { |attribute| ":#{attribute}" }.join(", ") %>
87
+ ])<%- if attributes.any?(&:attachment?) || attributes.any?(&:attachments?) -%>.tap do |hash|
88
+ <%- attributes.filter(&:attachment?).map do |attribute| -%>
89
+ hash["<%= attribute.column_name %>"] = {filename: <%= singular_table_name %>.<%= attribute.column_name %>.filename, url: url_for(<%= singular_table_name %>.<%= attribute.column_name %>)} if <%= singular_table_name %>.<%= attribute.column_name %>.attached?
90
+ <%- end -%>
91
+ <%- attributes.filter(&:attachments?).map do |attribute| -%>
92
+ hash["<%= attribute.column_name %>"] =
93
+ <%= singular_table_name %>.<%= attribute.column_name %>.flat_map do |file|
94
+ {filename: file.filename.to_s, url: url_for(file)}
95
+ end
96
+ <%- end -%>
97
+ end<% end %>
98
+ end
99
+ end
100
+ <% end -%>
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'inertia_rails/generators/controller_template_base'
4
+
5
+ module InertiaTemplates
6
+ module Generators
7
+ class ControllerGenerator < InertiaRails::Generators::ControllerTemplateBase
8
+ hide!
9
+ source_root File.expand_path('./templates', __dir__)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ export default function <%= @action.camelize %>() {
2
+ return (
3
+ <>
4
+ <h1><%= class_name %>#<%= @action %></h1>
5
+ <p>Find me in <%= @path %></p>
6
+ </>
7
+ );
8
+ }
@@ -0,0 +1,8 @@
1
+ export default function <%= @action.camelize %>() {
2
+ return (
3
+ <>
4
+ <h1><%= class_name %>#<%= @action %></h1>
5
+ <p>Find me in <%= @path %></p>
6
+ </>
7
+ );
8
+ }
@@ -0,0 +1,2 @@
1
+ <h1><%= class_name %>#<%= @action %></h1>
2
+ <p>Find me in <%= @path %></p>
@@ -0,0 +1,2 @@
1
+ <h1><%= class_name %>#<%= @action %></h1>
2
+ <p>Find me in <%= @path %></p>
@@ -0,0 +1,4 @@
1
+ <template>
2
+ <h1><%= class_name %>#<%= @action %></h1>
3
+ <p>Find me in <%= @path %></p>
4
+ </template>
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'inertia_rails/generators/scaffold_template_base'
4
+
5
+ module InertiaTemplates
6
+ module Generators
7
+ class ScaffoldGenerator < InertiaRails::Generators::ScaffoldTemplateBase
8
+ hide!
9
+ source_root File.expand_path('./templates', __dir__)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,35 @@
1
+ import { Head, Link } from '@inertiajs/react'
2
+ import Form from './Form'
3
+
4
+ export default function Edit({ <%= singular_table_name %> }) {
5
+ return (
6
+ <>
7
+ <Head title="Editing <%= human_name.downcase %>" />
8
+
9
+ <h1>Editing <%= human_name.downcase %></h1>
10
+
11
+ <Form
12
+ <%= singular_table_name %>={<%= singular_table_name %>}
13
+ onSubmit={(form) => {
14
+ form.transform((data) => ({ <%= singular_table_name %>: data }))
15
+ <% if attributes.any?(&:attachments?) -%>
16
+ form.post(`<%= js_resource_path %>`, {
17
+ headers: { 'X-HTTP-METHOD-OVERRIDE': 'put' },
18
+ })
19
+ <% else -%>
20
+ form.patch(`<%= js_resource_path %>`)
21
+ <% end -%>
22
+ }}
23
+ submitText="Update <%= human_name %>"
24
+ />
25
+
26
+ <br />
27
+
28
+ <div>
29
+ <Link href={`<%= js_resource_path %>`}>Show this <%= human_name.downcase %></Link>
30
+ {' | '}
31
+ <Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
32
+ </div>
33
+ </>
34
+ )
35
+ }
@@ -0,0 +1,40 @@
1
+ import { Head, Link } from '@inertiajs/react'
2
+ import Form from './Form'
3
+ import { <%= inertia_model_type %> } from './types'
4
+
5
+ interface EditProps {
6
+ <%= singular_table_name %>: <%= inertia_model_type %>
7
+ }
8
+
9
+ export default function Edit({ <%= singular_table_name %> }: EditProps) {
10
+ return (
11
+ <>
12
+ <Head title="Editing <%= human_name.downcase %>" />
13
+
14
+ <h1>Editing <%= human_name.downcase %></h1>
15
+
16
+ <Form
17
+ <%= singular_table_name %>={<%= singular_table_name %>}
18
+ onSubmit={(form) => {
19
+ form.transform((data) => ({ <%= singular_table_name %>: data }))
20
+ <% if attributes.any?(&:attachments?) -%>
21
+ form.post(`<%= js_resource_path %>`, {
22
+ headers: { 'X-HTTP-METHOD-OVERRIDE': 'put' },
23
+ })
24
+ <% else -%>
25
+ form.patch(`<%= js_resource_path %>`)
26
+ <% end -%>
27
+ }}
28
+ submitText="Update <%= human_name %>"
29
+ />
30
+
31
+ <br />
32
+
33
+ <div>
34
+ <Link href={`<%= js_resource_path %>`}>Show this <%= human_name.downcase %></Link>
35
+ {' | '}
36
+ <Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
37
+ </div>
38
+ </>
39
+ )
40
+ }
@@ -0,0 +1,111 @@
1
+ import { useForm } from '@inertiajs/react'
2
+
3
+ export default function Form({ <%= singular_table_name %>, onSubmit, submitText }) {
4
+ const form = useForm({
5
+ <% attributes.each do |attribute| -%>
6
+ <% if attribute.password_digest? -%>
7
+ password: '',
8
+ password_confirmation: '',
9
+ <% else -%>
10
+ <%= attribute.column_name %>: <%= singular_table_name %>.<%= attribute.column_name %> || <%= default_value(attribute) %>,
11
+ <% end -%>
12
+ <% end -%>
13
+ })
14
+ const { data, setData, errors, processing } = form
15
+
16
+ const handleSubmit = (e) => {
17
+ e.preventDefault()
18
+ onSubmit(form)
19
+ }
20
+
21
+ return (
22
+ <form onSubmit={handleSubmit}>
23
+ <% attributes.each do |attribute| -%>
24
+ <% if attribute.password_digest? -%>
25
+ <div>
26
+ <label style={{ display: 'block' }} htmlFor="password">
27
+ Password
28
+ </label>
29
+ <input
30
+ type="password"
31
+ name="password"
32
+ id="password"
33
+ onChange={(e) => setData('password', e.target.value)}
34
+ />
35
+ {errors.password && (
36
+ <div style={{ color: 'red' }}>{errors.password.join(', ')}</div>
37
+ )}
38
+ </div>
39
+
40
+ <div>
41
+ <label style={{ display: 'block' }} htmlFor="password_confirmation">
42
+ Password confirmation
43
+ </label>
44
+ <input
45
+ type="password"
46
+ name="password_confirmation"
47
+ id="password_confirmation"
48
+ onChange={(e) => setData('password_confirmation', e.target.value)}
49
+ />
50
+ {errors.password_confirmation && (
51
+ <div style={{ color: 'red' }}>{errors.password_confirmation.join(', ')}</div>
52
+ )}
53
+ </div>
54
+ <% else -%>
55
+ <div>
56
+ <label style={{ display: 'block' }} htmlFor="<%= attribute.singular_name %>">
57
+ <%= attribute.human_name %>
58
+ </label>
59
+ <% if input_type(attribute) == "text_area" -%>
60
+ <textarea
61
+ name="<%= attribute.singular_name %>"
62
+ id="<%= attribute.singular_name %>"
63
+ value={data.<%= attribute.column_name %>}
64
+ onChange={(e) => setData('<%= attribute.column_name %>', e.target.value)}
65
+ />
66
+ <% elsif attribute.attachment? -%>
67
+ <input
68
+ type="file"
69
+ name="<%= attribute.singular_name %>"
70
+ id="<%= attribute.singular_name %>"
71
+ onChange={(e) => setData('<%= attribute.column_name %>', e.target.files[0])}
72
+ />
73
+ <% elsif attribute.attachments? -%>
74
+ <input
75
+ type="file"
76
+ multiple
77
+ name="<%= attribute.singular_name %>[]"
78
+ id="<%= attribute.singular_name %>"
79
+ onChange={(e) => setData('<%= attribute.column_name %>', Array.from(e.target.files))}
80
+ />
81
+ <% elsif input_type(attribute) == "checkbox" -%>
82
+ <input
83
+ type="<%= input_type(attribute) %>"
84
+ name="<%= attribute.singular_name %>"
85
+ id="<%= attribute.singular_name %>"
86
+ checked={data.<%= attribute.column_name %>}
87
+ onChange={(e) => setData('<%= attribute.column_name %>', e.target.checked)}
88
+ />
89
+ <% else -%>
90
+ <input
91
+ type="<%= input_type(attribute) %>"
92
+ name="<%= attribute.singular_name %>"
93
+ id="<%= attribute.singular_name %>"
94
+ value={data.<%= attribute.column_name %>}
95
+ onChange={(e) => setData('<%= attribute.column_name %>', e.target.value)}
96
+ />
97
+ <% end -%>
98
+ {errors.<%= attribute.column_name %> && (
99
+ <div style={{ color: 'red' }}>{errors.<%= attribute.column_name %>.join(', ')}</div>
100
+ )}
101
+ </div>
102
+ <% end -%>
103
+ <% end -%>
104
+ <div>
105
+ <button type="submit" disabled={processing}>
106
+ {submitText}
107
+ </button>
108
+ </div>
109
+ </form>
110
+ )
111
+ }