Skip to content

Commit

Permalink
gem: fix generators
Browse files Browse the repository at this point in the history
  • Loading branch information
skryukov committed Jun 28, 2024
1 parent 1297825 commit 0299a67
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Installing Inertia's Rails adapter
Adding Inertia's Rails adapter initializer
create config/initializers/inertia_rails.rb
Installing Inertia npm packages
What framework do you want to use with Turbo Mount? [react, vue, svelte] (react)
What framework do you want to use with Inertia? [react, vue, svelte] (react)
run npm add @inertiajs/inertia @inertiajs/react react react-dom from "."

added 6 packages, removed 42 packages, and audited 69 packages in 8s
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/server-side-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Installing Inertia's Rails adapter
Adding Inertia's Rails adapter initializer
create config/initializers/inertia_rails.rb
Installing Inertia npm packages
What framework do you want to use with Turbo Mount? [react, vue, svelte] (react)
What framework do you want to use with Inertia? [react, vue, svelte] (react)
run npm add @inertiajs/inertia @inertiajs/react react react-dom from "."

added 6 packages, removed 42 packages, and audited 69 packages in 8s
Expand Down
35 changes: 20 additions & 15 deletions lib/generators/inertia/install/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class InstallGenerator < Rails::Generators::Base
vite_plugin_import: "import react from '@vitejs/plugin-react'",
vite_plugin_call: "react()",
copy_files: {
"InertiaExample.jsx" => "app/frontend/pages/InertiaExample.jsx",
"InertiaExample.module.css" => "app/frontend/pages/InertiaExample.module.css",
"../assets/react.svg" => "app/frontend/assets/react.svg",
"../assets/inertia.svg" => "app/frontend/assets/inertia.svg",
"../assets/vite_ruby.svg" => "app/frontend/assets/vite_ruby.svg"
"InertiaExample.jsx" => "#{root_path}/pages/InertiaExample.jsx",
"InertiaExample.module.css" => "#{root_path}/pages/InertiaExample.module.css",
"../assets/react.svg" => "#{root_path}/assets/react.svg",
"../assets/inertia.svg" => "#{root_path}/assets/inertia.svg",
"../assets/vite_ruby.svg" => "#{root_path}/assets/vite_ruby.svg"
}
},
"vue" => {
Expand All @@ -25,10 +25,10 @@ class InstallGenerator < Rails::Generators::Base
vite_plugin_import: "import vue from '@vitejs/plugin-vue'",
vite_plugin_call: "vue()",
copy_files: {
"InertiaExample.vue" => "app/frontend/pages/InertiaExample.vue",
"../assets/vue.svg" => "app/frontend/assets/vue.svg",
"../assets/inertia.svg" => "app/frontend/assets/inertia.svg",
"../assets/vite_ruby.svg" => "app/frontend/assets/vite_ruby.svg"
"InertiaExample.vue" => "#{root_path}/pages/InertiaExample.vue",
"../assets/vue.svg" => "#{root_path}/assets/vue.svg",
"../assets/inertia.svg" => "#{root_path}/assets/inertia.svg",
"../assets/vite_ruby.svg" => "#{root_path}/assets/vite_ruby.svg"
}
},
"svelte" => {
Expand All @@ -38,10 +38,10 @@ class InstallGenerator < Rails::Generators::Base
vite_plugin_call: "svelte()",
copy_files: {
"svelte.config.js" => "svelte.config.js",
"InertiaExample.svelte" => "app/frontend/pages/InertiaExample.svelte",
"../assets/svelte.svg" => "app/frontend/assets/svelte.svg",
"../assets/inertia.svg" => "app/frontend/assets/inertia.svg",
"../assets/vite_ruby.svg" => "app/frontend/assets/vite_ruby.svg"
"InertiaExample.svelte" => "#{root_path}/pages/InertiaExample.svelte",
"../assets/svelte.svg" => "#{root_path}/assets/svelte.svg",
"../assets/inertia.svg" => "#{root_path}/assets/inertia.svg",
"../assets/vite_ruby.svg" => "#{root_path}/assets/vite_ruby.svg"
}
}
}
Expand Down Expand Up @@ -86,7 +86,7 @@ def install_inertia
end

say "Copying inertia.js into Vite entrypoints", :blue
template "#{framework}/inertia.js", Rails.root.join("app/frontend/entrypoints/inertia.js").to_s
template "#{framework}/inertia.js", Rails.root.join("#{root_path}/entrypoints/inertia.js").to_s

say "Adding inertia.js script tag to the application layout"
headers = <<-ERB
Expand All @@ -99,6 +99,7 @@ def install_inertia
if framework == "react" && !APPLICATION_LAYOUT.read.include?("vite_react_refresh_tag")
say "Adding Vite React Refresh tag to the application layout"
insert_into_file APPLICATION_LAYOUT.to_s, "<%= vite_react_refresh_tag %>\n ", before: "<%= vite_client_tag %>"
gsub_file APPLICATION_LAYOUT.to_s, /<title>/, "<title inertia>"
end

say "Copying example Inertia controller"
Expand Down Expand Up @@ -144,7 +145,11 @@ def vite_config_path
end

def framework
@framework ||= ask("What framework do you want to use with Turbo Mount?", limited_to: FRAMEWORKS.keys, default: "react")
@framework ||= ask("What framework do you want to use with Inertia?", limited_to: FRAMEWORKS.keys, default: "react")
end

def root_path
(defined?(ViteRuby) ? ViteRuby.config.source_code_dir : "app/frontend")
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ def template_filename
end

def pages_path
"app/frontend/pages"
"#{root_path}/pages"
end

def root_path
(defined?(ViteRuby) ? ViteRuby.config.source_code_dir : "app/frontend")
end

def extension
Expand Down

0 comments on commit 0299a67

Please sign in to comment.