inertia_rails 3.4.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -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/always_prop.rb +6 -0
  176. data/lib/inertia_rails/base_prop.rb +14 -0
  177. data/lib/inertia_rails/configuration.rb +1 -1
  178. data/lib/inertia_rails/controller.rb +8 -1
  179. data/lib/inertia_rails/generators/controller_template_base.rb +63 -0
  180. data/lib/inertia_rails/generators/helper.rb +139 -0
  181. data/lib/inertia_rails/generators/scaffold_template_base.rb +45 -0
  182. data/lib/inertia_rails/inertia_rails.rb +18 -12
  183. data/lib/inertia_rails/lazy_prop.rb +20 -0
  184. data/lib/inertia_rails/renderer.rb +71 -17
  185. data/lib/inertia_rails/version.rb +1 -1
  186. data/lib/patches/better_errors.rb +10 -8
  187. data/lib/patches/debug_exceptions/patch-5-0.rb +7 -3
  188. data/lib/patches/debug_exceptions/patch-5-1.rb +7 -3
  189. data/lib/patches/mapper.rb +9 -5
  190. data/lib/patches/request.rb +10 -6
  191. metadata +181 -13
  192. data/lib/generators/inertia_rails/install/react/InertiaExample.jsx +0 -9
  193. data/lib/generators/inertia_rails/install/react/inertia.jsx +0 -17
  194. data/lib/generators/inertia_rails/install/svelte/InertiaExample.svelte +0 -11
  195. data/lib/generators/inertia_rails/install/svelte/inertia.js +0 -14
  196. data/lib/generators/inertia_rails/install/vue/InertiaExample.vue +0 -11
  197. data/lib/generators/inertia_rails/install/vue/inertia.js +0 -20
  198. data/lib/generators/inertia_rails/install_generator.rb +0 -84
  199. data/lib/inertia_rails/lazy.rb +0 -28
