inertia_rails-contrib 0.2.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -1
- data/README.md +12 -133
- data/lib/inertia_rails_contrib/version.rb +1 -1
- metadata +5 -112
- data/lib/generators/inertia/controller/controller_generator.rb +0 -16
- data/lib/generators/inertia/controller/templates/controller.rb.tt +0 -10
- data/lib/generators/inertia/install/frameworks.yml +0 -73
- data/lib/generators/inertia/install/helpers.rb +0 -48
- data/lib/generators/inertia/install/install_generator.rb +0 -282
- data/lib/generators/inertia/install/templates/assets/inertia.svg +0 -1
- data/lib/generators/inertia/install/templates/assets/react.svg +0 -1
- data/lib/generators/inertia/install/templates/assets/svelte.svg +0 -1
- data/lib/generators/inertia/install/templates/assets/vite_ruby.svg +0 -1
- data/lib/generators/inertia/install/templates/assets/vue.svg +0 -1
- data/lib/generators/inertia/install/templates/controller.rb +0 -7
- data/lib/generators/inertia/install/templates/dev +0 -23
- data/lib/generators/inertia/install/templates/initializer.rb +0 -4
- data/lib/generators/inertia/install/templates/react/InertiaExample.jsx +0 -60
- data/lib/generators/inertia/install/templates/react/InertiaExample.module.css +0 -80
- data/lib/generators/inertia/install/templates/react/InertiaExample.tsx +0 -60
- data/lib/generators/inertia/install/templates/react/inertia.js +0 -34
- data/lib/generators/inertia/install/templates/react/inertia.ts +0 -36
- data/lib/generators/inertia/install/templates/react/tsconfig.app.json +0 -27
- data/lib/generators/inertia/install/templates/react/tsconfig.json +0 -11
- data/lib/generators/inertia/install/templates/react/tsconfig.node.json +0 -13
- data/lib/generators/inertia/install/templates/react/vite-env.d.ts +0 -1
- data/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte +0 -116
- data/lib/generators/inertia/install/templates/svelte/InertiaExample.ts.svelte +0 -116
- data/lib/generators/inertia/install/templates/svelte/inertia.js +0 -29
- data/lib/generators/inertia/install/templates/svelte/inertia.ts +0 -32
- data/lib/generators/inertia/install/templates/svelte/svelte.config.js +0 -7
- data/lib/generators/inertia/install/templates/svelte/tsconfig.json +0 -21
- data/lib/generators/inertia/install/templates/svelte/tsconfig.node.json +0 -12
- data/lib/generators/inertia/install/templates/svelte/vite-env.d.ts +0 -2
- data/lib/generators/inertia/install/templates/tailwind/application.css +0 -13
- data/lib/generators/inertia/install/templates/tailwind/postcss.config.js +0 -6
- data/lib/generators/inertia/install/templates/tailwind/tailwind.config.js.tt +0 -18
- data/lib/generators/inertia/install/templates/vue/InertiaExample.ts.vue +0 -117
- data/lib/generators/inertia/install/templates/vue/InertiaExample.vue +0 -117
- data/lib/generators/inertia/install/templates/vue/inertia.js +0 -33
- data/lib/generators/inertia/install/templates/vue/inertia.ts +0 -33
- data/lib/generators/inertia/install/templates/vue/tsconfig.app.json +0 -24
- data/lib/generators/inertia/install/templates/vue/tsconfig.json +0 -11
- data/lib/generators/inertia/install/templates/vue/tsconfig.node.json +0 -22
- data/lib/generators/inertia/install/templates/vue/vite-env.d.ts +0 -1
- data/lib/generators/inertia/scaffold/scaffold_generator.rb +0 -16
- data/lib/generators/inertia/scaffold_controller/scaffold_controller_generator.rb +0 -56
- data/lib/generators/inertia/scaffold_controller/templates/controller.rb.tt +0 -100
- data/lib/generators/inertia_templates/controller/controller_generator.rb +0 -12
- data/lib/generators/inertia_templates/controller/templates/react/view.jsx.tt +0 -8
- data/lib/generators/inertia_templates/controller/templates/svelte/view.svelte.tt +0 -2
- data/lib/generators/inertia_templates/controller/templates/vue/view.vue.tt +0 -4
- data/lib/generators/inertia_templates/scaffold/scaffold_generator.rb +0 -12
- data/lib/generators/inertia_templates/scaffold/templates/react/Edit.jsx.tt +0 -35
- data/lib/generators/inertia_templates/scaffold/templates/react/Form.jsx.tt +0 -111
- data/lib/generators/inertia_templates/scaffold/templates/react/Index.jsx.tt +0 -26
- data/lib/generators/inertia_templates/scaffold/templates/react/New.jsx.tt +0 -27
- data/lib/generators/inertia_templates/scaffold/templates/react/One.jsx.tt +0 -26
- data/lib/generators/inertia_templates/scaffold/templates/react/Show.jsx.tt +0 -39
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Edit.svelte.tt +0 -37
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Form.svelte.tt +0 -96
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Index.svelte.tt +0 -42
- data/lib/generators/inertia_templates/scaffold/templates/svelte/New.svelte.tt +0 -30
- data/lib/generators/inertia_templates/scaffold/templates/svelte/One.svelte.tt +0 -28
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Show.svelte.tt +0 -46
- data/lib/generators/inertia_templates/scaffold/templates/vue/Edit.vue.tt +0 -36
- data/lib/generators/inertia_templates/scaffold/templates/vue/Form.vue.tt +0 -94
- data/lib/generators/inertia_templates/scaffold/templates/vue/Index.vue.tt +0 -31
- data/lib/generators/inertia_templates/scaffold/templates/vue/New.vue.tt +0 -29
- data/lib/generators/inertia_templates/scaffold/templates/vue/One.vue.tt +0 -26
- data/lib/generators/inertia_templates/scaffold/templates/vue/Show.vue.tt +0 -44
- data/lib/generators/inertia_tw_templates/controller/controller_generator.rb +0 -12
- data/lib/generators/inertia_tw_templates/controller/templates/react/view.jsx.tt +0 -8
- data/lib/generators/inertia_tw_templates/controller/templates/svelte/view.svelte.tt +0 -2
- data/lib/generators/inertia_tw_templates/controller/templates/vue/view.vue.tt +0 -4
- data/lib/generators/inertia_tw_templates/scaffold/scaffold_generator.rb +0 -12
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Edit.jsx.tt +0 -42
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Form.jsx.tt +0 -122
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Index.jsx.tt +0 -43
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/New.jsx.tt +0 -30
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/One.jsx.tt +0 -26
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Show.jsx.tt +0 -54
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Edit.svelte.tt +0 -45
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Form.svelte.tt +0 -120
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Index.svelte.tt +0 -49
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/New.svelte.tt +0 -33
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/One.svelte.tt +0 -28
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Show.svelte.tt +0 -58
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Edit.vue.tt +0 -44
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Form.vue.tt +0 -127
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Index.vue.tt +0 -43
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/New.vue.tt +0 -32
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/One.vue.tt +0 -26
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Show.vue.tt +0 -56
- data/lib/inertia_rails_contrib/generators/controller_template_base.rb +0 -56
- data/lib/inertia_rails_contrib/generators/scaffold_template_base.rb +0 -35
- data/lib/inertia_rails_contrib/generators_helper.rb +0 -88
@@ -1,24 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"compilerOptions": {
|
3
|
-
"target": "ES2020",
|
4
|
-
"useDefineForClassFields": true,
|
5
|
-
"module": "ESNext",
|
6
|
-
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
7
|
-
"skipLibCheck": true,
|
8
|
-
|
9
|
-
/* Bundler mode */
|
10
|
-
"moduleResolution": "bundler",
|
11
|
-
"allowImportingTsExtensions": true,
|
12
|
-
"isolatedModules": true,
|
13
|
-
"moduleDetection": "force",
|
14
|
-
"noEmit": true,
|
15
|
-
"jsx": "preserve",
|
16
|
-
|
17
|
-
/* Linting */
|
18
|
-
"strict": true,
|
19
|
-
"noUnusedLocals": true,
|
20
|
-
"noUnusedParameters": true,
|
21
|
-
"noFallthroughCasesInSwitch": true
|
22
|
-
},
|
23
|
-
"include": ["<%= js_destination_path %>/**/*.ts", "<%= js_destination_path %>/**/*.tsx", "<%= js_destination_path %>/**/*.vue"]
|
24
|
-
}
|
@@ -1,22 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"compilerOptions": {
|
3
|
-
"target": "ES2022",
|
4
|
-
"lib": ["ES2023"],
|
5
|
-
"module": "ESNext",
|
6
|
-
"skipLibCheck": true,
|
7
|
-
|
8
|
-
/* Bundler mode */
|
9
|
-
"moduleResolution": "bundler",
|
10
|
-
"allowImportingTsExtensions": true,
|
11
|
-
"isolatedModules": true,
|
12
|
-
"moduleDetection": "force",
|
13
|
-
"noEmit": true,
|
14
|
-
|
15
|
-
/* Linting */
|
16
|
-
"strict": true,
|
17
|
-
"noUnusedLocals": true,
|
18
|
-
"noUnusedParameters": true,
|
19
|
-
"noFallthroughCasesInSwitch": true
|
20
|
-
},
|
21
|
-
"include": ["vite.config.ts"]
|
22
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
/// <reference types="vite/client" />
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rails/generators/rails/resource/resource_generator"
|
4
|
-
|
5
|
-
module Inertia
|
6
|
-
module Generators
|
7
|
-
class ScaffoldGenerator < Rails::Generators::ResourceGenerator # :nodoc:
|
8
|
-
remove_hook_for :resource_controller
|
9
|
-
remove_class_option :actions
|
10
|
-
|
11
|
-
class_option :resource_route, type: :boolean
|
12
|
-
|
13
|
-
hook_for :scaffold_controller, required: true
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require "rails/generators/resource_helpers"
|
2
|
-
require "inertia_rails_contrib/generators_helper"
|
3
|
-
|
4
|
-
module Inertia
|
5
|
-
module Generators
|
6
|
-
# This class is a modified copy of Rails::Generators::ScaffoldControllerGenerator.
|
7
|
-
# We don't use inheritance because some gems (i.e. jsbuilder) monkey-patch it.
|
8
|
-
class ScaffoldControllerGenerator < Rails::Generators::NamedBase
|
9
|
-
include InertiaRailsContrib::GeneratorsHelper
|
10
|
-
include Rails::Generators::ResourceHelpers
|
11
|
-
|
12
|
-
source_root File.expand_path("./templates", __dir__)
|
13
|
-
|
14
|
-
check_class_collision suffix: "Controller"
|
15
|
-
|
16
|
-
class_option :helper, type: :boolean
|
17
|
-
class_option :orm, banner: "NAME", type: :string, required: true,
|
18
|
-
desc: "ORM to generate the controller for"
|
19
|
-
|
20
|
-
class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
|
21
|
-
|
22
|
-
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
23
|
-
|
24
|
-
def create_controller_files
|
25
|
-
template "controller.rb", File.join("app/controllers", controller_class_path, "#{controller_file_name}_controller.rb")
|
26
|
-
end
|
27
|
-
|
28
|
-
hook_for :inertia_templates, as: :scaffold, required: true, default: InertiaRailsContrib::GeneratorsHelper.guess_inertia_template
|
29
|
-
|
30
|
-
hook_for :resource_route, in: :rails, required: true do |route|
|
31
|
-
invoke route unless options.skip_routes?
|
32
|
-
end
|
33
|
-
|
34
|
-
hook_for :test_framework, in: :rails, as: :scaffold
|
35
|
-
|
36
|
-
# Invoke the helper using the controller name (pluralized)
|
37
|
-
hook_for :helper, in: :rails, as: :scaffold do |invoked|
|
38
|
-
invoke invoked, [controller_name]
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def permitted_params
|
44
|
-
attachments, others = attributes_names.partition { |name| attachments?(name) }
|
45
|
-
params = others.map { |name| ":#{name}" }
|
46
|
-
params += attachments.map { |name| "#{name}: []" }
|
47
|
-
params.join(", ")
|
48
|
-
end
|
49
|
-
|
50
|
-
def attachments?(name)
|
51
|
-
attribute = attributes.find { |attr| attr.name == name }
|
52
|
-
attribute&.attachments?
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
<% module_namespacing do -%>
|
2
|
-
class <%= controller_class_name %>Controller < ApplicationController
|
3
|
-
before_action :set_<%= singular_table_name %>, only: %i[ show edit update destroy ]
|
4
|
-
|
5
|
-
<% if regular_class_path.any? -%>
|
6
|
-
wrap_parameters :<%= singular_table_name %>
|
7
|
-
|
8
|
-
<% end -%>
|
9
|
-
inertia_share flash: -> { flash.to_hash }
|
10
|
-
|
11
|
-
# GET <%= route_url %>
|
12
|
-
def index
|
13
|
-
@<%= plural_table_name %> = <%= orm_class.all(class_name) %>
|
14
|
-
render inertia: '<%= "#{inertia_base_path}/Index" %>', props: {
|
15
|
-
<%= plural_table_name %>: @<%= plural_table_name %>.map do |<%= singular_table_name %>|
|
16
|
-
<%= "serialize_#{singular_table_name}" %>(<%= singular_table_name %>)
|
17
|
-
end
|
18
|
-
}
|
19
|
-
end
|
20
|
-
|
21
|
-
# GET <%= route_url %>/1
|
22
|
-
def show
|
23
|
-
render inertia: '<%= "#{inertia_base_path}/Show" %>', props: {
|
24
|
-
<%= singular_table_name %>: <%= "serialize_#{singular_table_name}" %>(@<%= singular_table_name %>)
|
25
|
-
}
|
26
|
-
end
|
27
|
-
|
28
|
-
# GET <%= route_url %>/new
|
29
|
-
def new
|
30
|
-
@<%= singular_table_name %> = <%= orm_class.build(class_name) %>
|
31
|
-
render inertia: '<%= "#{inertia_base_path}/New" %>', props: {
|
32
|
-
<%= singular_table_name %>: <%= "serialize_#{singular_table_name}" %>(@<%= singular_table_name %>)
|
33
|
-
}
|
34
|
-
end
|
35
|
-
|
36
|
-
# GET <%= route_url %>/1/edit
|
37
|
-
def edit
|
38
|
-
render inertia: '<%= "#{inertia_base_path}/Edit" %>', props: {
|
39
|
-
<%= singular_table_name %>: <%= "serialize_#{singular_table_name}" %>(@<%= singular_table_name %>)
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
# POST <%= route_url %>
|
44
|
-
def create
|
45
|
-
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
|
46
|
-
|
47
|
-
if @<%= orm_instance.save %>
|
48
|
-
redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully created.") %>
|
49
|
-
else
|
50
|
-
redirect_to <%= new_helper %>, inertia: { errors: @<%= singular_table_name %>.errors }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# PATCH/PUT <%= route_url %>/1
|
55
|
-
def update
|
56
|
-
if @<%= orm_instance.update("#{singular_table_name}_params") %>
|
57
|
-
redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully updated.") %>
|
58
|
-
else
|
59
|
-
redirect_to <%= edit_helper %>, inertia: { errors: @<%= singular_table_name %>.errors }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# DELETE <%= route_url %>/1
|
64
|
-
def destroy
|
65
|
-
@<%= orm_instance.destroy %>
|
66
|
-
redirect_to <%= index_helper %>_url, notice: <%= %("#{human_name} was successfully destroyed.") %>
|
67
|
-
end
|
68
|
-
|
69
|
-
private
|
70
|
-
# Use callbacks to share common setup or constraints between actions.
|
71
|
-
def set_<%= singular_table_name %>
|
72
|
-
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
73
|
-
end
|
74
|
-
|
75
|
-
# Only allow a list of trusted parameters through.
|
76
|
-
def <%= "#{singular_table_name}_params" %>
|
77
|
-
<%- if attributes_names.empty? -%>
|
78
|
-
params.fetch(:<%= singular_table_name %>, {})
|
79
|
-
<%- else -%>
|
80
|
-
params.require(:<%= singular_table_name %>).permit(<%= permitted_params %>)
|
81
|
-
<%- end -%>
|
82
|
-
end
|
83
|
-
|
84
|
-
def <%= "serialize_#{singular_table_name}" %>(<%= singular_table_name %>)
|
85
|
-
<%= singular_table_name %>.as_json(only: [
|
86
|
-
<%= attributes_to_serialize.map { |attribute| ":#{attribute}" }.join(", ") %>
|
87
|
-
])<%- if attributes.any?(&:attachment?) || attributes.any?(&:attachments?) -%>.tap do |hash|
|
88
|
-
<%- attributes.filter(&:attachment?).map do |attribute| -%>
|
89
|
-
hash["<%= attribute.column_name %>"] = {filename: <%= singular_table_name %>.<%= attribute.column_name %>.filename, url: url_for(<%= singular_table_name %>.<%= attribute.column_name %>)} if <%= singular_table_name %>.<%= attribute.column_name %>.attached?
|
90
|
-
<%- end -%>
|
91
|
-
<%- attributes.filter(&:attachments?).map do |attribute| -%>
|
92
|
-
hash["<%= attribute.column_name %>"] =
|
93
|
-
<%= singular_table_name %>.<%= attribute.column_name %>.flat_map do |file|
|
94
|
-
{filename: file.filename.to_s, url: url_for(file)}
|
95
|
-
end
|
96
|
-
<%- end -%>
|
97
|
-
end<% end %>
|
98
|
-
end
|
99
|
-
end
|
100
|
-
<% end -%>
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "inertia_rails_contrib/generators/controller_template_base"
|
4
|
-
|
5
|
-
module InertiaTemplates
|
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
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "inertia_rails_contrib/generators/scaffold_template_base"
|
4
|
-
|
5
|
-
module InertiaTemplates
|
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
|
@@ -1,35 +0,0 @@
|
|
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
|
-
<h1>Editing <%= human_name.downcase %></h1>
|
10
|
-
|
11
|
-
<Form
|
12
|
-
<%= singular_table_name %>={<%= singular_table_name %>}
|
13
|
-
onSubmit={(form) => {
|
14
|
-
form.transform((data) => ({ <%= singular_table_name %>: data }))
|
15
|
-
<% if attributes.any?(&:attachments?) -%>
|
16
|
-
form.post(`<%= js_resource_path %>`, {
|
17
|
-
headers: { 'X-HTTP-METHOD-OVERRIDE': 'put' },
|
18
|
-
})
|
19
|
-
<% else -%>
|
20
|
-
form.patch(`<%= js_resource_path %>`)
|
21
|
-
<% end -%>
|
22
|
-
}}
|
23
|
-
submitText="Update <%= human_name.downcase %>"
|
24
|
-
/>
|
25
|
-
|
26
|
-
<br />
|
27
|
-
|
28
|
-
<div>
|
29
|
-
<Link href={`<%= js_resource_path %>`}>Show this <%= human_name.downcase %></Link>
|
30
|
-
{' | '}
|
31
|
-
<Link href="<%= js_resources_path %>">Back to <%= human_name.pluralize.downcase %></Link>
|
32
|
-
</div>
|
33
|
-
</>
|
34
|
-
)
|
35
|
-
}
|
@@ -1,111 +0,0 @@
|
|
1
|
-
import { useForm } from '@inertiajs/react'
|
2
|
-
|
3
|
-
export default function Form({ <%= singular_table_name %>, onSubmit, submitText }) {
|
4
|
-
const form = useForm({
|
5
|
-
<% attributes.each do |attribute| -%>
|
6
|
-
<% if attribute.password_digest? -%>
|
7
|
-
password: '',
|
8
|
-
password_confirmation: '',
|
9
|
-
<% else -%>
|
10
|
-
<%= attribute.column_name %>: <%= singular_table_name %>.<%= attribute.column_name %> || <%= default_value(attribute) %>,
|
11
|
-
<% end -%>
|
12
|
-
<% end -%>
|
13
|
-
})
|
14
|
-
const { data, setData, errors, processing } = form
|
15
|
-
|
16
|
-
const handleSubmit = (e) => {
|
17
|
-
e.preventDefault()
|
18
|
-
onSubmit(form)
|
19
|
-
}
|
20
|
-
|
21
|
-
return (
|
22
|
-
<form onSubmit={handleSubmit}>
|
23
|
-
<% attributes.each do |attribute| -%>
|
24
|
-
<% if attribute.password_digest? -%>
|
25
|
-
<div>
|
26
|
-
<label style={{ display: 'block' }} htmlFor="password">
|
27
|
-
Password
|
28
|
-
</label>
|
29
|
-
<input
|
30
|
-
type="password"
|
31
|
-
name="password"
|
32
|
-
id="password"
|
33
|
-
onChange={(e) => setData('password', e.target.value)}
|
34
|
-
/>
|
35
|
-
{errors.password && (
|
36
|
-
<div style={{ color: 'red' }}>{errors.password.join(', ')}</div>
|
37
|
-
)}
|
38
|
-
</div>
|
39
|
-
|
40
|
-
<div>
|
41
|
-
<label style={{ display: 'block' }} htmlFor="password_confirmation">
|
42
|
-
Password Confirmation
|
43
|
-
</label>
|
44
|
-
<input
|
45
|
-
type="password"
|
46
|
-
name="password_confirmation"
|
47
|
-
id="password_confirmation"
|
48
|
-
onChange={(e) => setData('password_confirmation', e.target.value)}
|
49
|
-
/>
|
50
|
-
{errors.password_confirmation && (
|
51
|
-
<div style={{ color: 'red' }}>{errors.password_confirmation.join(', ')}</div>
|
52
|
-
)}
|
53
|
-
</div>
|
54
|
-
<% else -%>
|
55
|
-
<div>
|
56
|
-
<label style={{ display: 'block' }} htmlFor="<%= attribute.singular_name %>">
|
57
|
-
<%= attribute.human_name %>
|
58
|
-
</label>
|
59
|
-
<% if input_type(attribute) == "text_area" -%>
|
60
|
-
<textarea
|
61
|
-
name="<%= attribute.singular_name %>"
|
62
|
-
id="<%= attribute.singular_name %>"
|
63
|
-
value={data.<%= attribute.column_name %>}
|
64
|
-
onChange={(e) => setData('<%= attribute.column_name %>', e.target.value)}
|
65
|
-
/>
|
66
|
-
<% elsif attribute.attachment? -%>
|
67
|
-
<input
|
68
|
-
type="file"
|
69
|
-
name="<%= attribute.singular_name %>"
|
70
|
-
id="<%= attribute.singular_name %>"
|
71
|
-
onChange={(e) => setData('<%= attribute.column_name %>', e.target.files[0])}
|
72
|
-
/>
|
73
|
-
<% elsif attribute.attachments? -%>
|
74
|
-
<input
|
75
|
-
type="file"
|
76
|
-
multiple="multiple"
|
77
|
-
name="<%= attribute.singular_name %>[]"
|
78
|
-
id="<%= attribute.singular_name %>"
|
79
|
-
onChange={(e) => setData('<%= attribute.column_name %>', Array.from(e.target.files))}
|
80
|
-
/>
|
81
|
-
<% elsif attribute.field_type == :check_box -%>
|
82
|
-
<input
|
83
|
-
type="<%= input_type(attribute) %>"
|
84
|
-
name="<%= attribute.singular_name %>"
|
85
|
-
id="<%= attribute.singular_name %>"
|
86
|
-
checked={data.<%= attribute.column_name %>}
|
87
|
-
onChange={(e) => setData('<%= attribute.column_name %>', e.target.checked)}
|
88
|
-
/>
|
89
|
-
<% else -%>
|
90
|
-
<input
|
91
|
-
type="<%= input_type(attribute) %>"
|
92
|
-
name="<%= attribute.singular_name %>"
|
93
|
-
id="<%= attribute.singular_name %>"
|
94
|
-
value={data.<%= attribute.column_name %>}
|
95
|
-
onChange={(e) => setData('<%= attribute.column_name %>', e.target.value)}
|
96
|
-
/>
|
97
|
-
<% end -%>
|
98
|
-
{errors.<%= attribute.column_name %> && (
|
99
|
-
<div style={{ color: 'red' }}>{errors.<%= attribute.column_name %>.join(', ')}</div>
|
100
|
-
)}
|
101
|
-
</div>
|
102
|
-
<% end -%>
|
103
|
-
<% end -%>
|
104
|
-
<div>
|
105
|
-
<button type="submit" disabled={processing}>
|
106
|
-
{submitText}
|
107
|
-
</button>
|
108
|
-
</div>
|
109
|
-
</form>
|
110
|
-
)
|
111
|
-
}
|
@@ -1,26 +0,0 @@
|
|
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
|
-
}
|
@@ -1,27 +0,0 @@
|
|
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
|
-
}
|
@@ -1,26 +0,0 @@
|
|
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
|
-
}
|
@@ -1,39 +0,0 @@
|
|
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
|
-
}
|
@@ -1,37 +0,0 @@
|
|
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>
|