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
3 changes: 3 additions & 0 deletions lib/generators/inertia/install/frameworks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ react:
"InertiaExample.jsx": "%{js_destination_path}/pages/inertia_example/index.jsx"
copy_files:
"InertiaExample.module.css": "%{js_destination_path}/pages/inertia_example/index.module.css"
"../assets/rails.svg": "%{js_destination_path}/assets/rails.svg"
"../assets/react.svg": "%{js_destination_path}/assets/react.svg"
"../assets/inertia.svg": "%{js_destination_path}/assets/inertia.svg"
"../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg"
Expand All @@ -39,6 +40,7 @@ vue:
vite_plugin_import: "import vue from '@vitejs/plugin-vue'"
vite_plugin_call: "vue()"
copy_files:
"../assets/rails.svg": "%{js_destination_path}/assets/rails.svg"
"../assets/vue.svg": "%{js_destination_path}/assets/vue.svg"
"../assets/inertia.svg": "%{js_destination_path}/assets/inertia.svg"
"../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg"
Expand Down Expand Up @@ -76,6 +78,7 @@ svelte:
copy_files_js:
"InertiaExample.svelte": "%{js_destination_path}/pages/inertia_example/index.svelte"
copy_files:
"../assets/rails.svg": "%{js_destination_path}/assets/rails.svg"
"../assets/svelte.svg": "%{js_destination_path}/assets/svelte.svg"
"../assets/inertia.svg": "%{js_destination_path}/assets/inertia.svg"
"../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg"
1 change: 1 addition & 0 deletions lib/generators/inertia/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def install_example_page

say 'Adding a route for the example Inertia controller'
route "get 'inertia-example', to: 'inertia_example#index'"
route "root 'inertia_example#index'" unless File.read(file_path('config/routes.rb')).match?(/^\s*root\s+/)

