Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions template/_example_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
route 'root "home#index"'
end

file "#{js_destination_path}/pages/home/home.css", <%= code("shared/example/home.css") %>

case framework
when "react"
file "#{js_destination_path}/pages/home/index.#{component_ext}", <%= code("react/home.tsx") %>
Expand Down
70 changes: 18 additions & 52 deletions template/react/home.tsx.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<% if use_typescript %>
import { Head } from '@inertiajs/react'

import './home.css'

<% if use_typescript %>
interface HomeProps {
rails_version: string
ruby_version: string
Expand All @@ -9,59 +11,23 @@ interface HomeProps {

export default function Home({ rails_version, ruby_version, inertia_rails_version }: HomeProps) {
<% else %>
import { Head } from '@inertiajs/react'

export default function Home({ rails_version, ruby_version, inertia_rails_version }) {
<% end %>
return (
<>
<Head title="Welcome" />
<% if use_tailwind %>
<div className="flex min-h-screen items-center justify-center bg-gray-50">
<div className="mx-auto max-w-md space-y-6 p-8 text-center">
<h1 className="text-4xl font-bold text-gray-900">Welcome to Inertia Rails</h1>
<p className="text-lg text-gray-600">
Your app is ready. Start building something amazing.
</p>
<div className="space-y-2 text-sm text-gray-500">
<p>Rails {rails_version} &middot; Ruby {ruby_version}</p>
<p>Inertia Rails {inertia_rails_version}</p>
</div>
<div className="pt-4">
<a
href="https://inertia-rails.dev"
className="inline-flex items-center rounded-md bg-gray-900 px-4 py-2 text-sm font-medium text-white hover:bg-gray-800"
target="_blank"
rel="noopener noreferrer"
>
Documentation
</a>
</div>
</div>
</div>
<% else %>
<div style={{ display: 'flex', minHeight: '100vh', alignItems: 'center', justifyContent: 'center' }}>
<div style={{ maxWidth: '28rem', margin: '0 auto', padding: '2rem', textAlign: 'center' }}>
<h1 style={{ fontSize: '2rem', fontWeight: 'bold', marginBottom: '1rem' }}>Welcome to Inertia Rails</h1>
<p style={{ color: '#666', marginBottom: '1rem' }}>
Your app is ready. Start building something amazing.
</p>
<p style={{ fontSize: '0.875rem', color: '#999' }}>
Rails {rails_version} &middot; Ruby {ruby_version} &middot; Inertia Rails {inertia_rails_version}
</p>
<div style={{ marginTop: '1.5rem' }}>
<a
href="https://inertia-rails.dev"
style={{ padding: '0.5rem 1rem', backgroundColor: '#111', color: '#fff', borderRadius: '0.375rem', textDecoration: 'none' }}
target="_blank"
rel="noopener noreferrer"
>
Documentation
</a>
</div>
</div>
</div>
<% end %>
</>
<main className="inertia-home">
<Head title="Inertia on Rails" />
<a href="https://inertia-rails.dev" aria-label="Inertia Rails documentation" />
<footer>
<p>
<strong>Rails version:</strong> {rails_version}
</p>
<p>
<strong>Ruby version:</strong> {ruby_version}
</p>
<p>
<strong>Inertia Rails version:</strong> {inertia_rails_version}
</p>
</footer>
</main>
)
}
41 changes: 41 additions & 0 deletions template/shared/example/home.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
body:has(.inertia-home) {
margin: 0;
}

.inertia-home {
display: grid;
grid-template-rows: 1fr auto 1fr;
place-items: center;
min-height: 100svh;
background: radial-gradient(
ellipse 110% 80% at 72% -28%,
white 99.8%,
#eaf0fb 100%
);
color: #202c46;
font:
1.125rem/1.35 system-ui,
sans-serif;
text-align: center;
}

.inertia-home a {
grid-row: 2;
width: clamp(86px, 20vw, 280px);
aspect-ratio: 1;
background: #2563eb
url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 400'%3E%3Cpath fill='white' d='M137.331 117.6H52.4l82.069 82.069L52.4 281.737h84.931L219.4 199.67Zm127.9 0H180.3l82.069 82.069-82.069 82.068h84.931L347.3 199.67Z'/%3E%3C/svg%3E")
center / contain no-repeat;
border-radius: 50%;
box-shadow: 0 8px 18px #1e3a8a24;
}

.inertia-home footer {
grid-row: 3;
align-self: end;
padding: 1.5rem 1rem;
}

.inertia-home p {
margin: 0;
}
60 changes: 13 additions & 47 deletions template/svelte/home.svelte.tt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<% if use_typescript %>
<script lang="ts">
import './home.css'

interface Props {
rails_version: string
ruby_version: string
Expand All @@ -10,57 +12,21 @@
</script>
<% else %>
<script>
import './home.css'

let { rails_version, ruby_version, inertia_rails_version } = $props()
</script>
<% end %>

<svelte:head>
<title>Welcome</title>
<title>Inertia on Rails</title>
</svelte:head>

<% if use_tailwind %>
<div class="flex min-h-screen items-center justify-center bg-gray-50">
<div class="mx-auto max-w-md space-y-6 p-8 text-center">
<h1 class="text-4xl font-bold text-gray-900">Welcome to Inertia Rails</h1>
<p class="text-lg text-gray-600">
Your app is ready. Start building something amazing.
</p>
<div class="space-y-2 text-sm text-gray-500">
<p>Rails {rails_version} &middot; Ruby {ruby_version}</p>
<p>Inertia Rails {inertia_rails_version}</p>
</div>
<div class="pt-4">
<a
href="https://inertia-rails.dev"
class="inline-flex items-center rounded-md bg-gray-900 px-4 py-2 text-sm font-medium text-white hover:bg-gray-800"
target="_blank"
rel="noopener noreferrer"
>
Documentation
</a>
</div>
</div>
</div>
<% else %>
<div style="display: flex; min-height: 100vh; align-items: center; justify-content: center">
<div style="max-width: 28rem; margin: 0 auto; padding: 2rem; text-align: center">
<h1 style="font-size: 2rem; font-weight: bold; margin-bottom: 1rem">Welcome to Inertia Rails</h1>
<p style="color: #666; margin-bottom: 1rem">
Your app is ready. Start building something amazing.
</p>
<p style="font-size: 0.875rem; color: #999">
Rails {rails_version} &middot; Ruby {ruby_version} &middot; Inertia Rails {inertia_rails_version}
</p>
<div style="margin-top: 1.5rem">
<a
href="https://inertia-rails.dev"
style="padding: 0.5rem 1rem; background-color: #111; color: #fff; border-radius: 0.375rem; text-decoration: none"
target="_blank"
rel="noopener noreferrer"
>
Documentation
</a>
</div>
</div>
</div>
<% end %>
<main class="inertia-home">
<a href="https://inertia-rails.dev" aria-label="Inertia Rails documentation"></a>
<footer>
<p><strong>Rails version:</strong> {rails_version}</p>
<p><strong>Ruby version:</strong> {ruby_version}</p>
<p><strong>Inertia Rails version:</strong> {inertia_rails_version}</p>
</footer>
</main>
60 changes: 13 additions & 47 deletions template/vue/home.vue.tt
Original file line number Diff line number Diff line change
@@ -1,57 +1,21 @@
<template>
<Head title="Welcome" />
<% if use_tailwind %>
<div class="flex min-h-screen items-center justify-center bg-gray-50">
<div class="mx-auto max-w-md space-y-6 p-8 text-center">
<h1 class="text-4xl font-bold text-gray-900">Welcome to Inertia Rails</h1>
<p class="text-lg text-gray-600">
Your app is ready. Start building something amazing.
</p>
<div class="space-y-2 text-sm text-gray-500">
<p>Rails {{ rails_version }} &middot; Ruby {{ ruby_version }}</p>
<p>Inertia Rails {{ inertia_rails_version }}</p>
</div>
<div class="pt-4">
<a
href="https://inertia-rails.dev"
class="inline-flex items-center rounded-md bg-gray-900 px-4 py-2 text-sm font-medium text-white hover:bg-gray-800"
target="_blank"
rel="noopener noreferrer"
>
Documentation
</a>
</div>
</div>
</div>
<% else %>
<div style="display: flex; min-height: 100vh; align-items: center; justify-content: center">
<div style="max-width: 28rem; margin: 0 auto; padding: 2rem; text-align: center">
<h1 style="font-size: 2rem; font-weight: bold; margin-bottom: 1rem">Welcome to Inertia Rails</h1>
<p style="color: #666; margin-bottom: 1rem">
Your app is ready. Start building something amazing.
</p>
<p style="font-size: 0.875rem; color: #999">
Rails {{ rails_version }} &middot; Ruby {{ ruby_version }} &middot; Inertia Rails {{ inertia_rails_version }}
</p>
<div style="margin-top: 1.5rem">
<a
href="https://inertia-rails.dev"
style="padding: 0.5rem 1rem; background-color: #111; color: #fff; border-radius: 0.375rem; text-decoration: none"
target="_blank"
rel="noopener noreferrer"
>
Documentation
</a>
</div>
</div>
</div>
<% end %>
<Head title="Inertia on Rails" />
<main class="inertia-home">
<a href="https://inertia-rails.dev" aria-label="Inertia Rails documentation"></a>
<footer>
<p><strong>Rails version:</strong> {{ rails_version }}</p>
<p><strong>Ruby version:</strong> {{ ruby_version }}</p>
<p><strong>Inertia Rails version:</strong> {{ inertia_rails_version }}</p>
</footer>
</main>
</template>

<% if use_typescript %>
<script setup lang="ts">
import { Head } from '@inertiajs/vue3'

import './home.css'

defineProps<{
rails_version: string
ruby_version: string
Expand All @@ -62,6 +26,8 @@ defineProps<{
<script setup>
import { Head } from '@inertiajs/vue3'

import './home.css'

defineProps({
rails_version: String,
ruby_version: String,
Expand Down
10 changes: 7 additions & 3 deletions test/template/example_page_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def test_creates_controller

def test_creates_page_component
run_generator do
assert_file "app/javascript/pages/home/index.tsx"
assert_file_contains "app/javascript/pages/home/index.tsx", "./home.css"
assert_file "app/javascript/pages/home/home.css"
end
end

Expand All @@ -51,7 +52,8 @@ class ExamplePageVueTest < GeneratorTestCase

def test_creates_vue_page_component
run_generator do
assert_file "app/javascript/pages/home/index.vue"
assert_file_contains "app/javascript/pages/home/index.vue", "./home.css"
assert_file "app/javascript/pages/home/home.css"
end
end
end
Expand All @@ -71,7 +73,8 @@ class ExamplePageSvelteTest < GeneratorTestCase

def test_creates_svelte_page_component
run_generator do
assert_file "app/javascript/pages/home/index.svelte"
assert_file_contains "app/javascript/pages/home/index.svelte", "./home.css"
assert_file "app/javascript/pages/home/home.css"
end
end
end
Expand All @@ -90,6 +93,7 @@ class ExamplePageSkippedWithStarterKitTest < GeneratorTestCase

def test_skips_when_starter_kit
run_generator do
refute_file "app/javascript/pages/home/home.css"
refute_file "app/controllers/home_controller.rb"
refute_file "app/javascript/pages/home/index.tsx"
end
Expand Down
Loading