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