Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
skryukov committed Nov 23, 2024
1 parent 6cff2e8 commit 189ffb6
Show file tree
Hide file tree
Showing 61 changed files with 158 additions and 137 deletions.
11 changes: 6 additions & 5 deletions bin/generate_scaffold_example
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ npm_cache = File.join(working_dir, 'npm_cache')
FileUtils.mkdir_p(dir) unless File.directory?(dir)
end

# Clean working directory
FileUtils.rm_r(working_dir) if File.directory?(working_dir)
FileUtils.mkdir_p(working_dir)
app_name = "scaffold_example_#{options[:framework]}"
app_dir = File.join(working_dir, app_name)

# Clean app directory
FileUtils.rm_r(app_dir) if File.directory?(app_dir)
FileUtils.mkdir_p(app_dir)

# Generate a new Rails app
app_name = 'scaffold_example'
app_dir = File.join(working_dir, app_name)
system("rails new #{app_dir} -J")

# Install and configure with caching
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Head } from '@inertiajs/react'
import { useState } from 'react'

import reactSvg from '/assets/react.svg'
import inertiaSvg from '/assets/inertia.svg'
import reactSvg from '/assets/react.svg'
import viteRubySvg from '/assets/vite_ruby.svg'

import cs from './InertiaExample.module.css'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Head } from '@inertiajs/react'
import { useState } from 'react'

import reactSvg from '/assets/react.svg'
import inertiaSvg from '/assets/inertia.svg'
import reactSvg from '/assets/react.svg'
import viteRubySvg from '/assets/vite_ruby.svg'