@@ -0,0 +1,33 @@
1
+ <script lang="ts">
2
+ import { Link, type InertiaFormProps } from '@inertiajs/svelte'
3
+ import type { <%= inertia_model_type %>, <%= inertia_model_form_type %> } from './types'
4
+ import Form from './Form.svelte'
5
+
6
+ let { <%= singular_table_name %> } = $props<{ <%= singular_table_name %>: <%= inertia_model_type %> }>()
7
+
8
+ const handleSubmit = ({ form }: { form: InertiaFormProps<<%= inertia_model_form_type %>> }) => {
9
+ form.transform((data) => ({ <%= singular_table_name %>: data }))
10
+ form.post('<%= js_resources_path %>')
11
+ }
12
+ </script>
13
+
14
+ <svelte:head>
15
+ <title>New <%= human_name.downcase %></title>
16
+ </svelte:head>
17
+
18
+ <div class="mx-auto md:w-2/3 w-full px-8 pt-8">
19
+ <h1 class="font-bold text-4xl">New <%= human_name.downcase %></h1>
20
+
21
+ <Form
22
+ {<%= singular_table_name %>}
23
+ submitText="Create <%= human_name %>"
24
+ onSubmit={handleSubmit}
25
+ />
26
+
27
+ <Link
28
+ href="<%= js_resources_path %>"
29
+ class="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
30
+ >
31
+ Back to <%= human_name.pluralize.downcase %>
32
+ </Link>
33
+ </div>
@@ -0,0 +1,28 @@
1
+ <script>
2
+ let { <%= singular_table_name %> } = $props()
3
+ </script>
4
+
5
+ <div>
6
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
7
+ <p class="my-5">
8
+ <strong class="block font-medium mb-1"><%= attribute.human_name %>:</strong>
9
+ <% if attribute.attachment? -%>
10
+ {#if <%= singular_table_name %>.<%= attribute.column_name %>}
11
+ <a href={<%= singular_table_name %>.<%= attribute.column_name %>.url}>
12
+ {<%= singular_table_name %>.<%= attribute.column_name %>.filename}
13
+ </a>
14
+ {/if}
15
+ </p>
16
+ <% elsif attribute.attachments? -%>
17
+ </p>
18
+ {#each <%= singular_table_name %>.<%= attribute.column_name %> as { url, filename }}
19
+ <div>
20
+ <a href={url}>{filename}</a>
21
+ </div>
22
+ {/each}
23
+ <% else -%>
24
+ {<%= singular_table_name %>.<%= attribute.column_name %>}
25
+ </p>
26
+ <% end -%>
27
+ <% end -%>
28
+ </div>
@@ -0,0 +1,30 @@
1
+ <script lang="ts">
2
+ import type { <%= inertia_model_type %> } from './types'
3
+
4
+ let { <%= singular_table_name %> } = $props<{ <%= singular_table_name %>: <%= inertia_model_type %> }>()
5
+ </script>
6
+
7
+ <div>
8
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
9
+ <p class="my-5">
10
+ <strong class="block font-medium mb-1"><%= attribute.human_name %>:</strong>
11
+ <% if attribute.attachment? -%>
12
+ {#if <%= singular_table_name %>.<%= attribute.column_name %>}
13
+ <a href={<%= singular_table_name %>.<%= attribute.column_name %>.url}>
14
+ {<%= singular_table_name %>.<%= attribute.column_name %>.filename}
15
+ </a>
16
+ {/if}
17
+ </p>
18
+ <% elsif attribute.attachments? -%>
19
+ </p>
20
+ {#each <%= singular_table_name %>.<%= attribute.column_name %> as { url, filename }}
21
+ <div>
22
+ <a href={url}>{filename}</a>
23
+ </div>
24
+ {/each}
25
+ <% else -%>
26
+ {<%= singular_table_name %>.<%= attribute.column_name %>}
27
+ </p>
28
+ <% end -%>
29
+ <% end -%>
30
+ </div>
@@ -0,0 +1,50 @@
1
+ <script>
2
+ import { Link } from '@inertiajs/svelte'
3
+ import <%= inertia_component_name %> from './<%= inertia_component_name %>.svelte'
4
+
5
+ let { <%= singular_table_name %>, flash } = $props()
6
+ </script>
7
+
8
+ <svelte:head>
9
+ <title><%= human_name %> #{<%= singular_table_name %>.id}</title>
10
+ </svelte:head>
11
+
12
+ <div class="mx-auto md:w-2/3 w-full px-8 pt-8">
13
+ <div class="mx-auto">
14
+ {#if flash.notice}
15
+ <p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block">
16
+ {flash.notice}
17
+ </p>
18
+ {/if}
19
+
20
+ <h1 class="font-bold text-4xl"><%= human_name %> #{<%= singular_table_name %>.id}</h1>
21
+
22
+ <<%= inertia_component_name %> {<%= singular_table_name %>} />
23
+
24
+ <Link
25
+ href={`<%= js_edit_resource_path %>`}
26
+ class="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
27
+ >
28
+ Edit this <%= human_name.downcase %>
29
+ </Link>
30
+ <Link
31
+ href="<%= js_resources_path %>"
32
+ class="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
33
+ >
34
+ Back to <%= human_name.pluralize.downcase %>
35
+ </Link>
36
+ <div class="inline-block ml-2">
37
+ <Link
38
+ href={`<%= js_resource_path %>`}
39
+ method="delete"
40
+ class="mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium"
41
+ >
42
+ Destroy this <%= human_name.downcase %>
43
+ </Link>
44
+ </div>
45
+ </div>
46
+ </div>
47
+
48
+
49
+
50
+
@@ -0,0 +1,54 @@
1
+ <script lang="ts">
2
+ import { Link } from '@inertiajs/svelte'
3
+ import <%= inertia_component_name %> from './<%= inertia_component_name %>.svelte'
4
+ import type { <%= inertia_model_type %> } from './types'
5
+
6
+ let { <%= singular_table_name %>, flash } = $props<{
7
+ <%= singular_table_name %>: <%= inertia_model_type %>
8
+ flash: { notice?: string }
9
+ }>()
10
+ </script>
11
+
12
+ <svelte:head>
13
+ <title><%= human_name %> #{<%= singular_table_name %>.id}</title>
14
+ </svelte:head>
15
+
16
+ <div class="mx-auto md:w-2/3 w-full px-8 pt-8">
17
+ <div class="mx-auto">
18
+ {#if flash.notice}
19
+ <p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block">
20
+ {flash.notice}
21
+ </p>
22
+ {/if}
23
+
24
+ <h1 class="font-bold text-4xl"><%= human_name %> #{<%= singular_table_name %>.id}</h1>
25
+
26
+ <<%= inertia_component_name %> {<%= singular_table_name %>} />
27
+
28
+ <Link
29
+ href={`<%= js_edit_resource_path %>`}
30
+ class="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
31
+ >
32
+ Edit this <%= human_name.downcase %>
33
+ </Link>
34
+ <Link
35
+ href="<%= js_resources_path %>"
36
+ class="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
37
+ >
38
+ Back to <%= human_name.pluralize.downcase %>
39
+ </Link>
40
+ <div class="inline-block ml-2">
41
+ <Link
42
+ href={`<%= js_resource_path %>`}
43
+ method="delete"
44
+ class="mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium"
45
+ >
46
+ Destroy this <%= human_name.downcase %>
47
+ </Link>
48
+ </div>
49
+ </div>
50
+ </div>
51
+
52
+
53
+
54
+
@@ -0,0 +1,19 @@
1
+ export interface <%= inertia_model_type %> {
2
+ id: number
3
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
4
+ <%= attribute.column_name %>: <%= ts_type(attribute) %>
5
+ <% end -%>
6
+ }
7
+
8
+ export type <%= inertia_model_form_type %> = Omit<<%= inertia_model_type %>, <%= omit_input_attributes.map { |a| "'#{a}'" }.join(' | ') %>><% if custom_form_attributes.any? -%> & {
9
+ <% custom_form_attributes.map do |attribute| -%>
10
+ <% if attribute.password_digest? -%>
11
+ password: string
12
+ password_confirmation: string
13
+ <% elsif attribute.attachment? -%>
14
+ <%= attribute.column_name %>?: File
15
+ <% elsif attribute.attachments? -%>
16
+ <%= attribute.column_name %>?: File[]
17
+ <% end -%>
18
+ <% end -%>
19
+ }<% end %>
@@ -0,0 +1,45 @@
1
+ <script>
2
+ import { Link } from '@inertiajs/svelte'
3
+ import Form from './Form.svelte'
4
+
5
+ export let <%= singular_table_name %>
6
+
7
+ const handleSubmit = (e) => {
8
+ const { form } = e.detail
9
+ form.transform((data) => ({ <%= singular_table_name %>: data }))
10
+ <% if attributes.any?(&:attachments?) -%>
11
+ form.post(`<%= js_resource_path %>`, {
12
+ headers: { 'X-HTTP-METHOD-OVERRIDE': 'put' },
13
+ })
14
+ <% else -%>
15
+ form.patch(`<%= js_resource_path %>`)
16
+ <% end -%>
17
+ }
18
+ </script>
19
+
20
+ <svelte:head>
21
+ <title>Editing <%= human_name.downcase %></title>
22
+ </svelte:head>
23
+
24
+ <div class="mx-auto md:w-2/3 w-full px-8 pt-8">
25
+ <h1 class="font-bold text-4xl">Editing <%= human_name.downcase %></h1>
26
+
27
+ <Form
28
+ {<%= singular_table_name %>}
29
+ submitText="Update <%= human_name %>"
30
+ on:submit={handleSubmit}
31
+ />
32
+
33
+ <Link
34
+ href={`<%= js_resource_path %>`}
35
+ class="mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
36
+ >
37
+ Show this <%= human_name.downcase %>
38
+ </Link>
39
+ <Link
40
+ href="<%= js_resources_path %>"
41
+ class="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
42
+ >
43
+ Back to <%= human_name.pluralize.downcase %>
44
+ </Link>
45
+ </div>
@@ -0,0 +1,46 @@
1
+ <script lang="ts">
2
+ import { Link, type InertiaForm } from '@inertiajs/svelte'
3
+ import type { <%= inertia_model_type %>, <%= inertia_model_form_type %> } from './types'
4
+ import Form from './Form.svelte'
5
+
6
+ export let <%= singular_table_name %>: <%= inertia_model_type %>
7
+
8
+ const handleSubmit = (e: CustomEvent<{ form: InertiaForm<<%= inertia_model_form_type %>> }>) => {
9
+ const { form } = e.detail
10
+ form.transform((data) => ({ <%= singular_table_name %>: data }))
11
+ <% if attributes.any?(&:attachments?) -%>
12
+ form.post(`<%= js_resource_path %>`, {
13
+ headers: { 'X-HTTP-METHOD-OVERRIDE': 'put' },
14
+ })
15
+ <% else -%>
16
+ form.patch(`<%= js_resource_path %>`)
17
+ <% end -%>
18
+ }
19
+ </script>
20
+
21
+ <svelte:head>
22
+ <title>Editing <%= human_name.downcase %></title>
23
+ </svelte:head>
24
+
25
+ <div class="mx-auto md:w-2/3 w-full px-8 pt-8">
26
+ <h1 class="font-bold text-4xl">Editing <%= human_name.downcase %></h1>
27
+
28
+ <Form
29
+ {<%= singular_table_name %>}
30
+ submitText="Update <%= human_name %>"
31
+ on:submit={handleSubmit}
32
+ />
33
+
34
+ <Link
35
+ href={`<%= js_resource_path %>`}
36
+ class="mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
37
+ >
38
+ Show this <%= human_name.downcase %>
39
+ </Link>
40
+ <Link
41
+ href="<%= js_resources_path %>"
42
+ class="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
43
+ >
44
+ Back to <%= human_name.pluralize.downcase %>
45
+ </Link>
46
+ </div>
@@ -0,0 +1,120 @@
1
+ <script>
2
+ import { useForm } from '@inertiajs/svelte'
3
+ import { createEventDispatcher } from 'svelte'
4
+
5
+ const dispatch = createEventDispatcher()
6
+
7
+ export let <%= singular_table_name %>
8
+ export let submitText
9
+
10
+ const form = useForm({
11
+ <% attributes.each do |attribute| -%>
12
+ <% if attribute.password_digest? -%>
13
+ password: '',
14
+ password_confirmation: '',
15
+ <% else -%>
16
+ <%= attribute.column_name %>: <%= singular_table_name %>.<%= attribute.column_name %> || <%= default_value(attribute) %>,
17
+ <% end -%>
18
+ <% end -%>
19
+ })
20
+ </script>
21
+
22
+ <form
23
+ class="contents"
24
+ on:submit|preventDefault={dispatch('submit', { form: $form })}
25
+ >
26
+ <% attributes.each do |attribute| -%>
27
+ <div class="my-5">
28
+ <% if attribute.password_digest? -%>
29
+ <label for="password">Password</label>
30
+ <input
31
+ type="password"
32
+ name="password"
33
+ id="password"
34
+ bind:value={$form.password}
35
+ class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
36
+ />
37
+ {#if $form.errors.password}
38
+ <div class="text-red-500 px-3 py-2 font-medium">
39
+ {$form.errors.password.join(', ')}
40
+ </div>
41
+ {/if}
42
+ </div>
43
+
44
+ <div class="my-5">
45
+ <label for="password_confirmation">Password confirmation</label>
46
+ <input
47
+ type="password"
48
+ name="password_confirmation"
49
+ id="password_confirmation"
50
+ bind:value={$form.password_confirmation}
51
+ class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
52
+ />
53
+ {#if $form.errors.password_confirmation}
54
+ <div class="text-red-500 px-3 py-2 font-medium">
55
+ {$form.errors.password_confirmation.join(', ')}
56
+ </div>
57
+ {/if}
58
+ <% else -%>
59
+ <label for="<%= attribute.singular_name %>"><%= attribute.human_name %></label>
60
+ <% if input_type(attribute) == "text_area" -%>
61
+ <textarea
62
+ name="<%= attribute.singular_name %>"
63
+ id="<%= attribute.singular_name %>"
64
+ bind:value={$form.<%= attribute.column_name %>}
65
+ rows="4"
66
+ class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
67
+ />
68
+ <% elsif attribute.attachment? -%>
69
+ <input
70
+ type="file"
71
+ name="<%= attribute.singular_name %>"
72
+ id="<%= attribute.singular_name %>"
73
+ on:input={(e) => ($form.<%= attribute.column_name %> = e.target.files[0])}
74
+ class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
75
+ />
76
+ <% elsif attribute.attachments? -%>
77
+ <input
78
+ type="file"
79
+ multiple
80
+ name="<%= attribute.singular_name %>[]"
81
+ id="<%= attribute.singular_name %>"
82
+ on:input={(e) => ($form.<%= attribute.column_name %> = Array.from(e.target.files))}
83
+ class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
84
+ />
85
+ <% elsif input_type(attribute) == "checkbox" -%>
86
+ <input
87
+ type="<%= input_type(attribute) %>"
88
+ name="<%= attribute.singular_name %>"
89
+ id="<%= attribute.singular_name %>"
90
+ bind:checked={$form.<%= attribute.column_name %>}
91
+ class="block mt-2 h-5 w-5"
92
+ />
93
+ <% else -%>
94
+ <input
95
+ type="<%= input_type(attribute) %>"
96
+ name="<%= attribute.singular_name %>"
97
+ id="<%= attribute.singular_name %>"
98
+ bind:value={$form.<%= attribute.column_name %>}
99
+ class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
100
+ />
101
+ <% end -%>
102
+ {#if $form.errors.<%= attribute.column_name %>}
103
+ <div class="text-red-500 px-3 py-2 font-medium">
104
+ {$form.errors.<%= attribute.column_name %>.join(', ')}
105
+ </div>
106
+ {/if}
107
+ <% end -%>
108
+ </div>
109
+
110
+ <% end -%>
111
+ <div class="inline">
112
+ <button
113
+ type="submit"
114
+ disabled={$form.processing}
115
+ class="rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer"
116
+ >
117
+ {submitText}
118
+ </button>
119
+ </div>
120
+ </form>
@@ -0,0 +1,130 @@
1
+ <script lang="ts">
2
+ import { useForm, type InertiaForm } from '@inertiajs/svelte'
3
+ import { createEventDispatcher } from 'svelte'
4
+ import type { <%= inertia_model_type %>, <%= inertia_model_form_type %> } from './types'
5
+
6
+ const dispatch = createEventDispatcher<{
7
+ submit: { form: InertiaForm<<%= inertia_model_form_type %>> }
8
+ }>()
9
+
10
+ export let <%= singular_table_name %>: <%= inertia_model_type %>
11
+ export let submitText: string
12
+
13
+ <% if attributes.any? { |a| a.attachment? || a.attachments? } -%>
14
+ const filesFromEvent = (e: Event) => {
15
+ const target = e.target as HTMLInputElement
16
+ return Array.from(target.files || [])
17
+ }
18
+
19
+ <% end -%>
20
+ const form = useForm<<%= inertia_model_form_type %>>({
21
+ <% attributes.reject { |a| a.attachment? || a.attachments? }.each do |attribute| -%>
22
+ <% if attribute.password_digest? -%>
23
+ password: '',
24
+ password_confirmation: '',
25
+ <% else -%>
26
+ <%= attribute.column_name %>: <%= singular_table_name %>.<%= attribute.column_name %>,
27
+ <% end -%>
28
+ <% end -%>
29
+ })
30
+ </script>
31
+
32
+ <form
33
+ class="contents"
34
+ on:submit|preventDefault={() => dispatch('submit', { form: $form })}
35
+ >
36
+ <% attributes.each do |attribute| -%>
37
+ <div class="my-5">
38
+ <% if attribute.password_digest? -%>
39
+ <label for="password">Password</label>
40
+ <input
41
+ type="password"
42
+ name="password"
43
+ id="password"
44
+ bind:value={$form.password}
45
+ class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
46
+ />
47
+ {#if $form.errors.password}
48
+ <div class="text-red-500 px-3 py-2 font-medium">
49
+ {$form.errors.password}
50
+ </div>
51
+ {/if}
52
+ </div>
53
+
54
+ <div class="my-5">
55
+ <label for="password_confirmation">Password confirmation</label>
56
+ <input
57
+ type="password"
58
+ name="password_confirmation"
59
+ id="password_confirmation"
60
+ bind:value={$form.password_confirmation}
61
+ class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
62
+ />
63
+ {#if $form.errors.password_confirmation}
64
+ <div class="text-red-500 px-3 py-2 font-medium">
65
+ {$form.errors.password_confirmation}
66
+ </div>
67
+ {/if}
68
+ <% else -%>
69
+ <label for="<%= attribute.singular_name %>"><%= attribute.human_name %></label>
70
+ <% if input_type(attribute) == "text_area" -%>
71
+ <textarea
72
+ name="<%= attribute.singular_name %>"
73
+ id="<%= attribute.singular_name %>"
74
+ bind:value={$form.<%= attribute.column_name %>}
75
+ rows="4"
76
+ class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
77
+ />
78
+ <% elsif attribute.attachment? -%>
79
+ <input
80
+ type="file"
81
+ name="<%= attribute.singular_name %>"
82
+ id="<%= attribute.singular_name %>"
83
+ on:input={(e) => ($form.<%= attribute.column_name %> = filesFromEvent(e)[0])}
84
+ class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
85
+ />
86
+ <% elsif attribute.attachments? -%>
87
+ <input
88
+ type="file"
89
+ multiple
90
+ name="<%= attribute.singular_name %>[]"
91
+ id="<%= attribute.singular_name %>"
92
+ on:input={(e) => ($form.<%= attribute.column_name %> = filesFromEvent(e))}
93
+ class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
94
+ />
95
+ <% elsif input_type(attribute) == "checkbox" -%>
96
+ <input
97
+ type="<%= input_type(attribute) %>"
98
+ name="<%= attribute.singular_name %>"
99
+ id="<%= attribute.singular_name %>"
100
+ bind:checked={$form.<%= attribute.column_name %>}
101
+ class="block mt-2 h-5 w-5"
102
+ />
103
+ <% else -%>
104
+ <input
105
+ type="<%= input_type(attribute) %>"
106
+ name="<%= attribute.singular_name %>"
107
+ id="<%= attribute.singular_name %>"
108
+ bind:value={$form.<%= attribute.column_name %>}
109
+ class="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
110
+ />
111
+ <% end -%>
112
+ {#if $form.errors.<%= attribute.column_name %>}
113
+ <div class="text-red-500 px-3 py-2 font-medium">
114
+ {$form.errors.<%= attribute.column_name %>}
115
+ </div>
116
+ {/if}
117
+ <% end -%>
118
+ </div>
119
+
120
+ <% end -%>
121
+ <div class="inline">
122
+ <button
123
+ type="submit"
124
+ disabled={$form.processing}
125
+ class="rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer"
126
+ >
127
+ {submitText}
128
+ </button>
129
+ </div>
130
+ </form>
@@ -0,0 +1,43 @@
1
+ <script>
2
+ import { Link } from '@inertiajs/svelte'
3
+ import <%= inertia_component_name %> from './<%= inertia_component_name %>.svelte'
4
+
5
+ export let <%= plural_table_name %>
6
+ export let flash
7
+ </script>
8
+
9
+ <svelte:head>
10
+ <title><%= human_name.pluralize %></title>
11
+ </svelte:head>
12
+
13
+ <div class="mx-auto md:w-2/3 w-full px-8 pt-8">
14
+ {#if flash.notice}
15
+ <p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block">
16
+ {flash.notice}
17
+ </p>
18
+ {/if}
19
+
20
+ <div class="flex justify-between items-center">
21
+ <h1 class="font-bold text-4xl"><%= human_name.pluralize %></h1>
22
+ <Link
23
+ href="<%= js_new_resource_path %>"
24
+ class="rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium"
25
+ >
26
+ New <%= human_name.downcase %>
27
+ </Link>
28
+ </div>
29
+
30
+ <div class="min-w-full">
31
+ {#each <%= plural_table_name %> as <%= singular_table_name %> (<%= singular_table_name %>.id)}
32
+ <<%= inertia_component_name %> {<%= singular_table_name %>} />
33
+ <p>
34
+ <Link
35
+ href={`<%= js_resource_path %>`}
36
+ class="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
37
+ >
38
+ Show this <%= human_name.downcase %>
39
+ </Link>
40
+ </p>
41
+ {/each}
42
+ </div>
43
+ </div>
@@ -0,0 +1,44 @@
1
+ <script lang="ts">
2
+ import { Link } from '@inertiajs/svelte'
3
+ import <%= inertia_component_name %> from './<%= inertia_component_name %>.svelte'
4
+ import type { <%= inertia_model_type %> } from './types'
5
+
6
+ export let <%= plural_table_name %>: <%= inertia_model_type %>[]
7
+ export let flash: { notice?: string }
8
+ </script>
9
+
10
+ <svelte:head>
11
+ <title><%= human_name.pluralize %></title>
12
+ </svelte:head>
13
+
14
+ <div class="mx-auto md:w-2/3 w-full px-8 pt-8">
15
+ {#if flash.notice}
16
+ <p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block">
17
+ {flash.notice}
18
+ </p>
19
+ {/if}
20
+
21
+ <div class="flex justify-between items-center">
22
+ <h1 class="font-bold text-4xl"><%= human_name.pluralize %></h1>
23
+ <Link
24
+ href="<%= js_new_resource_path %>"
25
+ class="rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium"
26
+ >
27
+ New <%= human_name.downcase %>
28
+ </Link>
29
+ </div>
30
+
31
+ <div class="min-w-full">
32
+ {#each <%= plural_table_name %> as <%= singular_table_name %> (<%= singular_table_name %>.id)}
33
+ <<%= inertia_component_name %> {<%= singular_table_name %>} />
34
+ <p>
35
+ <Link
36
+ href={`<%= js_resource_path %>`}
37
+ class="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
38
+ >
39
+ Show this <%= human_name.downcase %>
40
+ </Link>
41
+ </p>
42
+ {/each}
43
+ </div>
44
+ </div>