inertia_rails-contrib 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +21 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +187 -0
  5. data/lib/generators/inertia/controller/controller_generator.rb +16 -0
  6. data/lib/generators/inertia/controller/templates/controller.rb.tt +10 -0
  7. data/lib/generators/inertia/install/install_generator.rb +151 -0
  8. data/lib/generators/inertia/install/templates/assets/inertia.svg +1 -0
  9. data/lib/generators/inertia/install/templates/assets/react.svg +1 -0
  10. data/lib/generators/inertia/install/templates/assets/svelte.svg +1 -0
  11. data/lib/generators/inertia/install/templates/assets/vite_ruby.svg +1 -0
  12. data/lib/generators/inertia/install/templates/assets/vue.svg +1 -0
  13. data/lib/generators/inertia/install/templates/controller.rb +7 -0
  14. data/lib/generators/inertia/install/templates/initializer.rb +4 -0
  15. data/lib/generators/inertia/install/templates/react/InertiaExample.jsx +60 -0
  16. data/lib/generators/inertia/install/templates/react/InertiaExample.module.css +80 -0
  17. data/lib/generators/inertia/install/templates/react/inertia.js +34 -0
  18. data/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte +116 -0
  19. data/lib/generators/inertia/install/templates/svelte/inertia.js +30 -0
  20. data/lib/generators/inertia/install/templates/svelte/svelte.config.js +7 -0
  21. data/lib/generators/inertia/install/templates/vue/InertiaExample.vue +117 -0
  22. data/lib/generators/inertia/install/templates/vue/inertia.js +33 -0
  23. data/lib/generators/inertia/scaffold/scaffold_generator.rb +16 -0
  24. data/lib/generators/inertia/scaffold_controller/scaffold_controller_generator.rb +56 -0
  25. data/lib/generators/inertia/scaffold_controller/templates/controller.rb.tt +102 -0
  26. data/lib/generators/inertia_templates/controller/controller_generator.rb +12 -0
  27. data/lib/generators/inertia_templates/controller/templates/react/view.jsx.tt +8 -0
  28. data/lib/generators/inertia_templates/controller/templates/svelte/view.svelte.tt +2 -0
  29. data/lib/generators/inertia_templates/controller/templates/vue/view.vue.tt +4 -0
  30. data/lib/generators/inertia_templates/scaffold/scaffold_generator.rb +12 -0
  31. data/lib/generators/inertia_templates/scaffold/templates/react/Edit.jsx.tt +36 -0
  32. data/lib/generators/inertia_templates/scaffold/templates/react/Form.jsx.tt +111 -0
  33. data/lib/generators/inertia_templates/scaffold/templates/react/Index.jsx.tt +26 -0
  34. data/lib/generators/inertia_templates/scaffold/templates/react/New.jsx.tt +27 -0
  35. data/lib/generators/inertia_templates/scaffold/templates/react/One.jsx.tt +26 -0
  36. data/lib/generators/inertia_templates/scaffold/templates/react/Show.jsx.tt +39 -0
  37. data/lib/generators/inertia_templates/scaffold/templates/svelte/Edit.svelte.tt +37 -0
  38. data/lib/generators/inertia_templates/scaffold/templates/svelte/Form.svelte.tt +96 -0
  39. data/lib/generators/inertia_templates/scaffold/templates/svelte/Index.svelte.tt +42 -0
  40. data/lib/generators/inertia_templates/scaffold/templates/svelte/New.svelte.tt +30 -0
  41. data/lib/generators/inertia_templates/scaffold/templates/svelte/One.svelte.tt +28 -0
  42. data/lib/generators/inertia_templates/scaffold/templates/svelte/Show.svelte.tt +46 -0
  43. data/lib/generators/inertia_templates/scaffold/templates/vue/Edit.vue.tt +36 -0
  44. data/lib/generators/inertia_templates/scaffold/templates/vue/Form.vue.tt +94 -0
  45. data/lib/generators/inertia_templates/scaffold/templates/vue/Index.vue.tt +31 -0
  46. data/lib/generators/inertia_templates/scaffold/templates/vue/New.vue.tt +29 -0
  47. data/lib/generators/inertia_templates/scaffold/templates/vue/One.vue.tt +26 -0
  48. data/lib/generators/inertia_templates/scaffold/templates/vue/Show.vue.tt +44 -0
  49. data/lib/generators/inertia_tw_templates/controller/controller_generator.rb +12 -0
  50. data/lib/generators/inertia_tw_templates/controller/templates/react/view.jsx.tt +8 -0
  51. data/lib/generators/inertia_tw_templates/controller/templates/svelte/view.svelte.tt +2 -0
  52. data/lib/generators/inertia_tw_templates/controller/templates/vue/view.vue.tt +4 -0
  53. data/lib/generators/inertia_tw_templates/scaffold/scaffold_generator.rb +12 -0
  54. data/lib/generators/inertia_tw_templates/scaffold/templates/react/Edit.jsx.tt +43 -0
  55. data/lib/generators/inertia_tw_templates/scaffold/templates/react/Form.jsx.tt +122 -0
  56. data/lib/generators/inertia_tw_templates/scaffold/templates/react/Index.jsx.tt +43 -0
  57. data/lib/generators/inertia_tw_templates/scaffold/templates/react/New.jsx.tt +30 -0
  58. data/lib/generators/inertia_tw_templates/scaffold/templates/react/One.jsx.tt +26 -0
  59. data/lib/generators/inertia_tw_templates/scaffold/templates/react/Show.jsx.tt +54 -0
  60. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Edit.svelte.tt +45 -0
  61. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Form.svelte.tt +120 -0
  62. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Index.svelte.tt +49 -0
  63. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/New.svelte.tt +33 -0
  64. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/One.svelte.tt +28 -0
  65. data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Show.svelte.tt +58 -0
  66. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Edit.vue.tt +44 -0
  67. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Form.vue.tt +127 -0
  68. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Index.vue.tt +43 -0
  69. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/New.vue.tt +32 -0
  70. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/One.vue.tt +26 -0
  71. data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Show.vue.tt +56 -0
  72. data/lib/inertia_rails-contrib.rb +3 -0
  73. data/lib/inertia_rails_contrib/generators/controller_template_base.rb +52 -0
  74. data/lib/inertia_rails_contrib/generators/scaffold_template_base.rb +35 -0
  75. data/lib/inertia_rails_contrib/generators_helper.rb +88 -0
  76. data/lib/inertia_rails_contrib/version.rb +5 -0
  77. data/lib/inertia_rails_contrib.rb +8 -0
  78. metadata +153 -0