import cs from './InertiaExample.module.css'
Expand Down
8 changes: 5 additions & 3 deletions lib/generators/inertia/install/templates/react/inertia.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ createInertiaApp({
// progress: false,

resolve: (name) => {
const pages = import.meta.glob('../pages/**/*.jsx', { eager: true })
const pages = import.meta.glob('../pages/**/*.jsx', {
eager: true,
})
const page = pages[`../pages/${name}.jsx`]
if (!page) {
console.error(`Missing Inertia page component: '${name}.jsx'`)
Expand All @@ -35,8 +37,8 @@ createInertiaApp({
} else {
console.error(
'Missing root element.\n\n' +
'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' +
'Consider moving <%%= vite_javascript_tag "inertia" %> to the Inertia-specific layout instead.'
'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' +
'Consider moving <%%= vite_javascript_tag "inertia" %> to the Inertia-specific layout instead.',
)
}
},
Expand Down
16 changes: 11 additions & 5 deletions lib/generators/inertia/install/templates/react/inertia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { createInertiaApp } from '@inertiajs/react'
import { createElement, ReactNode } from 'react'
import { createRoot } from 'react-dom/client'

type ResolvedComponent = { default: ReactNode, layout?: (page: ReactNode) => ReactNode }
// Temporary type definition, until @inertiajs/react provides one
type ResolvedComponent = {
default: ReactNode
layout?: (page: ReactNode) => ReactNode
}

createInertiaApp({
// Set default page title
Expand All @@ -16,7 +20,9 @@ createInertiaApp({
// progress: false,

resolve: (name) => {
const pages = import.meta.glob<ResolvedComponent>('../pages/**/*.tsx', {eager: true})
const pages = import.meta.glob<ResolvedComponent>('../pages/**/*.tsx', {
eager: true,
})
const page = pages[`../pages/${name}.tsx`]
if (!page) {
console.error(`Missing Inertia page component: '${name}.tsx'`)
Expand All @@ -31,14 +37,14 @@ createInertiaApp({
return page
},

setup({el, App, props}) {
setup({ el, App, props }) {
if (el) {
createRoot(el).render(createElement(App, props))
} else {
console.error(
'Missing root element.\n\n' +
'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' +
'Consider moving <%%= vite_typescript_tag "inertia" %> to the Inertia-specific layout instead.'
'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' +
'Consider moving <%%= vite_typescript_tag "inertia" %> to the Inertia-specific layout instead.',
)
}
},
Expand Down
8 changes: 5 additions & 3 deletions lib/generators/inertia/install/templates/svelte/inertia.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ createInertiaApp({
// progress: false,

resolve: (name) => {
const pages = import.meta.glob('../pages/**/*.svelte', { eager: true })
const pages = import.meta.glob('../pages/**/*.svelte', {
eager: true,
})
const page = pages[`../pages/${name}.svelte`]
if (!page) {
console.error(`Missing Inertia page component: '${name}.svelte'`)
Expand All @@ -34,8 +36,8 @@ createInertiaApp({
} else {
console.error(
'Missing root element.\n\n' +
'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' +
'Consider moving <%%= vite_javascript_tag "inertia" %> to the Inertia-specific layout instead.'
'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' +
'Consider moving <%%= vite_javascript_tag "inertia" %> to the Inertia-specific layout instead.',
)
}
},
Expand Down
10 changes: 6 additions & 4 deletions lib/generators/inertia/install/templates/svelte/inertia.ts.tt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ createInertiaApp({
// progress: false,

resolve: (name) => {
const pages = import.meta.glob<ResolvedComponent>('../pages/**/*.svelte', { eager: true })
const pages = import.meta.glob<ResolvedComponent>('../pages/**/*.svelte', {
eager: true,
})
const page = pages[`../pages/${name}.svelte`]
if (!page) {
console.error(`Missing Inertia page component: '${name}.svelte'`)
Expand All @@ -30,13 +32,13 @@ createInertiaApp({

setup({ el, App, props }) {
if (el) {
<%= "// @ts-expect-error 1.3.0 beta contains types mismatch\n" if inertia_resolved_version == Gem::Version.new('1.3.0-beta.2') -%>
<%= " // @ts-expect-error 1.3.0 beta contains types mismatch\n" if inertia_resolved_version == Gem::Version.new('1.3.0-beta.2') -%>
mount(App, { target: el, props })
} else {
console.error(
'Missing root element.\n\n' +
'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' +
'Consider moving <%%= vite_typescript_tag "inertia" %> to the Inertia-specific layout instead.'
'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' +
'Consider moving <%%= vite_typescript_tag "inertia" %> to the Inertia-specific layout instead.',
)
}
},
Expand Down
8 changes: 5 additions & 3 deletions lib/generators/inertia/install/templates/svelte4/inertia.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ createInertiaApp({
// progress: false,

resolve: (name) => {
const pages = import.meta.glob('../pages/**/*.svelte', { eager: true })
const pages = import.meta.glob('../pages/**/*.svelte', {
eager: true,
})
const page = pages[`../pages/${name}.svelte`]
if (!page) {
console.error(`Missing Inertia page component: '${name}.svelte'`)
Expand All @@ -33,8 +35,8 @@ createInertiaApp({
} else {
console.error(
'Missing root element.\n\n' +
'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' +
'Consider moving <%%= vite_javascript_tag "inertia" %> to the Inertia-specific layout instead.'
'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' +
'Consider moving <%%= vite_javascript_tag "inertia" %> to the Inertia-specific layout instead.',
)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ createInertiaApp({
// progress: false,

resolve: (name) => {
const pages = import.meta.glob<ResolvedComponent>('../pages/**/*.svelte', { eager: true })
const pages = import.meta.glob<ResolvedComponent>('../pages/**/*.svelte', {
eager: true,
})
const page = pages[`../pages/${name}.svelte`]
if (!page) {
console.error(`Missing Inertia page component: '${name}.svelte'`)
Expand All @@ -34,8 +36,8 @@ createInertiaApp({
} else {
console.error(
'Missing root element.\n\n' +
'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' +
'Consider moving <%%= vite_javascript_tag "inertia" %> to the Inertia-specific layout instead.'
'If you see this error, it probably means you load Inertia.js on non-Inertia pages.\n' +
'Consider moving <%%= vite_javascript_tag "inertia" %> to the Inertia-specific layout instead.',
)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
import { Head } from '@inertiajs/vue3'
import { ref } from 'vue'
import vueSvg from '/assets/vue.svg'
import inertiaSvg from '/assets/inertia.svg'
import viteRubySvg from '/assets/vite_ruby.svg'
import vueSvg from '/assets/vue.svg'
defineProps({
name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
import { Head } from '@inertiajs/vue3'
import { ref } from 'vue'
import vueSvg from '/assets/vue.svg'
import inertiaSvg from '/assets/inertia.svg'
import viteRubySvg from '/assets/vite_ruby.svg'
import vueSvg from '/assets/vue.svg'
defineProps({
name: String,
Expand Down
4 changes: 3 additions & 1 deletion lib/generators/inertia/install/templates/vue/inertia.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ createInertiaApp({
// progress: false,

resolve: (name) => {
const pages = import.meta.glob('../pages/**/*.vue', { eager: true })
const pages = import.meta.glob('../pages/**/*.vue', {
eager: true,
})
return pages[`../pages/${name}.vue`]

// To use a default layout, import the Layout component
Expand Down
6 changes: 4 additions & 2 deletions lib/generators/inertia/install/templates/vue/inertia.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createInertiaApp } from '@inertiajs/vue3'
import {createApp, DefineComponent, h} from 'vue'
import { createApp, DefineComponent, h } from 'vue'

createInertiaApp({
// Set default page title
Expand All @@ -13,7 +13,9 @@ createInertiaApp({
// progress: false,

resolve: (name) => {
const pages = import.meta.glob<DefineComponent>('../pages/**/*.vue', { eager: true })
const pages = import.meta.glob<DefineComponent>('../pages/**/*.vue', {
eager: true,
})
return pages[`../pages/${name}.vue`]

// To use a default layout, import the Layout component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link, Head } from '@inertiajs/react'
import { Head, Link } from '@inertiajs/react'
import Form from './Form'

export default function Edit({ <%= singular_table_name %> }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link, Head } from '@inertiajs/react'
import { Head, Link } from '@inertiajs/react'
import Form from './Form'
import { <%= inertia_model_type %> } from './types'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FormEvent } from 'react'
import { useForm <%= ', InertiaFormProps ' if inertia_js_version.release == Gem::Version.new('1.3.0') %>} from '@inertiajs/react'
import { <%= inertia_model_type %>, <%= inertia_model_form_type %> } from './types'
import { FormEvent } from 'react'
import { <%= inertia_model_form_type %>, <%= inertia_model_type %> } from './types'
<% if inertia_js_version.release != Gem::Version.new('1.3.0') %>
// Temporary fix for InertiaFormProps not being exported from @inertiajs/react
type InertiaFormProps<TForm extends Record<string, any>> = ReturnType<typeof useForm<TForm>>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link, Head } from '@inertiajs/react'
import { Head, Link } from '@inertiajs/react'
import <%= inertia_component_name %> from './<%= inertia_component_name %>'

export default function Index({ <%= plural_table_name %>, flash }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Link, Head } from '@inertiajs/react'
import { <%= inertia_model_type %> } from './types'
import { Head, Link } from '@inertiajs/react'
import <%= inertia_component_name %> from './<%= inertia_component_name %>'
import { <%= inertia_model_type %> } from './types'

interface IndexProps {
<%= plural_table_name %>: <%= inertia_model_type %>[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link, Head } from '@inertiajs/react'
import { Head, Link } from '@inertiajs/react'
import Form from './Form'

export default function New({ <%= singular_table_name %> }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link, Head } from '@inertiajs/react'
import { Head, Link } from '@inertiajs/react'
import Form from './Form'
import { <%= inertia_model_type %> } from './types'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Link, Head } from '@inertiajs/react'
import { Head, Link } from '@inertiajs/react'
import <%= inertia_component_name %> from './<%= inertia_component_name %>'

export default function Show({ <%= singular_table_name %>, flash }) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Link, Head } from '@inertiajs/react'
import { <%= inertia_model_type %> } from './types'
import { Head, Link } from '@inertiajs/react'
import <%= inertia_component_name %> from './<%= inertia_component_name %>'
import { <%= inertia_model_type %> } from './types'

interface ShowProps {
<%= singular_table_name %>: <%= inertia_model_type %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export interface <%= inertia_model_type %> {
export type <%= inertia_model_form_type %> = Omit<<%= inertia_model_type %>, <%= omit_input_attributes.map { |a| "'#{a}'" }.join(' | ') %>><% if custom_form_attributes.any? -%> & {
<% custom_form_attributes.map do |attribute| -%>
<% if attribute.password_digest? -%>
password: string
password_confirmation: string
password: string
password_confirmation: string
<% elsif attribute.attachment? -%>
<%= attribute.column_name %>?: File
<%= attribute.column_name %>?: File
<% elsif attribute.attachments? -%>
<%= attribute.column_name %>?: File[]
<%= attribute.column_name %>?: File[]
<% end -%>
<% end -%>
}<% end -%>
}<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

const handleSubmit = (e) => {
e.preventDefault()
onSubmit({form: $form })
onSubmit({ form: $form })
}
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

const handleSubmit = (e: SubmitEvent) => {
e.preventDefault()
onSubmit({form: $form })
onSubmit({ form: $form })
}
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export interface <%= inertia_model_type %> {
export type <%= inertia_model_form_type %> = Omit<<%= inertia_model_type %>, <%= omit_input_attributes.map { |a| "'#{a}'" }.join(' | ') %>><% if custom_form_attributes.any? -%> & {
<% custom_form_attributes.map do |attribute| -%>
<% if attribute.password_digest? -%>
password: string
password_confirmation: string
password: string
password_confirmation: string
<% elsif attribute.attachment? -%>
<%= attribute.column_name %>?: File
<%= attribute.column_name %>?: File
<% elsif attribute.attachments? -%>
<%= attribute.column_name %>?: File[]
<%= attribute.column_name %>?: File[]
<% end -%>
<% end -%>
}<% end -%>
}<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export interface <%= inertia_model_type %> {
export type <%= inertia_model_form_type %> = Omit<<%= inertia_model_type %>, <%= omit_input_attributes.map { |a| "'#{a}'" }.join(' | ') %>><% if custom_form_attributes.any? -%> & {
<% custom_form_attributes.map do |attribute| -%>
<% if attribute.password_digest? -%>
password: string
password_confirmation: string
password: string
password_confirmation: string
<% elsif attribute.attachment? -%>
<%= attribute.column_name %>?: File
<%= attribute.column_name %>?: File
<% elsif attribute.attachments? -%>
<%= attribute.column_name %>?: File[]
<%= attribute.column_name %>?: File[]
<% end -%>
<% end -%>
}<% end -%>
}<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
</template>

<script setup lang="ts">
import { Link, Head, InertiaForm } from '@inertiajs/vue3'
import { <%= inertia_model_type %>, <%= inertia_model_form_type %> } from './types'
import { Head, InertiaForm, Link } from '@inertiajs/vue3'
import Form from './Form.vue'
import { <%= inertia_model_form_type %>, <%= inertia_model_type %> } from './types'

const { <%= singular_table_name %> } = defineProps<{ <%= singular_table_name %>: <%= inertia_model_type %> }>()

Expand Down
Loading

0 comments on commit 189ffb6

Please sign in to comment.