inertia_rails-contrib 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +187 -0
- data/lib/generators/inertia/controller/controller_generator.rb +16 -0
- data/lib/generators/inertia/controller/templates/controller.rb.tt +10 -0
- data/lib/generators/inertia/install/install_generator.rb +151 -0
- data/lib/generators/inertia/install/templates/assets/inertia.svg +1 -0
- data/lib/generators/inertia/install/templates/assets/react.svg +1 -0
- data/lib/generators/inertia/install/templates/assets/svelte.svg +1 -0
- data/lib/generators/inertia/install/templates/assets/vite_ruby.svg +1 -0
- data/lib/generators/inertia/install/templates/assets/vue.svg +1 -0
- data/lib/generators/inertia/install/templates/controller.rb +7 -0
- data/lib/generators/inertia/install/templates/initializer.rb +4 -0
- data/lib/generators/inertia/install/templates/react/InertiaExample.jsx +60 -0
- data/lib/generators/inertia/install/templates/react/InertiaExample.module.css +80 -0
- data/lib/generators/inertia/install/templates/react/inertia.js +34 -0
- data/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte +116 -0
- data/lib/generators/inertia/install/templates/svelte/inertia.js +30 -0
- data/lib/generators/inertia/install/templates/svelte/svelte.config.js +7 -0
- data/lib/generators/inertia/install/templates/vue/InertiaExample.vue +117 -0
- data/lib/generators/inertia/install/templates/vue/inertia.js +33 -0
- data/lib/generators/inertia/scaffold/scaffold_generator.rb +16 -0
- data/lib/generators/inertia/scaffold_controller/scaffold_controller_generator.rb +56 -0
- data/lib/generators/inertia/scaffold_controller/templates/controller.rb.tt +102 -0
- data/lib/generators/inertia_templates/controller/controller_generator.rb +12 -0
- data/lib/generators/inertia_templates/controller/templates/react/view.jsx.tt +8 -0
- data/lib/generators/inertia_templates/controller/templates/svelte/view.svelte.tt +2 -0
- data/lib/generators/inertia_templates/controller/templates/vue/view.vue.tt +4 -0
- data/lib/generators/inertia_templates/scaffold/scaffold_generator.rb +12 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Edit.jsx.tt +36 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Form.jsx.tt +111 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Index.jsx.tt +26 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/New.jsx.tt +27 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/One.jsx.tt +26 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Show.jsx.tt +39 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Edit.svelte.tt +37 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Form.svelte.tt +96 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Index.svelte.tt +42 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/New.svelte.tt +30 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/One.svelte.tt +28 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Show.svelte.tt +46 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Edit.vue.tt +36 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Form.vue.tt +94 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Index.vue.tt +31 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/New.vue.tt +29 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/One.vue.tt +26 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Show.vue.tt +44 -0
- data/lib/generators/inertia_tw_templates/controller/controller_generator.rb +12 -0
- data/lib/generators/inertia_tw_templates/controller/templates/react/view.jsx.tt +8 -0
- data/lib/generators/inertia_tw_templates/controller/templates/svelte/view.svelte.tt +2 -0
- data/lib/generators/inertia_tw_templates/controller/templates/vue/view.vue.tt +4 -0
- data/lib/generators/inertia_tw_templates/scaffold/scaffold_generator.rb +12 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Edit.jsx.tt +43 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Form.jsx.tt +122 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Index.jsx.tt +43 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/New.jsx.tt +30 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/One.jsx.tt +26 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Show.jsx.tt +54 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Edit.svelte.tt +45 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Form.svelte.tt +120 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Index.svelte.tt +49 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/New.svelte.tt +33 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/One.svelte.tt +28 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Show.svelte.tt +58 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Edit.vue.tt +44 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Form.vue.tt +127 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Index.vue.tt +43 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/New.vue.tt +32 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/One.vue.tt +26 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Show.vue.tt +56 -0
- data/lib/inertia_rails-contrib.rb +3 -0
- data/lib/inertia_rails_contrib/generators/controller_template_base.rb +52 -0
- data/lib/inertia_rails_contrib/generators/scaffold_template_base.rb +35 -0
- data/lib/inertia_rails_contrib/generators_helper.rb +88 -0
- data/lib/inertia_rails_contrib/version.rb +5 -0
- data/lib/inertia_rails_contrib.rb +8 -0
- metadata +153 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "inertia_rails_contrib/generators/controller_template_base"
|
4
|
+
|
5
|
+
module InertiaTwTemplates
|
6
|
+
module Generators
|
7
|
+
class ControllerGenerator < InertiaRailsContrib::Generators::ControllerTemplateBase
|
8
|
+
hide!
|
9
|
+
source_root File.expand_path("./templates", __dir__)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "inertia_rails_contrib/generators/scaffold_template_base"
|
4
|
+
|
5
|
+
module InertiaTwTemplates
|
6
|
+
module Generators
|
7
|
+
class ScaffoldGenerator < InertiaRailsContrib::Generators::ScaffoldTemplateBase
|
8
|
+
hide!
|
9
|
+
source_root File.expand_path("./templates", __dir__)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { Link, Head } 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
|
+
<div className="mx-auto md:w-2/3 w-full px-8 pt-8">
|
10
|
+
<h1 className="font-bold text-4xl">Editing <%= human_name.downcase %></h1>
|
11
|
+
|
12
|
+
<Form
|
13
|
+
<%= singular_table_name %>={<%= singular_table_name %>}
|
14
|
+
onSubmit={(form) => {
|
15
|
+
form.transform((data) => ({ <%= singular_table_name %>: data }))
|
16
|
+
<% if attributes.any?(&:attachments?) -%>
|
17
|
+
form.post(`<%= js_resource_path %>`, {
|
18
|
+
headers: { 'X-HTTP-METHOD-OVERRIDE': 'put' },
|
19
|
+
})
|
20
|
+
}}
|
21
|
+
<% else -%>
|
22
|
+
form.patch(`<%= js_resource_path %>`)
|
23
|
+
}
|
24
|
+
<% end -%>
|
25
|
+
submitText="Update <%= human_name.downcase %>"
|
26
|
+
/>
|
27
|
+
|
28
|
+
<Link
|
29
|
+
href={`<%= js_resource_path %>`}
|
30
|
+
className="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
|
31
|
+
>
|
32
|
+
Show this <%= human_name.downcase %>
|
33
|
+
</Link>
|
34
|
+
<Link
|
35
|
+
href="<%= js_resources_path %>"
|
36
|
+
className="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>
|
41
|
+
</>
|
42
|
+
)
|
43
|
+
}
|
@@ -0,0 +1,122 @@
|
|
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} className="contents">
|
23
|
+
<% attributes.each do |attribute| -%>
|
24
|
+
<div className="my-5">
|
25
|
+
<% if attribute.password_digest? -%>
|
26
|
+
<label htmlFor="password">Password</label>
|
27
|
+
<input
|
28
|
+
type="password"
|
29
|
+
name="password"
|
30
|
+
id="password"
|
31
|
+
className="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
|
32
|
+
onChange={(e) => setData('password', e.target.value)}
|
33
|
+
/>
|
34
|
+
{errors.password && (
|
35
|
+
<div className="text-red-500 px-3 py-2 font-medium">
|
36
|
+
{errors.password.join(', ')}
|
37
|
+
</div>
|
38
|
+
)}
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div className="my-5">
|
42
|
+
<label htmlFor="password_confirmation">Password Confirmation</label>
|
43
|
+
<input
|
44
|
+
type="password"
|
45
|
+
name="password_confirmation"
|
46
|
+
id="password_confirmation"
|
47
|
+
className="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
|
48
|
+
onChange={(e) => setData('password_confirmation', e.target.value)}
|
49
|
+
/>
|
50
|
+
{errors.password_confirmation && (
|
51
|
+
<div className="text-red-500 px-3 py-2 font-medium">
|
52
|
+
{errors.password_confirmation.join(', ')}
|
53
|
+
</div>
|
54
|
+
)}
|
55
|
+
<% else -%>
|
56
|
+
<label htmlFor="<%= attribute.singular_name %>"><%= attribute.human_name %></label>
|
57
|
+
<% if input_type(attribute) == "text_area" -%>
|
58
|
+
<textarea
|
59
|
+
name="<%= attribute.singular_name %>"
|
60
|
+
id="<%= attribute.singular_name %>"
|
61
|
+
value={data.<%= attribute.column_name %>}
|
62
|
+
rows="4"
|
63
|
+
className="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
|
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
|
+
className="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
|
72
|
+
onChange={(e) => setData('<%= attribute.column_name %>', e.target.files[0])}
|
73
|
+
/>
|
74
|
+
<% elsif attribute.attachments? -%>
|
75
|
+
<input
|
76
|
+
type="file"
|
77
|
+
multiple="multiple"
|
78
|
+
name="<%= attribute.singular_name %>[]"
|
79
|
+
id="<%= attribute.singular_name %>"
|
80
|
+
className="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
|
81
|
+
onChange={(e) => setData('<%= attribute.column_name %>', Array.from(e.target.files))}
|
82
|
+
/>
|
83
|
+
<% elsif attribute.field_type == :check_box -%>
|
84
|
+
<input
|
85
|
+
type="<%= input_type(attribute) %>"
|
86
|
+
name="<%= attribute.singular_name %>"
|
87
|
+
id="<%= attribute.singular_name %>"
|
88
|
+
checked={!!data.<%= attribute.column_name %>}
|
89
|
+
className="block mt-2 h-5 w-5"
|
90
|
+
onChange={(e) => setData('<%= attribute.column_name %>', e.target.checked)}
|
91
|
+
/>
|
92
|
+
<% else -%>
|
93
|
+
<input
|
94
|
+
type="<%= input_type(attribute) %>"
|
95
|
+
name="<%= attribute.singular_name %>"
|
96
|
+
id="<%= attribute.singular_name %>"
|
97
|
+
value={data.<%= attribute.column_name %>}
|
98
|
+
className="block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full"
|
99
|
+
onChange={(e) => setData('<%= attribute.column_name %>', e.target.value)}
|
100
|
+
/>
|
101
|
+
<% end -%>
|
102
|
+
{errors.<%= attribute.column_name %> && (
|
103
|
+
<div className="text-red-500 px-3 py-2 font-medium">
|
104
|
+
{errors.<%= attribute.column_name %>.join(', ')}
|
105
|
+
</div>
|
106
|
+
)}
|
107
|
+
<% end -%>
|
108
|
+
</div>
|
109
|
+
|
110
|
+
<% end -%>
|
111
|
+
<div className="inline">
|
112
|
+
<button
|
113
|
+
type="submit"
|
114
|
+
disabled={processing}
|
115
|
+
className="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>
|
121
|
+
)
|
122
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { Link, Head } from '@inertiajs/react'
|
2
|
+
import { Fragment } from 'react'
|
3
|
+
import <%= inertia_component_name %> from './<%= inertia_component_name %>'
|
4
|
+
|
5
|
+
export default function Index({ <%= plural_table_name %>, flash }) {
|
6
|
+
return (
|
7
|
+
<>
|
8
|
+
<Head title="<%= human_name.pluralize %>" />
|
9
|
+
<div className="mx-auto md:w-2/3 w-full px-8 pt-8">
|
10
|
+
{flash.notice && (
|
11
|
+
<p className="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block">
|
12
|
+
{flash.notice}
|
13
|
+
</p>
|
14
|
+
)}
|
15
|
+
<div className="flex justify-between items-center">
|
16
|
+
<h1 className="font-bold text-4xl"><%= human_name.pluralize %></h1>
|
17
|
+
<Link
|
18
|
+
href="<%= js_new_resource_path %>"
|
19
|
+
className="rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium"
|
20
|
+
>
|
21
|
+
New <%= human_name.downcase %>
|
22
|
+
</Link>
|
23
|
+
</div>
|
24
|
+
|
25
|
+
<div className="min-w-full">
|
26
|
+
{<%= plural_table_name %>.map((<%= singular_table_name %>) => (
|
27
|
+
<Fragment key={<%= singular_table_name %>.id}>
|
28
|
+
<<%= inertia_component_name %> <%= singular_table_name %>={<%= singular_table_name %>} />
|
29
|
+
<p>
|
30
|
+
<Link
|
31
|
+
href={`<%= js_resource_path %>`}
|
32
|
+
className="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
|
33
|
+
>
|
34
|
+
Show this <%= human_name.downcase %>
|
35
|
+
</Link>
|
36
|
+
</p>
|
37
|
+
</Fragment>
|
38
|
+
))}
|
39
|
+
</div>
|
40
|
+
</div>
|
41
|
+
</>
|
42
|
+
)
|
43
|
+
}
|
@@ -0,0 +1,30 @@
|
|
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
|
+
<div className="mx-auto md:w-2/3 w-full px-8 pt-8">
|
10
|
+
<h1 className="font-bold text-4xl">New <%= human_name.downcase %></h1>
|
11
|
+
|
12
|
+
<Form
|
13
|
+
<%= singular_table_name %>={<%= singular_table_name %>}
|
14
|
+
onSubmit={(form) => {
|
15
|
+
form.transform((data) => ({ <%= singular_table_name %>: data }))
|
16
|
+
form.post('<%= js_resources_path %>')
|
17
|
+
}}
|
18
|
+
submitText="Create <%= human_name.downcase %>"
|
19
|
+
/>
|
20
|
+
|
21
|
+
<Link
|
22
|
+
href="<%= js_resources_path %>"
|
23
|
+
className="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
|
24
|
+
>
|
25
|
+
Back to <%= human_name.pluralize.downcase %>
|
26
|
+
</Link>
|
27
|
+
</div>
|
28
|
+
</>
|
29
|
+
)
|
30
|
+
}
|
@@ -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 className="my-5">
|
6
|
+
<strong className="block font-medium mb-1"><%= 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,54 @@
|
|
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
|
+
<div className="mx-auto md:w-2/3 w-full px-8 pt-8">
|
16
|
+
<div className="mx-auto">
|
17
|
+
{flash.notice && (
|
18
|
+
<p className="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block">
|
19
|
+
{flash.notice}
|
20
|
+
</p>
|
21
|
+
)}
|
22
|
+
|
23
|
+
<h1 className="font-bold text-4xl"><%= human_name %> #{<%= singular_table_name %>.id}</h1>
|
24
|
+
|
25
|
+
<<%= inertia_component_name %> <%= singular_table_name %>={<%= singular_table_name %>} />
|
26
|
+
|
27
|
+
<Link
|
28
|
+
href={`<%= js_edit_resource_path %>`}
|
29
|
+
className="mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
|
30
|
+
>
|
31
|
+
Edit this <%= human_name.downcase %>
|
32
|
+
</Link>
|
33
|
+
<Link
|
34
|
+
href="<%= js_resources_path %>"
|
35
|
+
className="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
|
36
|
+
>
|
37
|
+
Back to <%= human_name.pluralize.downcase %>
|
38
|
+
</Link>
|
39
|
+
<div className="inline-block ml-2">
|
40
|
+
<Link
|
41
|
+
href={`<%= js_resource_path %>`}
|
42
|
+
onClick={onDestroy}
|
43
|
+
as="button"
|
44
|
+
method="delete"
|
45
|
+
className="mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium"
|
46
|
+
>
|
47
|
+
Destroy this <%= human_name.downcase %>
|
48
|
+
</Link>
|
49
|
+
</div>
|
50
|
+
</div>
|
51
|
+
</div>
|
52
|
+
</>
|
53
|
+
)
|
54
|
+
}
|
@@ -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.downcase %>"
|
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,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="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 attribute.field_type == :check_box -%>
|
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,49 @@
|
|
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
|
+
<div class="mx-auto md:w-2/3 w-full px-8 pt-8">
|
20
|
+
{#if flash.notice}
|
21
|
+
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block">
|
22
|
+
{flash.notice}
|
23
|
+
</p>
|
24
|
+
{/if}
|
25
|
+
|
26
|
+
<div class="flex justify-between items-center">
|
27
|
+
<h1 class="font-bold text-4xl"><%= human_name.pluralize %></h1>
|
28
|
+
<Link
|
29
|
+
href="<%= js_new_resource_path %>"
|
30
|
+
class="rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium"
|
31
|
+
>
|
32
|
+
New <%= human_name.downcase %>
|
33
|
+
</Link>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<div class="min-w-full">
|
37
|
+
{#each <%= plural_table_name %> as <%= singular_table_name %> (<%= singular_table_name %>.id)}
|
38
|
+
<<%= inertia_component_name %> {<%= singular_table_name %>} />
|
39
|
+
<p>
|
40
|
+
<Link
|
41
|
+
href={`<%= js_resource_path %>`}
|
42
|
+
class="ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium"
|
43
|
+
>
|
44
|
+
Show this <%= human_name.downcase %>
|
45
|
+
</Link>
|
46
|
+
</p>
|
47
|
+
{/each}
|
48
|
+
</div>
|
49
|
+
</div>
|
@@ -0,0 +1,33 @@
|
|
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
|
+
<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.downcase %>"
|
24
|
+
on:submit={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
|
+
export let <%= singular_table_name %>
|
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>
|