inertia_rails-contrib 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/README.md +3 -2
- data/lib/generators/inertia/install/frameworks.yml +28 -3
- data/lib/generators/inertia/install/install_generator.rb +6 -2
- data/lib/generators/inertia/install/templates/react/inertia.ts +4 -4
- data/lib/generators/inertia/install/templates/svelte/InertiaExample.svelte +3 -7
- data/lib/generators/inertia/install/templates/svelte/InertiaExample.ts.svelte +3 -7
- data/lib/generators/inertia/install/templates/svelte/inertia.js +3 -2
- data/lib/generators/inertia/install/templates/svelte/inertia.ts +7 -9
- 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 +29 -0
- data/lib/generators/inertia/install/templates/svelte4/inertia.ts +29 -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/vue/inertia.ts +3 -3
- data/lib/generators/inertia_templates/controller/templates/svelte4/view.svelte.tt +2 -0
- data/lib/generators/inertia_templates/scaffold/templates/react/Form.jsx.tt +2 -2
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Edit.svelte.tt +3 -4
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Form.svelte.tt +12 -10
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Index.svelte.tt +1 -8
- data/lib/generators/inertia_templates/scaffold/templates/svelte/New.svelte.tt +3 -4
- data/lib/generators/inertia_templates/scaffold/templates/svelte/One.svelte.tt +1 -1
- data/lib/generators/inertia_templates/scaffold/templates/svelte/Show.svelte.tt +4 -9
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Edit.svelte.tt +37 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Form.svelte.tt +96 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Index.svelte.tt +36 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/New.svelte.tt +30 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/One.svelte.tt +28 -0
- data/lib/generators/inertia_templates/scaffold/templates/svelte4/Show.svelte.tt +46 -0
- data/lib/generators/inertia_templates/scaffold/templates/vue/Form.vue.tt +1 -1
- data/lib/generators/inertia_tw_templates/controller/templates/svelte4/view.svelte.tt +2 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/react/Form.jsx.tt +2 -2
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Edit.svelte.tt +3 -4
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Form.svelte.tt +12 -13
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Index.svelte.tt +1 -8
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/New.svelte.tt +3 -4
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/One.svelte.tt +1 -1
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte/Show.svelte.tt +7 -8
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Edit.svelte.tt +45 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Form.svelte.tt +120 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Index.svelte.tt +43 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/New.svelte.tt +33 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/One.svelte.tt +28 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/svelte4/Show.svelte.tt +58 -0
- data/lib/generators/inertia_tw_templates/scaffold/templates/vue/Form.vue.tt +2 -2
- data/lib/inertia_rails_contrib/generators_helper.rb +4 -3
- data/lib/inertia_rails_contrib/version.rb +1 -1
- metadata +24 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27c11a71a3acff524328e14dd27d4265a5365a113a58ae636b6877dbfb294d12
|
4
|
+
data.tar.gz: 8150b80e446aebe35e9e5a58026d2d633ce06c693254c2849229ceeee0f30a1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2c94b176f794229063106b9ca1bd28a73c0b766cb657479bc75656cbc2ef4de74e94a85c61aaa64e1ae20e6659bc5cf9923c1c75fd069f224e0403eb63fab74
|
7
|
+
data.tar.gz: c3030cd27b25dbc309d6e3ea7a2b410563b794724fad3f7043a53d86430ea8b1fae7eb122c62bfdaa69bf9301e0da9fdec7525f114c7e98df825eee0877ff1c5
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning].
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.3.0] - 2024-10-25
|
11
|
+
|
12
|
+
Added:
|
13
|
+
|
14
|
+
- [BREAKING] Svelte 5 support ([@skryukov])
|
15
|
+
- The `--framework=svelte` option now installs Svelte 5
|
16
|
+
- New `--framework=svelte4` option installs Svelte 4
|
17
|
+
- Support for Svelte 5 in the installation generator
|
18
|
+
- Support for Svelte 5 in the scaffold templates
|
19
|
+
|
10
20
|
## [0.2.2] - 2024-10-09
|
11
21
|
|
12
22
|
Added:
|
@@ -62,7 +72,8 @@ Added:
|
|
62
72
|
[@Shaglock]: https://github.com/Shaglock
|
63
73
|
[@skryukov]: https://github.com/skryukov
|
64
74
|
|
65
|
-
[Unreleased]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.
|
75
|
+
[Unreleased]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.3.0...HEAD
|
76
|
+
[0.3.0]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.2.2...v0.3.0
|
66
77
|
[0.2.2]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.2.1...v0.2.2
|
67
78
|
[0.2.1]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.2.0...v0.2.1
|
68
79
|
[0.2.0]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.1.1...v0.2.0
|
data/README.md
CHANGED
@@ -31,7 +31,8 @@ bin/rails generate inertia:install
|
|
31
31
|
|
32
32
|
This command will:
|
33
33
|
- Check for Vite Rails and install it if not present
|
34
|
-
- Ask you to
|
34
|
+
- Ask if you want to use TypeScript
|
35
|
+
- Ask you to choose your preferred frontend framework (React, Vue, Svelte 4, or Svelte 5)
|
35
36
|
- Ask if you want to install Tailwind CSS
|
36
37
|
- Install necessary dependencies
|
37
38
|
- Set up the application to work with Inertia
|
@@ -50,7 +51,7 @@ Vite Rails gem successfully installed
|
|
50
51
|
Vite Rails successfully installed
|
51
52
|
Would you like to use TypeScript? (y/n) y
|
52
53
|
Adding TypeScript support
|
53
|
-
What framework do you want to use with Inertia? [react, vue, svelte] (react)
|
54
|
+
What framework do you want to use with Inertia? [react, vue, svelte4, svelte] (react)
|
54
55
|
run npm add @types/react @types/react-dom typescript --silent from "."
|
55
56
|
Would you like to install Tailwind CSS? (y/n) y
|
56
57
|
Installing Tailwind CSS
|
@@ -47,13 +47,38 @@ vue:
|
|
47
47
|
copy_files_js:
|
48
48
|
"InertiaExample.vue": "%{js_destination_path}/pages/InertiaExample.vue"
|
49
49
|
|
50
|
+
svelte4:
|
51
|
+
inertia_package: "@inertiajs/svelte"
|
52
|
+
packages:
|
53
|
+
- "svelte@4"
|
54
|
+
- "@sveltejs/vite-plugin-svelte@3"
|
55
|
+
packages_ts:
|
56
|
+
- "@tsconfig/svelte@4"
|
57
|
+
- "svelte-check"
|
58
|
+
- "typescript"
|
59
|
+
- "tslib"
|
60
|
+
vite_plugin_import: "import { svelte } from '@sveltejs/vite-plugin-svelte'"
|
61
|
+
vite_plugin_call: "svelte()"
|
62
|
+
copy_files_ts:
|
63
|
+
"InertiaExample.ts.svelte": "%{js_destination_path}/pages/InertiaExample.svelte"
|
64
|
+
"tsconfig.json": "tsconfig.json"
|
65
|
+
"tsconfig.node.json": "tsconfig.node.json"
|
66
|
+
"vite-env.d.ts": "%{js_destination_path}/vite-env.d.ts"
|
67
|
+
copy_files_js:
|
68
|
+
"InertiaExample.svelte": "%{js_destination_path}/pages/InertiaExample.svelte"
|
69
|
+
copy_files:
|
70
|
+
"svelte.config.js": "svelte.config.js"
|
71
|
+
"../assets/svelte.svg": "%{js_destination_path}/assets/svelte.svg"
|
72
|
+
"../assets/inertia.svg": "%{js_destination_path}/assets/inertia.svg"
|
73
|
+
"../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg"
|
74
|
+
|
50
75
|
svelte:
|
51
76
|
inertia_package: "@inertiajs/svelte"
|
52
77
|
packages:
|
53
|
-
- "svelte"
|
54
|
-
- "@sveltejs/vite-plugin-svelte"
|
78
|
+
- "svelte@5"
|
79
|
+
- "@sveltejs/vite-plugin-svelte@4"
|
55
80
|
packages_ts:
|
56
|
-
- "@tsconfig/svelte"
|
81
|
+
- "@tsconfig/svelte@5"
|
57
82
|
- "svelte-check"
|
58
83
|
- "typescript"
|
59
84
|
- "tslib"
|
@@ -99,7 +99,7 @@ module Inertia
|
|
99
99
|
insert_into_file application_layout.to_s, "<%= vite_react_refresh_tag %>\n ", before: "<%= vite_client_tag %>"
|
100
100
|
end
|
101
101
|
|
102
|
-
gsub_file application_layout.to_s, /<title>/, "<title inertia>"
|
102
|
+
gsub_file application_layout.to_s, /<title>/, "<title inertia>" unless svelte?
|
103
103
|
else
|
104
104
|
say_error "Could not find the application layout file. Please add the following tags manually:", :red
|
105
105
|
say_error "- <title>...</title>"
|
@@ -112,7 +112,7 @@ module Inertia
|
|
112
112
|
|
113
113
|
def install_typescript
|
114
114
|
say "Adding TypeScript support"
|
115
|
-
if
|
115
|
+
if svelte? && inertia_resolved_version.release < Gem::Version.new("1.3.0")
|
116
116
|
say "WARNING: @inertiajs/svelte < 1.3.0 does not support TypeScript (resolved version: #{inertia_resolved_version}).", :yellow
|
117
117
|
say "Skipping TypeScript support for @inertiajs/svelte", :yellow
|
118
118
|
@typescript = false
|
@@ -270,6 +270,10 @@ module Inertia
|
|
270
270
|
options[:verbose]
|
271
271
|
end
|
272
272
|
|
273
|
+
def svelte?
|
274
|
+
framework.start_with? "svelte"
|
275
|
+
end
|
276
|
+
|
273
277
|
def inertia_package
|
274
278
|
"#{FRAMEWORKS[framework]["inertia_package"]}@#{options[:inertia_version]}"
|
275
279
|
end
|
@@ -2,7 +2,7 @@ import { createInertiaApp } from '@inertiajs/react'
|
|
2
2
|
import { createElement, ReactNode } from 'react'
|
3
3
|
import { createRoot } from 'react-dom/client'
|
4
4
|
|
5
|
-
type
|
5
|
+
type ResolvedComponent = { default: ReactNode, layout?: (page: ReactNode) => ReactNode }
|
6
6
|
|
7
7
|
createInertiaApp({
|
8
8
|
// Set default page title
|
@@ -16,14 +16,14 @@ createInertiaApp({
|
|
16
16
|
// progress: false,
|
17
17
|
|
18
18
|
resolve: (name) => {
|
19
|
-
const pages = import.meta.glob('../pages/**/*.tsx', { eager: true })
|
20
|
-
return pages[`../pages/${name}.tsx`]
|
19
|
+
const pages = import.meta.glob<ResolvedComponent>('../pages/**/*.tsx', { eager: true })
|
20
|
+
return pages[`../pages/${name}.tsx`]
|
21
21
|
|
22
22
|
// To use a default layout, import the Layout component
|
23
23
|
// and use the following lines.
|
24
24
|
// see https://inertia-rails.netlify.app/guide/pages#default-layouts
|
25
25
|
//
|
26
|
-
// const page = pages[`../pages/${name}.tsx`]
|
26
|
+
// const page = pages[`../pages/${name}.tsx`]
|
27
27
|
// page.default.layout ||= (page) => createElement(Layout, null, page)
|
28
28
|
// return page
|
29
29
|
},
|
@@ -3,13 +3,9 @@
|
|
3
3
|
import inertiaSvg from '/assets/inertia.svg'
|
4
4
|
import viteRubySvg from '/assets/vite_ruby.svg'
|
5
5
|
|
6
|
-
|
6
|
+
let { name } = $props()
|
7
7
|
|
8
|
-
let count = 0
|
9
|
-
|
10
|
-
function handleClick() {
|
11
|
-
count += 1
|
12
|
-
}
|
8
|
+
let count = $state(0)
|
13
9
|
</script>
|
14
10
|
|
15
11
|
<svelte:head>
|
@@ -34,7 +30,7 @@
|
|
34
30
|
<h2>Inertia + Vite Ruby + Svelte</h2>
|
35
31
|
|
36
32
|
<div class="card">
|
37
|
-
<button
|
33
|
+
<button onclick={() => count++}>
|
38
34
|
count is {count}
|
39
35
|
</button>
|
40
36
|
<p>
|
@@ -3,13 +3,9 @@
|
|
3
3
|
import inertiaSvg from '/assets/inertia.svg'
|
4
4
|
import viteRubySvg from '/assets/vite_ruby.svg'
|
5
5
|
|
6
|
-
|
6
|
+
let { name }: { name: string } = $props()
|
7
7
|
|
8
|
-
let count = 0
|
9
|
-
|
10
|
-
function handleClick() {
|
11
|
-
count += 1
|
12
|
-
}
|
8
|
+
let count = $state(0)
|
13
9
|
</script>
|
14
10
|
|
15
11
|
<svelte:head>
|
@@ -34,7 +30,7 @@
|
|
34
30
|
<h2>Inertia + Vite Ruby + Svelte</h2>
|
35
31
|
|
36
32
|
<div class="card">
|
37
|
-
<button
|
33
|
+
<button onclick={() => count++}>
|
38
34
|
count is {count}
|
39
35
|
</button>
|
40
36
|
<p>
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import { createInertiaApp } from '@inertiajs/svelte'
|
2
|
+
import { mount } from 'svelte';
|
2
3
|
|
3
4
|
createInertiaApp({
|
4
5
|
// Set default page title
|
@@ -23,7 +24,7 @@ createInertiaApp({
|
|
23
24
|
// return { default: page.default, layout: page.layout || Layout }
|
24
25
|
},
|
25
26
|
|
26
|
-
setup({ el, App }) {
|
27
|
-
|
27
|
+
setup({ el, App, props }) {
|
28
|
+
mount(App, { target: el, props })
|
28
29
|
},
|
29
30
|
})
|
@@ -1,7 +1,5 @@
|
|
1
|
-
import { createInertiaApp } from '@inertiajs/svelte'
|
2
|
-
import
|
3
|
-
|
4
|
-
type ResolvedComponent = { default: ComponentType, layout?: ComponentType }
|
1
|
+
import { createInertiaApp, type ResolvedComponent } from '@inertiajs/svelte'
|
2
|
+
import { mount } from 'svelte'
|
5
3
|
|
6
4
|
createInertiaApp({
|
7
5
|
// Set default page title
|
@@ -15,18 +13,18 @@ createInertiaApp({
|
|
15
13
|
// progress: false,
|
16
14
|
|
17
15
|
resolve: (name) => {
|
18
|
-
const pages = import.meta.glob('../pages/**/*.svelte', { eager: true })
|
19
|
-
return pages[`../pages/${name}.svelte`]
|
16
|
+
const pages = import.meta.glob<ResolvedComponent>('../pages/**/*.svelte', { eager: true })
|
17
|
+
return pages[`../pages/${name}.svelte`]
|
20
18
|
|
21
19
|
// To use a default layout, import the Layout component
|
22
20
|
// and use the following lines.
|
23
21
|
// see https://inertia-rails.netlify.app/guide/pages#default-layouts
|
24
22
|
//
|
25
|
-
// const page = pages[`../pages/${name}.svelte`]
|
23
|
+
// const page = pages[`../pages/${name}.svelte`]
|
26
24
|
// return { default: page.default, layout: page.layout || Layout }
|
27
25
|
},
|
28
26
|
|
29
|
-
setup({ el, App }) {
|
30
|
-
|
27
|
+
setup({ el, App, props }) {
|
28
|
+
mount(App, { target: el, props })
|
31
29
|
},
|
32
30
|
})
|
@@ -0,0 +1,116 @@
|
|
1
|
+
<script>
|
2
|
+
import svelteSvg from '/assets/svelte.svg'
|
3
|
+
import inertiaSvg from '/assets/inertia.svg'
|
4
|
+
import viteRubySvg from '/assets/vite_ruby.svg'
|
5
|
+
|
6
|
+
export let name
|
7
|
+
|
8
|
+
let count = 0
|
9
|
+
|
10
|
+
function handleClick() {
|
11
|
+
count += 1
|
12
|
+
}
|
13
|
+
</script>
|
14
|
+
|
15
|
+
<svelte:head>
|
16
|
+
<title>Inertia + Vite Ruby + Svelte Example</title>
|
17
|
+
</svelte:head>
|
18
|
+
|
19
|
+
<div class="inertia_example">
|
20
|
+
<h1>Hello {name}!</h1>
|
21
|
+
|
22
|
+
<div>
|
23
|
+
<a href="https://inertia-rails.netlify.app" target="_blank">
|
24
|
+
<img class="logo" src={inertiaSvg} alt="Inertia logo" />
|
25
|
+
</a>
|
26
|
+
<a href="https://vite-ruby.netlify.app" target="_blank">
|
27
|
+
<img class="logo vite" src={viteRubySvg} alt="Vite Ruby logo" />
|
28
|
+
</a>
|
29
|
+
<a href="https://svelte.dev" target="_blank">
|
30
|
+
<img class="logo svelte" src={svelteSvg} alt="Svelte logo" />
|
31
|
+
</a>
|
32
|
+
</div>
|
33
|
+
|
34
|
+
<h2>Inertia + Vite Ruby + Svelte</h2>
|
35
|
+
|
36
|
+
<div class="card">
|
37
|
+
<button on:click={handleClick}>
|
38
|
+
count is {count}
|
39
|
+
</button>
|
40
|
+
<p>
|
41
|
+
Edit <code>app/frontend/pages/InertiaExample.svelte</code> and save to test
|
42
|
+
HMR
|
43
|
+
</p>
|
44
|
+
</div>
|
45
|
+
<p class="read-the-docs">
|
46
|
+
Click on the Inertia, Vite Ruby, and Svelte logos to learn more
|
47
|
+
</p>
|
48
|
+
</div>
|
49
|
+
|
50
|
+
<style>
|
51
|
+
.inertia_example {
|
52
|
+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
53
|
+
line-height: 1.5;
|
54
|
+
font-weight: 400;
|
55
|
+
color: #213547;
|
56
|
+
background-color: #ffffff;
|
57
|
+
max-width: 1280px;
|
58
|
+
margin: 0 auto;
|
59
|
+
padding: 2rem;
|
60
|
+
text-align: center;
|
61
|
+
}
|
62
|
+
|
63
|
+
h1 {
|
64
|
+
font-size: 3.2em;
|
65
|
+
line-height: 1.1;
|
66
|
+
}
|
67
|
+
|
68
|
+
h2 {
|
69
|
+
font-size: 2.6em;
|
70
|
+
line-height: 1.1;
|
71
|
+
}
|
72
|
+
|
73
|
+
button {
|
74
|
+
border-radius: 8px;
|
75
|
+
border: 1px solid transparent;
|
76
|
+
padding: 0.6em 1.2em;
|
77
|
+
font-size: 1em;
|
78
|
+
font-weight: 500;
|
79
|
+
font-family: inherit;
|
80
|
+
background-color: #f9f9f9;
|
81
|
+
cursor: pointer;
|
82
|
+
transition: border-color 0.25s;
|
83
|
+
}
|
84
|
+
button:hover {
|
85
|
+
border-color: #646cff;
|
86
|
+
}
|
87
|
+
button:focus,
|
88
|
+
button:focus-visible {
|
89
|
+
outline: 4px auto -webkit-focus-ring-color;
|
90
|
+
}
|
91
|
+
|
92
|
+
.logo {
|
93
|
+
display: inline-block;
|
94
|
+
height: 6em;
|
95
|
+
padding: 1.5em;
|
96
|
+
will-change: filter;
|
97
|
+
transition: filter 300ms;
|
98
|
+
}
|
99
|
+
.logo:hover {
|
100
|
+
filter: drop-shadow(0 0 2em #646cffaa);
|
101
|
+
}
|
102
|
+
.logo.vite:hover {
|
103
|
+
filter: drop-shadow(0 0 2em #e4023baa);
|
104
|
+
}
|
105
|
+
.logo.svelte:hover {
|
106
|
+
filter: drop-shadow(0 0 2em #ff3e00aa);
|
107
|
+
}
|
108
|
+
|
109
|
+
.card {
|
110
|
+
padding: 2em;
|
111
|
+
}
|
112
|
+
|
113
|
+
.read-the-docs {
|
114
|
+
color: #888;
|
115
|
+
}
|
116
|
+
</style>
|
@@ -0,0 +1,116 @@
|
|
1
|
+
<script lang="ts">
|
2
|
+
import svelteSvg from '/assets/svelte.svg'
|
3
|
+
import inertiaSvg from '/assets/inertia.svg'
|
4
|
+
import viteRubySvg from '/assets/vite_ruby.svg'
|
5
|
+
|
6
|
+
export let name: string
|
7
|
+
|
8
|
+
let count = 0
|
9
|
+
|
10
|
+
function handleClick() {
|
11
|
+
count += 1
|
12
|
+
}
|
13
|
+
</script>
|
14
|
+
|
15
|
+
<svelte:head>
|
16
|
+
<title>Inertia + Vite Ruby + Svelte Example</title>
|
17
|
+
</svelte:head>
|
18
|
+
|
19
|
+
<div class="inertia_example">
|
20
|
+
<h1>Hello {name}!</h1>
|
21
|
+
|
22
|
+
<div>
|
23
|
+
<a href="https://inertia-rails.netlify.app" target="_blank">
|
24
|
+
<img class="logo" src={inertiaSvg} alt="Inertia logo" />
|
25
|
+
</a>
|
26
|
+
<a href="https://vite-ruby.netlify.app" target="_blank">
|
27
|
+
<img class="logo vite" src={viteRubySvg} alt="Vite Ruby logo" />
|
28
|
+
</a>
|
29
|
+
<a href="https://svelte.dev" target="_blank">
|
30
|
+
<img class="logo svelte" src={svelteSvg} alt="Svelte logo" />
|
31
|
+
</a>
|
32
|
+
</div>
|
33
|
+
|
34
|
+
<h2>Inertia + Vite Ruby + Svelte</h2>
|
35
|
+
|
36
|
+
<div class="card">
|
37
|
+
<button on:click={handleClick}>
|
38
|
+
count is {count}
|
39
|
+
</button>
|
40
|
+
<p>
|
41
|
+
Edit <code>app/frontend/pages/InertiaExample.svelte</code> and save to test
|
42
|
+
HMR
|
43
|
+
</p>
|
44
|
+
</div>
|
45
|
+
<p class="read-the-docs">
|
46
|
+
Click on the Inertia, Vite Ruby, and Svelte logos to learn more
|
47
|
+
</p>
|
48
|
+
</div>
|
49
|
+
|
50
|
+
<style>
|
51
|
+
.inertia_example {
|
52
|
+
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
53
|
+
line-height: 1.5;
|
54
|
+
font-weight: 400;
|
55
|
+
color: #213547;
|
56
|
+
background-color: #ffffff;
|
57
|
+
max-width: 1280px;
|
58
|
+
margin: 0 auto;
|
59
|
+
padding: 2rem;
|
60
|
+
text-align: center;
|
61
|
+
}
|
62
|
+
|
63
|
+
h1 {
|
64
|
+
font-size: 3.2em;
|
65
|
+
line-height: 1.1;
|
66
|
+
}
|
67
|
+
|
68
|
+
h2 {
|
69
|
+
font-size: 2.6em;
|
70
|
+
line-height: 1.1;
|
71
|
+
}
|
72
|
+
|
73
|
+
button {
|
74
|
+
border-radius: 8px;
|
75
|
+
border: 1px solid transparent;
|
76
|
+
padding: 0.6em 1.2em;
|
77
|
+
font-size: 1em;
|
78
|
+
font-weight: 500;
|
79
|
+
font-family: inherit;
|
80
|
+
background-color: #f9f9f9;
|
81
|
+
cursor: pointer;
|
82
|
+
transition: border-color 0.25s;
|
83
|
+
}
|
84
|
+
button:hover {
|
85
|
+
border-color: #646cff;
|
86
|
+
}
|
87
|
+
button:focus,
|
88
|
+
button:focus-visible {
|
89
|
+
outline: 4px auto -webkit-focus-ring-color;
|
90
|
+
}
|
91
|
+
|
92
|
+
.logo {
|
93
|
+
display: inline-block;
|
94
|
+
height: 6em;
|
95
|
+
padding: 1.5em;
|
96
|
+
will-change: filter;
|
97
|
+
transition: filter 300ms;
|
98
|
+
}
|
99
|
+
.logo:hover {
|
100
|
+
filter: drop-shadow(0 0 2em #646cffaa);
|
101
|
+
}
|
102
|
+
.logo.vite:hover {
|
103
|
+
filter: drop-shadow(0 0 2em #e4023baa);
|
104
|
+
}
|
105
|
+
.logo.svelte:hover {
|
106
|
+
filter: drop-shadow(0 0 2em #ff3e00aa);
|
107
|
+
}
|
108
|
+
|
109
|
+
.card {
|
110
|
+
padding: 2em;
|
111
|
+
}
|
112
|
+
|
113
|
+
.read-the-docs {
|
114
|
+
color: #888;
|
115
|
+
}
|
116
|
+
</style>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { createInertiaApp } from '@inertiajs/svelte'
|
2
|
+
|
3
|
+
createInertiaApp({
|
4
|
+
// Set default page title
|
5
|
+
// see https://inertia-rails.netlify.app/guide/title-and-meta
|
6
|
+
//
|
7
|
+
// title: title => title ? `${title} - App` : 'App',
|
8
|
+
|
9
|
+
// Disable progress bar
|
10
|
+
//
|
11
|
+
// see https://inertia-rails.netlify.app/guide/progress-indicators
|
12
|
+
// progress: false,
|
13
|
+
|
14
|
+
resolve: (name) => {
|
15
|
+
const pages = import.meta.glob('../pages/**/*.svelte', { eager: true })
|
16
|
+
return pages[`../pages/${name}.svelte`]
|
17
|
+
|
18
|
+
// To use a default layout, import the Layout component
|
19
|
+
// and use the following lines.
|
20
|
+
// see https://inertia-rails.netlify.app/guide/pages#default-layouts
|
21
|
+
//
|
22
|
+
// const page = pages[`../pages/${name}.svelte`]
|
23
|
+
// return { default: page.default, layout: page.layout || Layout }
|
24
|
+
},
|
25
|
+
|
26
|
+
setup({ el, App, props }) {
|
27
|
+
new App({ target: el, props })
|
28
|
+
},
|
29
|
+
})
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { createInertiaApp, type ResolvedComponent } from '@inertiajs/svelte'
|
2
|
+
|
3
|
+
createInertiaApp({
|
4
|
+
// Set default page title
|
5
|
+
// see https://inertia-rails.netlify.app/guide/title-and-meta
|
6
|
+
//
|
7
|
+
// title: title => title ? `${title} - App` : 'App',
|
8
|
+
|
9
|
+
// Disable progress bar
|
10
|
+
//
|
11
|
+
// see https://inertia-rails.netlify.app/guide/progress-indicators
|
12
|
+
// progress: false,
|
13
|
+
|
14
|
+
resolve: (name) => {
|
15
|
+
const pages = import.meta.glob<ResolvedComponent>('../pages/**/*.svelte', { eager: true })
|
16
|
+
return pages[`../pages/${name}.svelte`]
|
17
|
+
|
18
|
+
// To use a default layout, import the Layout component
|
19
|
+
// and use the following lines.
|
20
|
+
// see https://inertia-rails.netlify.app/guide/pages#default-layouts
|
21
|
+
//
|
22
|
+
// const page = pages[`../pages/${name}.svelte`]
|
23
|
+
// return { default: page.default, layout: page.layout || Layout }
|
24
|
+
},
|
25
|
+
|
26
|
+
setup({ el, App, props }) {
|
27
|
+
new App({ target: el, props })
|
28
|
+
},
|
29
|
+
})
|
@@ -0,0 +1,21 @@
|
|
1
|
+
{
|
2
|
+
"extends": "@tsconfig/svelte/tsconfig.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"target": "ESNext",
|
5
|
+
"useDefineForClassFields": true,
|
6
|
+
"module": "ESNext",
|
7
|
+
"resolveJsonModule": true,
|
8
|
+
/**
|
9
|
+
* Typecheck JS in `.svelte` and `.js` files by default.
|
10
|
+
* Disable checkJs if you'd like to use dynamic types in JS.
|
11
|
+
* Note that setting allowJs false does not prevent the use
|
12
|
+
* of JS in `.svelte` files.
|
13
|
+
*/
|
14
|
+
"allowJs": true,
|
15
|
+
"checkJs": true,
|
16
|
+
"isolatedModules": true,
|
17
|
+
"moduleDetection": "force",
|
18
|
+
},
|
19
|
+
"include": ["<%= js_destination_path %>/**/*.ts", "<%= js_destination_path %>/**/*.js", "<%= js_destination_path %>/**/*.svelte"],
|
20
|
+
"references": [{ "path": "./tsconfig.node.json" }]
|
21
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"composite": true,
|
4
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
5
|
+
"skipLibCheck": true,
|
6
|
+
"module": "ESNext",
|
7
|
+
"moduleResolution": "bundler",
|
8
|
+
"strict": true,
|
9
|
+
"noEmit": true,
|
10
|
+
},
|
11
|
+
"include": ["vite.config.ts"]
|
12
|
+
}
|
@@ -13,14 +13,14 @@ createInertiaApp({
|
|
13
13
|
// progress: false,
|
14
14
|
|
15
15
|
resolve: (name) => {
|
16
|
-
const pages = import.meta.glob('../pages/**/*.vue', { eager: true })
|
17
|
-
return pages[`../pages/${name}.vue`]
|
16
|
+
const pages = import.meta.glob<DefineComponent>('../pages/**/*.vue', { eager: true })
|
17
|
+
return pages[`../pages/${name}.vue`]
|
18
18
|
|
19
19
|
// To use a default layout, import the Layout component
|
20
20
|
// and use the following lines.
|
21
21
|
// see https://inertia-rails.netlify.app/guide/pages#default-layouts
|
22
22
|
//
|
23
|
-
// const page = pages[`../pages/${name}.vue`]
|
23
|
+
// const page = pages[`../pages/${name}.vue`]
|
24
24
|
// page.default.layout = page.default.layout || Layout
|
25
25
|
// return page
|
26
26
|
},
|
@@ -73,12 +73,12 @@ export default function Form({ <%= singular_table_name %>, onSubmit, submitText
|
|
73
73
|
<% elsif attribute.attachments? -%>
|
74
74
|
<input
|
75
75
|
type="file"
|
76
|
-
multiple
|
76
|
+
multiple
|
77
77
|
name="<%= attribute.singular_name %>[]"
|
78
78
|
id="<%= attribute.singular_name %>"
|
79
79
|
onChange={(e) => setData('<%= attribute.column_name %>', Array.from(e.target.files))}
|
80
80
|
/>
|
81
|
-
<% elsif attribute
|
81
|
+
<% elsif input_type(attribute) == "checkbox" -%>
|
82
82
|
<input
|
83
83
|
type="<%= input_type(attribute) %>"
|
84
84
|
name="<%= attribute.singular_name %>"
|
@@ -2,10 +2,9 @@
|
|
2
2
|
import { Link } from '@inertiajs/svelte'
|
3
3
|
import Form from './Form.svelte'
|
4
4
|
|
5
|
-
|
5
|
+
let { <%= singular_table_name %> } = $props()
|
6
6
|
|
7
|
-
const handleSubmit = (
|
8
|
-
const { form } = e.detail
|
7
|
+
const handleSubmit = ({ form }) => {
|
9
8
|
form.transform((data) => ({ <%= singular_table_name %>: data }))
|
10
9
|
<% if attributes.any?(&:attachments?) -%>
|
11
10
|
form.post(`<%= js_resource_path %>`, {
|
@@ -26,7 +25,7 @@
|
|
26
25
|
<Form
|
27
26
|
{<%= singular_table_name %>}
|
28
27
|
submitText="Update <%= human_name.downcase %>"
|
29
|
-
|
28
|
+
onSubmit={handleSubmit}
|
30
29
|
/>
|
31
30
|
|
32
31
|
<br />
|