@@ -0,0 +1,26 @@
1
+ import { Link, Head } from '@inertiajs/react'
2
+ import <%= inertia_component_name %> from './<%= inertia_component_name %>'
3
+
4
+ export default function Index({ <%= plural_table_name %>, flash }) {
5
+ return (
6
+ <>
7
+ <Head title="<%= human_name.pluralize %>" />
8
+
9
+ {flash.notice && <p style={{ color: 'green' }}>{flash.notice}</p>}
10
+
11
+ <h1><%= human_name.pluralize %></h1>
12
+ <div>
13
+ {<%= plural_table_name %>.map((<%= singular_table_name %>) => (
14
+ <div key={<%= singular_table_name %>.id}>
15
+ <<%= inertia_component_name %> <%= singular_table_name %>={<%= singular_table_name %>} />
16
+ <p>
17
+ <Link href={`<%= js_resource_path %>`}>Show this <%= human_name.downcase %></Link>
18
+ </p>
19
+ </div>
20
+ ))}
21
+ </div>
22
+
23
+ <Link href="<%= js_new_resource_path %>">New <%= human_name.downcase %></Link>
24
+ </>
25
+ )
26
+ }
@@ -0,0 +1,27 @@
1
+ import { Link, Head } from '@inertiajs/react'
2
+ import Form from './Form'
3
+
4
+ export default function New({ <%= singular_table_name %> }) {
5
+ return (
6
+ <>
7
+ <Head title="New <%= human_name.downcase %>" />
8
+
9
+ <h1>New <%= 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
+ form.post('<%= js_resources_path %>')
16
+ }}
17
+ submitText="Create <%= human_name.downcase %>"
18
+ />
19
+
20
+ <br />
21
+
22
+ <div>
23
+ <Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
24
+ </div>
25
+ </>
26
+ )
27
+ }
@@ -0,0 +1,26 @@
1
+ export default function <%= inertia_component_name %>({ <%= singular_table_name %> }) {
2
+ return (
3
+ <div>
4
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
5
+ <p>
6
+ <strong><%= attribute.human_name %>:</strong>
7
+ <% if attribute.attachment? -%>
8
+ {<%= singular_table_name %>.<%= attribute.column_name %> && (
9
+ <a href={<%= singular_table_name %>.<%= attribute.column_name %>.url}>{<%= singular_table_name %>.<%= attribute.column_name %>.filename}</a>
10
+ )}
11
+ </p>
12
+ <% elsif attribute.attachments? -%>
13
+ </p>
14
+ {<%= singular_table_name %>.<%= attribute.column_name %>.map((file, i) => (
15
+ <div key={i}>
16
+ <a href={file.url}>{file.filename}</a>
17
+ </div>
18
+ ))}
19
+ <% else -%>
20
+ {<%= singular_table_name %>.<%= attribute.column_name %>.toString()}
21
+ </p>
22
+ <% end -%>
23
+ <% end -%>
24
+ </div>
25
+ )
26
+ }
@@ -0,0 +1,39 @@
1
+ import { Link, Head } from '@inertiajs/react'
2
+ import <%= inertia_component_name %> from './<%= inertia_component_name %>'
3
+
4
+ export default function Show({ <%= singular_table_name %>, flash }) {
5
+ const onDestroy = (e) => {
6
+ if (!confirm('Are you sure you want to delete this <%= human_name.downcase %>?')) {
7
+ e.preventDefault()
8
+ }
9
+ }
10
+
11
+ return (
12
+ <>
13
+ <Head title={`<%= human_name %> #${<%= singular_table_name %>.id}`} />
14
+
15
+ {flash.notice && <p style={{ color: 'green' }}>{flash.notice}</p>}
16
+
17
+ <h1><%= human_name %> #{<%= singular_table_name %>.id}</h1>
18
+
19
+ <<%= inertia_component_name %> <%= singular_table_name %>={<%= singular_table_name %>} />
20
+
21
+ <div>
22
+ <Link href={`<%= js_edit_resource_path %>`}>Edit this <%= human_name.downcase %></Link>
23
+ {' | '}
24
+ <Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
25
+
26
+ <br />
27
+
28
+ <Link
29
+ href={`<%= js_resource_path %>`}
30
+ onClick={onDestroy}
31
+ as="button"
32
+ method="delete"
33
+ >
34
+ Destroy this <%= human_name.downcase %>
35
+ </Link>
36
+ </div>
37
+ </>
38
+ )
39
+ }
@@ -0,0 +1,37 @@
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
+ <h1>Editing <%= human_name.downcase %></h1>
25
+
26
+ <Form
27
+ {<%= singular_table_name %>}
28
+ submitText="Update <%= human_name.downcase %>"
29
+ on:submit={handleSubmit}
30
+ />
31
+
32
+ <br />
33
+
34
+ <div>
35
+ <Link href={`<%= js_resource_path %>`}>Show this <%= human_name.downcase %></Link> |
36
+ <Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
37
+ </div>
@@ -0,0 +1,96 @@
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 on:submit|preventDefault={dispatch('submit', { form: $form })}>
23
+ <% attributes.each do |attribute| -%>
24
+ <% if attribute.password_digest? -%>
25
+ <div>
26
+ <label for="password">Password</label>
27
+ <input
28
+ type="password"
29
+ name="password"
30
+ id="password"
31
+ bind:value={$form.password}
32
+ />
33
+ {#if $form.errors.password}
34
+ <div class="error">{$form.errors.password.join(', ')}</div>
35
+ {/if}
36
+ </div>
37
+
38
+ <div>
39
+ <label for="password_confirmation">Password Confirmation</label>
40
+ <input
41
+ type="password"
42
+ name="password_confirmation"
43
+ id="password_confirmation"
44
+ bind:value={$form.password_confirmation}
45
+ />
46
+ {#if $form.errors.password_confirmation}
47
+ <div class="error">{$form.errors.password_confirmation.join(', ')}</div>
48
+ {/if}
49
+ </div>
50
+ <% else -%>
51
+ <div>
52
+ <label for="<%= attribute.singular_name %>"><%= attribute.human_name %></label>
53
+ <% if input_type(attribute) == "text_area" -%>
54
+ <textarea name="<%= attribute.singular_name %>" id="<%= attribute.singular_name %>" bind:value={$form.<%= attribute.column_name %>} />
55
+ <% elsif attribute.attachment? -%>
56
+ <input
57
+ type="file"
58
+ name="<%= attribute.singular_name %>"
59
+ id="<%= attribute.singular_name %>"
60
+ on:input={(e) => ($form.<%= attribute.column_name %> = e.target.files[0])}
61
+ />
62
+ <% elsif attribute.attachments? -%>
63
+ <input
64
+ type="file"
65
+ multiple="multiple"
66
+ name="<%= attribute.singular_name %>[]"
67
+ id="<%= attribute.singular_name %>"
68
+ on:input={(e) => ($form.<%= attribute.column_name %> = Array.from(e.target.files))}
69
+ />
70
+ <% else -%>
71
+ <input
72
+ type="<%= input_type(attribute) %>"
73
+ name="<%= attribute.singular_name %>"
74
+ id="<%= attribute.singular_name %>"
75
+ bind:value={$form.<%= attribute.column_name %>}
76
+ />
77
+ <% end -%>
78
+ {#if $form.errors.<%= attribute.column_name %>}
79
+ <div class="error">{$form.errors.<%= attribute.column_name %>.join(', ')}</div>
80
+ {/if}
81
+ </div>
82
+ <% end -%>
83
+ <% end -%>
84
+ <div>
85
+ <button type="submit" disabled={$form.processing}>{submitText}</button>
86
+ </div>
87
+ </form>
88
+
89
+ <style>
90
+ label {
91
+ display: block;
92
+ }
93
+ .error {
94
+ color: red;
95
+ }
96
+ </style>
@@ -0,0 +1,42 @@
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
+
8
+ const onDestroy = (e) => {
9
+ if (!confirm('Are you sure you want to delete this <%= human_name.downcase %>?')) {
10
+ e.preventDefault()
11
+ }
12
+ }
13
+ </script>
14
+
15
+ <svelte:head>
16
+ <title><%= human_name.pluralize %></title>
17
+ </svelte:head>
18
+
19
+ {#if flash.notice}
20
+ <p class="notice">{flash.notice}</p>
21
+ {/if}
22
+
23
+ <h1><%= human_name.pluralize %></h1>
24
+
25
+ <div>
26
+ {#each <%= plural_table_name %> as <%= singular_table_name %> (<%= singular_table_name %>.id)}
27
+ <div>
28
+ <<%= inertia_component_name %> {<%= singular_table_name %>} />
29
+ <p>
30
+ <Link href={`<%= js_resource_path %>`}>Show this <%= human_name.downcase %></Link>
31
+ </p>
32
+ </div>
33
+ {/each}
34
+ </div>
35
+
36
+ <Link href="<%= js_new_resource_path %>">New <%= human_name.downcase %></Link>
37
+
38
+ <style>
39
+ .notice {
40
+ color: green;
41
+ }
42
+ </style>
@@ -0,0 +1,30 @@
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
+ form.post('<%= js_resources_path %>')
11
+ }
12
+ </script>
13
+
14
+ <svelte:head>
15
+ <title>New <%= human_name.downcase %></title>
16
+ </svelte:head>
17
+
18
+ <h1>New <%= human_name.downcase %></h1>
19
+
20
+ <Form
21
+ {<%= singular_table_name %>}
22
+ submitText="Create <%= human_name.downcase %>"
23
+ on:submit={handleSubmit}
24
+ />
25
+
26
+ <br />
27
+
28
+ <div>
29
+ <Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
30
+ </div>
@@ -0,0 +1,28 @@
1
+ <script>
2
+ export let <%= singular_table_name %>
3
+ </script>
4
+
5
+ <div>
6
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
7
+ <p>
8
+ <strong><%= 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,46 @@
1
+ <script>
2
+ import { inertia, Link } from '@inertiajs/svelte'
3
+ import <%= inertia_component_name %> from './<%= inertia_component_name %>.svelte'
4
+
5
+ export let <%= singular_table_name %>
6
+ export let flash
7
+
8
+ const onDestroy = (e) => {
9
+ if (!confirm('Are you sure you want to delete this <%= human_name.downcase %>?')) {
10
+ e.preventDefault()
11
+ }
12
+ }
13
+ </script>
14
+
15
+ <svelte:head>
16
+ <title><%= human_name %> #{<%= singular_table_name %>.id}</title>
17
+ </svelte:head>
18
+
19
+ {#if flash.notice}
20
+ <p class="notice">{flash.notice}</p>
21
+ {/if}
22
+
23
+ <h1><%= human_name %> #{<%= singular_table_name %>.id}</h1>
24
+
25
+ <<%= inertia_component_name %> {<%= singular_table_name %>} />
26
+
27
+ <div>
28
+ <Link href={`<%= js_edit_resource_path %>`}>Edit this <%= human_name.downcase %></Link> |
29
+ <Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
30
+
31
+ <br />
32
+
33
+ <button
34
+ use:inertia={{ href: `<%= js_resource_path %>`, method: 'delete' }}
35
+ on:click={onDestroy}
36
+ type="button"
37
+ >
38
+ Destroy this <%= human_name.downcase %>
39
+ </button>
40
+ </div>
41
+
42
+ <style>
43
+ .notice {
44
+ color: green;
45
+ }
46
+ </style>
@@ -0,0 +1,36 @@
1
+ <template>
2
+ <Head title="Editing <%= human_name.downcase %>" />
3
+
4
+ <h1>Editing <%= human_name.downcase %></h1>
5
+
6
+ <Form
7
+ :<%= singular_table_name %>="<%= singular_table_name %>"
8
+ submitText="Update <%= human_name.downcase %>"
9
+ @onSubmit="handleSubmit"
10
+ />
11
+
12
+ <br />
13
+
14
+ <div>
15
+ <Link :href="`<%= js_resource_path %>`">Show this <%= human_name.downcase %></Link> |
16
+ <Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
17
+ </div>
18
+ </template>
19
+
20
+ <script setup>
21
+ import { Link, Head } from '@inertiajs/vue3'
22
+ import Form from './Form.vue'
23
+
24
+ const { <%= singular_table_name %> } = defineProps(['<%= singular_table_name %>'])
25
+
26
+ const handleSubmit = (form) => {
27
+ form.transform((data) => ({ <%= singular_table_name %>: data }))
28
+ <% if attributes.any?(&:attachments?) -%>
29
+ form.post(`<%= js_resource_path %>`, {
30
+ headers: { 'X-HTTP-METHOD-OVERRIDE': 'put' },
31
+ })
32
+ <% else -%>
33
+ form.patch(`<%= js_resource_path %>`)
34
+ <% end -%>
35
+ }
36
+ </script>
@@ -0,0 +1,94 @@
1
+ <template>
2
+ <form @submit.prevent="emit('onSubmit', form)">
3
+ <% attributes.each do |attribute| -%>
4
+ <% if attribute.password_digest? -%>
5
+ <div>
6
+ <label class="label" for="password">Password</label>
7
+ <input
8
+ type="password"
9
+ name="password"
10
+ id="password"
11
+ v-model="form.password"
12
+ />
13
+ <div v-if="form.errors.password" class="error">
14
+ {{ form.errors.password.join(', ') }}
15
+ </div>
16
+ </div>
17
+
18
+ <div>
19
+ <label class="label" for="password_confirmation">
20
+ Password Confirmation
21
+ </label>
22
+ <input
23
+ type="password"
24
+ name="password_confirmation"
25
+ id="password_confirmation"
26
+ v-model="form.password_confirmation"
27
+ />
28
+ <div v-if="form.errors.password_confirmation" class="error">
29
+ {{ form.errors.password_confirmation.join(', ') }}
30
+ </div>
31
+ </div>
32
+ <% else -%>
33
+ <div>
34
+ <label class="label" for="<%= attribute.singular_name %>"><%= attribute.human_name %></label>
35
+ <% if input_type(attribute) == "text_area" -%>
36
+ <textarea name="<%= attribute.singular_name %>" id="<%= attribute.singular_name %>" v-model="form.<%= attribute.column_name %>" />
37
+ <% elsif attribute.attachment? -%>
38
+ <input
39
+ type="file"
40
+ name="<%= attribute.singular_name %>"
41
+ id="<%= attribute.singular_name %>"
42
+ @input="form.<%= attribute.column_name %> = $event.target.files[0]"
43
+ />
44
+ <% elsif attribute.attachments? -%>
45
+ <input
46
+ type="file"
47
+ multiple="multiple"
48
+ name="<%= attribute.singular_name %>[]"
49
+ id="<%= attribute.singular_name %>"
50
+ @input="form.<%= attribute.column_name %> = Array.from($event.target.files)"
51
+ />
52
+ <% else -%>
53
+ <input type="<%= input_type(attribute) %>" name="<%= attribute.singular_name %>" id="<%= attribute.singular_name %>" v-model="form.<%= attribute.column_name %>" />
54
+ <% end -%>
55
+ <div v-if="form.errors.<%= attribute.column_name %>" class="error">
56
+ {{ form.errors.<%= attribute.column_name %>.join(', ') }}
57
+ </div>
58
+ </div>
59
+ <% end -%>
60
+ <% end -%>
61
+ <div>
62
+ <button type="submit" :disabled="form.processing">
63
+ {{ submitText }}
64
+ </button>
65
+ </div>
66
+ </form>
67
+ </template>
68
+
69
+ <script setup>
70
+ import { useForm } from '@inertiajs/vue3'
71
+
72
+ const { <%= singular_table_name %>, submitText } = defineProps(['<%= singular_table_name %>', 'submitText'])
73
+ const emit = defineEmits(['onSubmit'])
74
+
75
+ const form = useForm({
76
+ <% attributes.each do |attribute| -%>
77
+ <% if attribute.password_digest? -%>
78
+ password: '',
79
+ password_confirmation: '',
80
+ <% else -%>
81
+ <%= attribute.column_name %>: <%= singular_table_name %>.<%= attribute.column_name %> || <%= default_value(attribute) %>,
82
+ <% end -%>
83
+ <% end -%>
84
+ })
85
+ </script>
86
+
87
+ <style scoped>
88
+ .label {
89
+ display: block;
90
+ }
91
+ .error {
92
+ color: red;
93
+ }
94
+ </style>
@@ -0,0 +1,31 @@
1
+ <template>
2
+ <Head title="<%= human_name.pluralize %>" />
3
+
4
+ <p v-if="flash.notice" class="notice">{{ flash.notice }}</p>
5
+
6
+ <h1><%= human_name.pluralize %></h1>
7
+
8
+ <div>
9
+ <div v-for="<%= singular_table_name %> in <%= plural_table_name %>" :key="<%= singular_table_name %>.id">
10
+ <<%= inertia_component_name %> :<%= singular_table_name %>="<%= singular_table_name %>" />
11
+ <p>
12
+ <Link :href="`<%= js_resource_path %>`">Show this <%= human_name.downcase %></Link>
13
+ </p>
14
+ </div>
15
+ </div>
16
+
17
+ <Link href="<%= js_new_resource_path %>">New <%= human_name.downcase %></Link>
18
+ </template>
19
+
20
+ <script setup>
21
+ import { Link, Head } from '@inertiajs/vue3'
22
+ import <%= inertia_component_name %> from './<%= inertia_component_name %>.vue'
23
+
24
+ const { <%= plural_table_name %>, flash } = defineProps(['<%= plural_table_name %>', 'flash'])
25
+ </script>
26
+
27
+ <style scoped>
28
+ .notice {
29
+ color: green;
30
+ }
31
+ </style>
@@ -0,0 +1,29 @@
1
+ <template>
2
+ <Head title="New <%= human_name.downcase %>" />
3
+
4
+ <h1>New <%= human_name.downcase %></h1>
5
+
6
+ <Form
7
+ :<%= singular_table_name %>="<%= singular_table_name %>"
8
+ submitText="Create <%= human_name.downcase %>"
9
+ @onSubmit="handleSubmit"
10
+ />
11
+
12
+ <br />
13
+
14
+ <div>
15
+ <Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
16
+ </div>
17
+ </template>
18
+
19
+ <script setup>
20
+ import { Link, Head } from '@inertiajs/vue3'
21
+ import Form from './Form.vue'
22
+
23
+ const { <%= singular_table_name %> } = defineProps(['<%= singular_table_name %>'])
24
+
25
+ const handleSubmit = (form) => {
26
+ form.transform((data) => ({ <%= singular_table_name %>: data }))
27
+ form.post('<%= js_resources_path %>')
28
+ }
29
+ </script>
@@ -0,0 +1,26 @@
1
+ <template>
2
+ <div>
3
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
4
+ <p>
5
+ <strong><%= attribute.human_name %>:</strong>
6
+ <% if attribute.attachment? -%>
7
+ <a v-if="<%= singular_table_name %>.<%= attribute.column_name %>" :href="<%= singular_table_name %>.<%= attribute.column_name %>.url">
8
+ {{ <%= singular_table_name %>.<%= attribute.column_name %>.filename }}
9
+ </a>
10
+ </p>
11
+ <% elsif attribute.attachments? -%>
12
+ </p>
13
+ <div v-for="file in <%= singular_table_name %>.<%= attribute.column_name %>">
14
+ <a :href="file.url">{{ file.filename }}</a>
15
+ </div>
16
+ <% else -%>
17
+ {{ <%= singular_table_name %>.<%= attribute.column_name %> }}
18
+ </p>
19
+ <% end -%>
20
+ <% end -%>
21
+ </div>
22
+ </template>
23
+
24
+ <script setup>
25
+ const { <%= singular_table_name %> } = defineProps(['<%= singular_table_name %>'])
26
+ </script>
@@ -0,0 +1,44 @@
1
+ <template>
2
+ <Head :title="`<%= human_name %> #${<%= singular_table_name %>.id}`" />
3
+
4
+ <p v-if="flash.notice" class="notice">{{ flash.notice }}</p>
5
+
6
+ <h1><%= human_name %> #{{ <%= singular_table_name %>.id }}</h1>
7
+
8
+ <<%= inertia_component_name %> :<%= singular_table_name %>="<%= singular_table_name %>" />
9
+
10
+ <div>
11
+ <Link :href="`<%= js_edit_resource_path %>`">Edit this <%= human_name.downcase %></Link> |
12
+ <Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
13
+
14
+ <br />
15
+
16
+ <Link
17
+ :href="`<%= js_resource_path %>`"
18
+ @click="onDestroy"
19
+ as="button"
20
+ method="delete"
21
+ >
22
+ Destroy this <%= human_name.downcase %>
23
+ </Link>
24
+ </div>
25
+ </template>
26
+
27
+ <script setup>
28
+ import { Link, Head } from '@inertiajs/vue3'
29
+ import <%= inertia_component_name %> from './<%= inertia_component_name %>.vue'
30
+
31
+ const { <%= singular_table_name %>, flash } = defineProps(['<%= singular_table_name %>', 'flash'])
32
+
33
+ const onDestroy = (e) => {
34
+ if (!confirm('Are you sure you want to delete this <%= human_name.downcase %>?')) {
35
+ e.preventDefault()
36
+ }
37
+ }
38
+ </script>
39
+
40
+ <style scoped>
41
+ .notice {
42
+ color: green;
43
+ }
44
+ </style>