say 'Copying page assets'
copy_files = FRAMEWORKS[framework]['copy_files'].merge(
Expand Down
9 changes: 9 additions & 0 deletions lib/generators/inertia/install/templates/assets/rails.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion lib/generators/inertia/install/templates/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

class InertiaExampleController < InertiaController
def index
render inertia: { name: params.fetch(:name, 'World') }
render inertia: {
rails_version: Rails.version,
ruby_version: RUBY_DESCRIPTION,
rack_version: Rack.release,
inertia_rails_version: InertiaRails::VERSION,
}
end
end
88 changes: 42 additions & 46 deletions lib/generators/inertia/install/templates/react/InertiaExample.jsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,56 @@
import { Head } from '@inertiajs/react'
import { useState } from 'react'
import { version as react_version } from 'react'

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

import cs from './index.module.css'

export default function InertiaExample({ name }) {
const [count, setCount] = useState(0)

export default function InertiaExample({ rails_version, ruby_version, rack_version, inertia_rails_version }) {
return (
<>
<Head title="Inertia + Vite Ruby + React Example" />

<div className={cs.root}>
<h1 className={cs.h1}>Hello {name}!</h1>

<div>
<a href="https://inertia-rails.dev" target="_blank">
<img className={cs.logo} src={inertiaSvg} alt="Inertia logo" />
</a>
<a href="https://vite-ruby.netlify.app" target="_blank">
<img
className={`${cs.logo} ${cs.vite}`}
src={viteRubySvg}
alt="Vite Ruby logo"
/>
</a>
<a href="https://react.dev" target="_blank">
<img
className={`${cs.logo} ${cs.react}`}
src={reactSvg}
alt="React logo"
/>
</a>
</div>

<h2 className={cs.h2}>Inertia + Vite Ruby + React</h2>

<div className="card">
<button
className={cs.button}
onClick={() => setCount((count) => count + 1)}
>
count is {count}
</button>
<div className={cs.root}>
<Head title="Ruby on Rails + Inertia + React" />

<nav className={cs.subNav}>
<a href="https://rubyonrails.org" target="_blank">
<img className={`${cs.logo} ${cs.rails}`} alt="Ruby on Rails Logo" src={railsSvg} />
</a>
<a href="https://inertia-rails.dev" target="_blank">
<img className={`${cs.logo} ${cs.inertia}`} src={inertiaSvg} alt="Inertia logo" />
</a>
<a href="https://react.dev" target="_blank">
<img
className={`${cs.logo} ${cs.react}`}
src={reactSvg}
alt="React logo"
/>
</a>
</nav>

<div className={cs.footer}>
<div className={cs.card}>
<p>
Edit <code>app/frontend/pages/inertia_example/index.jsx</code> and save to
test HMR
Edit <code><%= js_destination_path %>/pages/inertia_example/index.jsx</code> and save to test <abbr title="Hot Module Replacement">HMR</abbr>.
</p>
</div>
<p className={cs.readTheDocs}>
Click on the Inertia, Vite Ruby, and React logos to learn more
</p>

<ul>
<li>
<ul>
<li><strong>Rails version:</strong> {rails_version}</li>
<li><strong>Rack version:</strong> {rack_version}</li>
</ul>
</li>
<li><strong>Ruby version:</strong> {ruby_version}</li>
<li>
<ul>
<li><strong>Inertia Rails version:</strong> {inertia_rails_version}</li>
<li><strong>React version:</strong> {react_version}</li>
</ul>
</li>
</ul>
</div>
</>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -1,60 +1,52 @@
.root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
box-sizing: border-box;
margin: 0;
padding: 0;
align-items: center;
background-color: #F0E7E9;
background-image: url(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjEwMjQiIHZpZXdCb3g9IjAgMCAxNDQwIDEwMjQiIHdpZHRoPSIxNDQwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Im0xNDQwIDUxMC4wMDA2NDh2LTUxMC4wMDA2NDhoLTE0NDB2Mzg0LjAwMDY0OGM0MTcuMzExOTM5IDEzMS4xNDIxNzkgODkxIDE3MS41MTMgMTQ0MCAxMjZ6IiBmaWxsPSIjZmZmIi8+PC9zdmc+);
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
color: #261B23;
display: flex;
flex-direction: column;
font-family: Sans-Serif;
font-size: calc(0.9em + 0.5vw);
font-style: normal;
font-weight: 400;
color: #213547;
background-color: #ffffff;
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
justify-content: center;
line-height: 1.25;
min-height: 100vh;
text-align: center;
}

.h1 {
font-size: 3.2em;
line-height: 1.1;
}

.h2 {
font-size: 2.6em;
line-height: 1.1;
}

.button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #f9f9f9;
cursor: pointer;
transition: border-color 0.25s;
}
.button:hover {
border-color: #646cff;
}
.button:focus,
.button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
@media (prefers-color-scheme: dark) {
.root {
background-color: #1a1a1a;
background-image: url(data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjEwMjQiIHZpZXdCb3g9IjAgMCAxNDQwIDEwMjQiIHdpZHRoPSIxNDQwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Im0xNDQwIDUxMC4wMDA2NDh2LTUxMC4wMDA2NDhoLTE0NDB2Mzg0LjAwMDY0OGM0MTcuMzExOTM5IDEzMS4xNDIxNzkgODkxIDE3MS41MTMgMTQ0MCAxMjZ6IiBmaWxsPSIjMzMzIi8+PC9zdmc+);
color: #e0e0e0;
}
}

.logo {
display: inline-block;
height: 6em;
height: 9.8vw;
min-height: 130px;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
filter: drop-shadow(0 20px 13px rgb(0 0 0 / 0.03)) drop-shadow(0 8px 5px rgb(0 0 0 / 0.08));
}
.logo:hover {
.logo.inertia:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.vite:hover {
filter: drop-shadow(0 0 2em #e4023baa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}
.logo.rails:hover {
filter: drop-shadow(0 0 2em rgb(211 0 1 / 0.6));
}

@keyframes logo-spin {
from {
Expand All @@ -71,10 +63,40 @@
}
}

@media (prefers-color-scheme: dark) {
.logo {
filter: drop-shadow(0 20px 13px rgb(255 255 255 / 0.03)) drop-shadow(0 8px 5px rgb(255 255 255 / 0.08));
}
}

.card {
padding: 2em;
font-size: 0.7em;
color: #948e90;
}

.footer {
bottom: 0;
left: 0;
margin: 0 2rem 2rem 2rem;
position: absolute;
right: 0;
}

.footer ul {
list-style: none;
}

.footer ul li {
display: inline;
}

.footer ul ul li:after {
content: " | ";
font-weight: 300;
color: #948e90;
}

.read-the-docs {
color: #888;
.footer ul ul li:last-child:after {
content: "";
}
Loading