inertia_rails-contrib 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -1
- data/README.md +35 -71
- data/lib/generators/inertia/install/frameworks.yml +41 -0
- data/lib/generators/inertia/install/helpers.rb +48 -0
- data/lib/generators/inertia/install/install_generator.rb +169 -86
- data/lib/generators/inertia/install/templates/dev +23 -0
- data/lib/generators/inertia/install/templates/react/inertia.js +1 -1
- data/lib/generators/inertia/install/templates/svelte/inertia.js +1 -1
- data/lib/generators/inertia/install/templates/tailwind/application.css +13 -0
- data/lib/generators/inertia/install/templates/tailwind/postcss.config.js +6 -0
- data/lib/generators/inertia/install/templates/tailwind/tailwind.config.js.tt +18 -0
- data/lib/generators/inertia/install/templates/vue/inertia.js +1 -1
- data/lib/generators/inertia/scaffold_controller/templates/controller.rb.tt +6 -8
- data/lib/inertia_rails_contrib/generators/controller_template_base.rb +5 -1
- data/lib/inertia_rails_contrib/generators_helper.rb +1 -1
- data/lib/inertia_rails_contrib/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e6c5bccb1afe9ba7ccd8366ea492d47c947ec2c5787ca63b871f7303ea1c598
|
4
|
+
data.tar.gz: 3a6eeaabc968804dfc1d2cab8e9a5064332c7e96a6d480e0ae1d34fa4fd5b967
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e275e6b29e124aeb22edf64f676112af27e037b720aafc7e22ea70eddd965491447fbb3a1e40f5f78c6117764c5327e5e809616c66f5603f7f787f9f4f54123
|
7
|
+
data.tar.gz: b419a7c886222c86ee2893c3741e1a6dbea59b47144723c7f187bb1ce386edbd551ad6df68eac99368db80566cd75f64256be087a04375ec6447b8f3b83dac46
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning].
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.2.1] - 2024-08-11
|
11
|
+
|
12
|
+
Added:
|
13
|
+
|
14
|
+
- Support `pnpm` package manager ([@skryukov])
|
15
|
+
- New `--verbose` option for the installation generator ([@skryukov])
|
16
|
+
|
17
|
+
Fixed:
|
18
|
+
|
19
|
+
- Support installation alongside Webpacker ([@skryukov])
|
20
|
+
|
21
|
+
## [0.2.0] - 2024-08-10
|
22
|
+
|
23
|
+
Added:
|
24
|
+
|
25
|
+
- Improve installation generator ([@skryukov])
|
26
|
+
- option to install Vite Rails gem (`--install-vite`)
|
27
|
+
- option to install Tailwind CSS (`--install-tailwind`)
|
28
|
+
- option to install without interactivity (`--no-interaction` & `--framework=react|vue|svelte`)
|
29
|
+
- option to skip example page generation (`--no-example-page`)
|
30
|
+
- option to choose package manager (`--package-manager=yarn|npm|bun`)
|
31
|
+
- generate `bin/dev`
|
32
|
+
|
10
33
|
## [0.1.1] - 2024-06-17
|
11
34
|
|
12
35
|
### Fixed:
|
@@ -20,7 +43,10 @@ and this project adheres to [Semantic Versioning].
|
|
20
43
|
[@iurev]: https://github.com/iurev
|
21
44
|
[@skryukov]: https://github.com/skryukov
|
22
45
|
|
23
|
-
[Unreleased]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.1
|
46
|
+
[Unreleased]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.2.1...HEAD
|
47
|
+
[0.2.1]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.2.0...v0.2.1
|
48
|
+
[0.2.0]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.1.1...v0.2.0
|
49
|
+
[0.1.1]: https://github.com/skryukov/inertia_rails-contrib/compare/v0.1.0...v0.1.1
|
24
50
|
[0.1.0]: https://github.com/skryukov/inertia_rails-contrib/commits/v0.1.0
|
25
51
|
|
26
52
|
[Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
|
data/README.md
CHANGED
@@ -20,40 +20,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
20
20
|
|
21
21
|
### Installation generator
|
22
22
|
|
23
|
-
`InertiaRailsContrib` comes with a generator that installs and sets up Inertia in a Rails application.
|
24
|
-
|
25
|
-
<details>
|
26
|
-
<summary>Creating a new Rails application and configuring Vite</summary>
|
27
|
-
|
28
|
-
This is actually a simple process. First, create a new Rails application:
|
29
|
-
```bash
|
30
|
-
rails new myapp --skip-js
|
31
|
-
```
|
32
|
-
|
33
|
-
Next, install the Vite Ruby gem:
|
34
|
-
|
35
|
-
```bash
|
36
|
-
bundle add vite_ruby
|
37
|
-
bundle exec vite install
|
38
|
-
```
|
39
|
-
|
40
|
-
If you use macOS, you may need to edit the `config/vite.rb` file to add the following line:
|
41
|
-
|
42
|
-
```json
|
43
|
-
{
|
44
|
-
"development": {
|
45
|
-
+ "host": "127.0.0.1",
|
46
|
-
"autoBuild": true,
|
47
|
-
"publicOutputDir": "vite-dev",
|
48
|
-
"port": 3036
|
49
|
-
}
|
50
|
-
}
|
51
|
-
```
|
52
|
-
|
53
|
-
That's it! Vite is now installed and configured in the Rails application. For more information, refer to the [Vite Ruby documentation](https://vite-ruby.netlify.app) and the [Vite-lizing Rails: get live reload and hot replacement with Vite Ruby](https://evilmartians.com/chronicles/vite-lizing-rails-get-live-reload-and-hot-replacement-with-vite-ruby) article.
|
54
|
-
|
55
|
-
The next step is to install Inertia!
|
56
|
-
</details>
|
23
|
+
`InertiaRailsContrib` comes with a generator that installs and sets up Inertia in a Rails application. It automatically detects if the [Vite Rails](https://vite-ruby.netlify.app/guide/rails.html) gem is installed and will attempt to install it if not present.
|
57
24
|
|
58
25
|
To install and setup Inertia in a Rails application, execute the following command in the terminal:
|
59
26
|
|
@@ -62,73 +29,70 @@ bundle add inertia_rails-contrib
|
|
62
29
|
bin/rails generate inertia:install
|
63
30
|
```
|
64
31
|
|
65
|
-
This command will
|
32
|
+
This command will:
|
33
|
+
- Check for Vite Rails and install it if not present
|
34
|
+
- Ask you to choose your preferred frontend framework (React, Vue, or Svelte)
|
35
|
+
- Ask if you want to install Tailwind CSS
|
36
|
+
- Install necessary dependencies
|
37
|
+
- Set up the application to work with Inertia
|
38
|
+
- Copy example Inertia controller and views (can be skipped with the `--skip-example` option)
|
66
39
|
|
67
40
|
Example output:
|
68
41
|
|
69
42
|
```bash
|
70
43
|
$ bin/rails generate inertia:install
|
71
|
-
|
72
44
|
Installing Inertia's Rails adapter
|
45
|
+
Could not find a package.json file to install Inertia to.
|
46
|
+
Would you like to install Vite Ruby? (y/n) y
|
47
|
+
run bundle add vite_rails from "."
|
48
|
+
Vite Rails gem successfully installed
|
49
|
+
run bundle exec vite install from "."
|
50
|
+
Vite Rails successfully installed
|
51
|
+
Would you like to install Tailwind CSS? (y/n) y
|
52
|
+
Installing Tailwind CSS
|
53
|
+
run npm add tailwindcss postcss autoprefixer @tailwindcss/forms @tailwindcss/typography @tailwindcss/container-queries --silent from "."
|
54
|
+
create tailwind.config.js
|
55
|
+
create postcss.config.js
|
56
|
+
create app/frontend/entrypoints/application.css
|
57
|
+
Adding Tailwind CSS to the application layout
|
58
|
+
insert app/views/layouts/application.html.erb
|
73
59
|
Adding Inertia's Rails adapter initializer
|
74
60
|
create config/initializers/inertia_rails.rb
|
75
61
|
Installing Inertia npm packages
|
76
|
-
What framework do you want to use with
|
77
|
-
run npm add @inertiajs/
|
78
|
-
|
79
|
-
added 6 packages, removed 42 packages, and audited 69 packages in 8s
|
80
|
-
|
81
|
-
18 packages are looking for funding
|
82
|
-
run `npm fund` for details
|
83
|
-
|
84
|
-
2 moderate severity vulnerabilities
|
85
|
-
|
86
|
-
Some issues need review, and may require choosing
|
87
|
-
a different dependency.
|
88
|
-
|
89
|
-
Run `npm audit` for details.
|
90
|
-
run npm add --save-dev @vitejs/plugin-react from "."
|
91
|
-
|
92
|
-
added 58 packages, and audited 127 packages in 6s
|
93
|
-
|
94
|
-
22 packages are looking for funding
|
95
|
-
run `npm fund` for details
|
96
|
-
|
97
|
-
2 moderate severity vulnerabilities
|
98
|
-
|
99
|
-
Some issues need review, and may require choosing
|
100
|
-
a different dependency.
|
101
|
-
|
102
|
-
Run `npm audit` for details.
|
62
|
+
What framework do you want to use with Inertia? [react, vue, svelte] (react)
|
63
|
+
run npm add @inertiajs/react react react-dom @vitejs/plugin-react --silent from "."
|
103
64
|
Adding Vite plugin for react
|
104
65
|
insert vite.config.ts
|
105
66
|
prepend vite.config.ts
|
106
|
-
|
107
|
-
gsub package.json
|
108
|
-
Copying inertia.js into Vite entrypoints
|
67
|
+
Copying inertia.js entrypoint
|
109
68
|
create app/frontend/entrypoints/inertia.js
|
110
69
|
Adding inertia.js script tag to the application layout
|
111
70
|
insert app/views/layouts/application.html.erb
|
112
71
|
Adding Vite React Refresh tag to the application layout
|
113
72
|
insert app/views/layouts/application.html.erb
|
73
|
+
gsub app/views/layouts/application.html.erb
|
114
74
|
Copying example Inertia controller
|
115
75
|
create app/controllers/inertia_example_controller.rb
|
116
76
|
Adding a route for the example Inertia controller
|
117
77
|
route get 'inertia-example', to: 'inertia_example#index'
|
118
|
-
Copying
|
78
|
+
Copying page assets
|
119
79
|
create app/frontend/pages/InertiaExample.jsx
|
80
|
+
create app/frontend/pages/InertiaExample.module.css
|
81
|
+
create app/frontend/assets/react.svg
|
82
|
+
create app/frontend/assets/inertia.svg
|
83
|
+
create app/frontend/assets/vite_ruby.svg
|
84
|
+
Copying bin/dev
|
85
|
+
create bin/dev
|
120
86
|
Inertia's Rails adapter successfully installed
|
121
87
|
```
|
122
88
|
|
123
89
|
With that done, you can now start the Rails server and the Vite development server (we recommend using [Overmind](https://github.com/DarthSim/overmind)):
|
124
90
|
|
125
91
|
```bash
|
126
|
-
|
127
|
-
# or
|
128
|
-
foreman start -f Procfile.dev
|
92
|
+
bin/dev
|
129
93
|
```
|
130
94
|
|
131
|
-
And navigate to `http://
|
95
|
+
And navigate to `http://localhost:3100/inertia-example` to see the example Inertia page.
|
132
96
|
|
133
97
|
### Scaffold generator
|
134
98
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
react:
|
2
|
+
packages:
|
3
|
+
- "@inertiajs/react"
|
4
|
+
- "react"
|
5
|
+
- "react-dom"
|
6
|
+
- "@vitejs/plugin-react"
|
7
|
+
vite_plugin_import: "import react from '@vitejs/plugin-react'"
|
8
|
+
vite_plugin_call: "react()"
|
9
|
+
copy_files:
|
10
|
+
"InertiaExample.jsx": "%{js_destination_path}/pages/InertiaExample.jsx"
|
11
|
+
"InertiaExample.module.css": "%{js_destination_path}/pages/InertiaExample.module.css"
|
12
|
+
"../assets/react.svg": "%{js_destination_path}/assets/react.svg"
|
13
|
+
"../assets/inertia.svg": "%{js_destination_path}/assets/inertia.svg"
|
14
|
+
"../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg"
|
15
|
+
|
16
|
+
vue:
|
17
|
+
packages:
|
18
|
+
- "@inertiajs/vue3"
|
19
|
+
- "vue"
|
20
|
+
- "@vitejs/plugin-vue"
|
21
|
+
vite_plugin_import: "import vue from '@vitejs/plugin-vue'"
|
22
|
+
vite_plugin_call: "vue()"
|
23
|
+
copy_files:
|
24
|
+
"InertiaExample.vue": "%{js_destination_path}/pages/InertiaExample.vue"
|
25
|
+
"../assets/vue.svg": "%{js_destination_path}/assets/vue.svg"
|
26
|
+
"../assets/inertia.svg": "%{js_destination_path}/assets/inertia.svg"
|
27
|
+
"../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg"
|
28
|
+
|
29
|
+
svelte:
|
30
|
+
packages:
|
31
|
+
- "@inertiajs/svelte"
|
32
|
+
- "svelte"
|
33
|
+
- "@sveltejs/vite-plugin-svelte"
|
34
|
+
vite_plugin_import: "import { svelte } from '@sveltejs/vite-plugin-svelte'"
|
35
|
+
vite_plugin_call: "svelte()"
|
36
|
+
copy_files:
|
37
|
+
"svelte.config.js": "svelte.config.js"
|
38
|
+
"InertiaExample.svelte": "%{js_destination_path}/pages/InertiaExample.svelte"
|
39
|
+
"../assets/svelte.svg": "%{js_destination_path}/assets/svelte.svg"
|
40
|
+
"../assets/inertia.svg": "%{js_destination_path}/assets/inertia.svg"
|
41
|
+
"../assets/vite_ruby.svg": "%{js_destination_path}/assets/vite_ruby.svg"
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Inertia
|
2
|
+
module Generators
|
3
|
+
module Helpers
|
4
|
+
### FS Helpers
|
5
|
+
def js_destination_path
|
6
|
+
return ViteRuby.config.source_code_dir if defined?(ViteRuby)
|
7
|
+
if file?("config/vite.json")
|
8
|
+
source_code_dir = JSON.parse(File.read(file_path("config/vite.json"))).dig("all", "sourceCodeDir")
|
9
|
+
return source_code_dir if source_code_dir
|
10
|
+
end
|
11
|
+
|
12
|
+
"app/frontend"
|
13
|
+
end
|
14
|
+
|
15
|
+
def js_destination_root
|
16
|
+
file_path(js_destination_path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def js_file_path(*relative_path)
|
20
|
+
File.join(js_destination_root, *relative_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def file?(*relative_path)
|
24
|
+
File.file?(file_path(*relative_path))
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_path(*relative_path)
|
28
|
+
File.join(destination_root, *relative_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Interactivity Helpers
|
32
|
+
def ask(*)
|
33
|
+
unless options[:interactive]
|
34
|
+
say_error "Specify all options when running the generator non-interactively.", :red
|
35
|
+
exit(1)
|
36
|
+
end
|
37
|
+
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
def yes?(*)
|
42
|
+
return false unless options[:interactive]
|
43
|
+
|
44
|
+
super
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -1,66 +1,56 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "rails/generators"
|
3
|
+
require "rails/generators/base"
|
4
|
+
|
5
|
+
require_relative "helpers"
|
6
|
+
|
1
7
|
module Inertia
|
2
8
|
module Generators
|
3
9
|
class InstallGenerator < Rails::Generators::Base
|
10
|
+
include Helpers
|
11
|
+
|
12
|
+
FRAMEWORKS = YAML.load_file(File.expand_path("./frameworks.yml", __dir__))
|
13
|
+
|
4
14
|
source_root File.expand_path("./templates", __dir__)
|
5
15
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
"
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
"InertiaExample.vue" => "app/frontend/pages/InertiaExample.vue",
|
29
|
-
"../assets/vue.svg" => "app/frontend/assets/vue.svg",
|
30
|
-
"../assets/inertia.svg" => "app/frontend/assets/inertia.svg",
|
31
|
-
"../assets/vite_ruby.svg" => "app/frontend/assets/vite_ruby.svg"
|
32
|
-
}
|
33
|
-
},
|
34
|
-
"svelte" => {
|
35
|
-
packages: %w[@inertiajs/svelte svelte @sveltejs/vite-plugin-svelte],
|
36
|
-
dev_packages: %w[@vitejs/plugin-vue],
|
37
|
-
vite_plugin_import: "import { svelte } from '@sveltejs/vite-plugin-svelte'",
|
38
|
-
vite_plugin_call: "svelte()",
|
39
|
-
copy_files: {
|
40
|
-
"svelte.config.js" => "svelte.config.js",
|
41
|
-
"InertiaExample.svelte" => "app/frontend/pages/InertiaExample.svelte",
|
42
|
-
"../assets/svelte.svg" => "app/frontend/assets/svelte.svg",
|
43
|
-
"../assets/inertia.svg" => "app/frontend/assets/inertia.svg",
|
44
|
-
"../assets/vite_ruby.svg" => "app/frontend/assets/vite_ruby.svg"
|
45
|
-
}
|
46
|
-
}
|
47
|
-
}
|
16
|
+
class_option :framework, type: :string,
|
17
|
+
desc: "The framework you want to use with Inertia",
|
18
|
+
enum: FRAMEWORKS.keys,
|
19
|
+
default: nil
|
20
|
+
|
21
|
+
class_option :package_manager, type: :string, default: nil, enum: %w[npm yarn bun pnpm],
|
22
|
+
desc: "The package manager you want to use to install Inertia's npm packages"
|
23
|
+
|
24
|
+
class_option :interactive, type: :boolean, default: true,
|
25
|
+
desc: "Whether to prompt for optional installations"
|
26
|
+
|
27
|
+
class_option :install_tailwind, type: :boolean, default: false,
|
28
|
+
desc: "Whether to install Tailwind CSS"
|
29
|
+
class_option :install_vite, type: :boolean, default: false,
|
30
|
+
desc: "Whether to install Vite Ruby"
|
31
|
+
class_option :example_page, type: :boolean, default: true,
|
32
|
+
desc: "Whether to add an example Inertia page"
|
33
|
+
|
34
|
+
class_option :verbose, type: :boolean, default: false,
|
35
|
+
desc: "Run the generator in verbose mode"
|
36
|
+
|
37
|
+
remove_class_option :skip_namespace, :skip_collision_check
|
48
38
|
|
49
39
|
def install
|
50
40
|
say "Installing Inertia's Rails adapter"
|
51
41
|
|
52
|
-
|
53
|
-
say "Could not find a package.json file to install Inertia to.", :red
|
54
|
-
exit!
|
55
|
-
end
|
42
|
+
install_vite unless ruby_vite_installed?
|
56
43
|
|
57
|
-
|
58
|
-
say "Could not find a Vite configuration file `config/vite.json`. This generator only supports Ruby on Rails with Vite.", :red
|
59
|
-
exit!
|
60
|
-
end
|
44
|
+
install_tailwind if install_tailwind?
|
61
45
|
|
62
46
|
install_inertia
|
63
47
|
|
48
|
+
install_example_page if options[:example_page]
|
49
|
+
|
50
|
+
say "Copying bin/dev"
|
51
|
+
copy_file "#{__dir__}/templates/dev", "bin/dev"
|
52
|
+
chmod "bin/dev", 0o755, verbose: verbose?
|
53
|
+
|
64
54
|
say "Inertia's Rails adapter successfully installed", :green
|
65
55
|
end
|
66
56
|
|
@@ -68,83 +58,176 @@ module Inertia
|
|
68
58
|
|
69
59
|
def install_inertia
|
70
60
|
say "Adding Inertia's Rails adapter initializer"
|
71
|
-
template "initializer.rb",
|
61
|
+
template "initializer.rb", file_path("config/initializers/inertia_rails.rb")
|
72
62
|
|
73
63
|
say "Installing Inertia npm packages"
|
74
|
-
add_packages(*FRAMEWORKS[framework][
|
75
|
-
add_packages("--save-dev", *FRAMEWORKS[framework][:dev_packages])
|
64
|
+
add_packages(*FRAMEWORKS[framework]["packages"])
|
76
65
|
|
77
|
-
unless File.read(vite_config_path).include?(FRAMEWORKS[framework][
|
66
|
+
unless File.read(vite_config_path).include?(FRAMEWORKS[framework]["vite_plugin_import"])
|
78
67
|
say "Adding Vite plugin for #{framework}"
|
79
|
-
insert_into_file vite_config_path, "\n #{FRAMEWORKS[framework][
|
80
|
-
prepend_file vite_config_path, "#{FRAMEWORKS[framework][
|
81
|
-
end
|
82
|
-
|
83
|
-
unless Rails.root.join("package.json").read.include?('"type": "module"')
|
84
|
-
say 'Add "type": "module", to the package.json file'
|
85
|
-
gsub_file Rails.root.join("package.json").to_s, /\A\s*\{/, "{\n \"type\": \"module\","
|
68
|
+
insert_into_file vite_config_path, "\n #{FRAMEWORKS[framework]["vite_plugin_call"]},", after: "plugins: ["
|
69
|
+
prepend_file vite_config_path, "#{FRAMEWORKS[framework]["vite_plugin_import"]}\n"
|
86
70
|
end
|
87
71
|
|
88
|
-
say "Copying inertia.js
|
89
|
-
template "#{framework}/inertia.js",
|
90
|
-
|
91
|
-
say "Adding inertia.js script tag to the application layout"
|
92
|
-
headers = <<-ERB
|
93
|
-
<%= vite_javascript_tag 'inertia' %>
|
72
|
+
say "Copying inertia.js entrypoint"
|
73
|
+
template "#{framework}/inertia.js", js_file_path("entrypoints/inertia.js")
|
94
74
|
|
75
|
+
if application_layout.exist?
|
76
|
+
say "Adding inertia.js script tag to the application layout"
|
77
|
+
headers = <<-ERB
|
78
|
+
<%= vite_javascript_tag "inertia" %>
|
95
79
|
<%= inertia_headers %>
|
96
|
-
|
97
|
-
|
80
|
+
ERB
|
81
|
+
headers += "\n <%= vite_stylesheet_tag \"application\" %>" if install_tailwind?
|
98
82
|
|
99
|
-
|
100
|
-
|
101
|
-
|
83
|
+
insert_into_file application_layout.to_s, headers, after: "<%= vite_client_tag %>\n"
|
84
|
+
|
85
|
+
if framework == "react" && !application_layout.read.include?("vite_react_refresh_tag")
|
86
|
+
say "Adding Vite React Refresh tag to the application layout"
|
87
|
+
insert_into_file application_layout.to_s, "<%= vite_react_refresh_tag %>\n ", before: "<%= vite_client_tag %>"
|
88
|
+
gsub_file application_layout.to_s, /<title>/, "<title inertia>"
|
89
|
+
end
|
90
|
+
else
|
91
|
+
say_error "Could not find the application layout file. Please add the following tags manually:", :red
|
92
|
+
say_error "- <title>...</title>"
|
93
|
+
say_error "+ <title inertia>...</title>"
|
94
|
+
say_error "+ <%= inertia_headers %>"
|
95
|
+
say_error "+ <%= vite_react_refresh_tag %>" if framework == "react"
|
96
|
+
say_error "+ <%= vite_javascript_tag \"inertia\" %>"
|
102
97
|
end
|
98
|
+
end
|
103
99
|
|
100
|
+
def install_example_page
|
104
101
|
say "Copying example Inertia controller"
|
105
|
-
template "controller.rb",
|
102
|
+
template "controller.rb", file_path("app/controllers/inertia_example_controller.rb")
|
106
103
|
|
107
104
|
say "Adding a route for the example Inertia controller"
|
108
105
|
route "get 'inertia-example', to: 'inertia_example#index'"
|
109
106
|
|
110
|
-
say "Copying
|
111
|
-
FRAMEWORKS[framework][
|
112
|
-
template "#{framework}/#{source}",
|
107
|
+
say "Copying page assets"
|
108
|
+
FRAMEWORKS[framework]["copy_files"].each do |source, destination|
|
109
|
+
template "#{framework}/#{source}", file_path(destination % {js_destination_path: js_destination_path})
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def install_tailwind
|
114
|
+
say "Installing Tailwind CSS"
|
115
|
+
add_packages(%w[tailwindcss postcss autoprefixer @tailwindcss/forms @tailwindcss/typography @tailwindcss/container-queries])
|
116
|
+
|
117
|
+
template "tailwind/tailwind.config.js", file_path("tailwind.config.js")
|
118
|
+
copy_file "tailwind/postcss.config.js", file_path("postcss.config.js")
|
119
|
+
copy_file "tailwind/application.css", js_file_path("entrypoints/application.css")
|
120
|
+
|
121
|
+
if application_layout.exist?
|
122
|
+
say "Adding Tailwind CSS to the application layout"
|
123
|
+
insert_into_file application_layout.to_s, "<%= vite_stylesheet_tag \"application\" %>\n ", before: "<%= vite_client_tag %>"
|
124
|
+
else
|
125
|
+
say_error "Could not find the application layout file. Please add the following tags manually:", :red
|
126
|
+
say_error "+ <%= vite_stylesheet_tag \"application\" %>" if install_tailwind?
|
113
127
|
end
|
114
128
|
end
|
115
129
|
|
130
|
+
def install_vite
|
131
|
+
unless install_vite?
|
132
|
+
say_error "This generator only supports Ruby on Rails with Vite.", :red
|
133
|
+
exit(false)
|
134
|
+
end
|
135
|
+
|
136
|
+
in_root do
|
137
|
+
Bundler.with_original_env do
|
138
|
+
if (capture = run("bundle add vite_rails", capture: !verbose?))
|
139
|
+
say "Vite Rails gem successfully installed", :green
|
140
|
+
else
|
141
|
+
say capture
|
142
|
+
say_error "Failed to install Vite Rails gem", :red
|
143
|
+
exit(false)
|
144
|
+
end
|
145
|
+
if (capture = run("bundle exec vite install", capture: !verbose?))
|
146
|
+
say "Vite Rails successfully installed", :green
|
147
|
+
else
|
148
|
+
say capture
|
149
|
+
say_error "Failed to install Vite Rails", :red
|
150
|
+
exit(false)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def ruby_vite_installed?
|
157
|
+
return true if package_manager && ruby_vite?
|
158
|
+
|
159
|
+
if package_manager.nil?
|
160
|
+
say_status "Could not find a package.json file to install Inertia to.", nil
|
161
|
+
elsif gem_installed?("webpacker") || gem_installed?("shakapacker")
|
162
|
+
say "Webpacker or Shakapacker is installed.", :yellow
|
163
|
+
say "Vite Ruby can work alongside Webpacker or Shakapacker, but it might cause issues.", :yellow
|
164
|
+
say "Please see the Vite Ruby documentation for the migration guide:", :yellow
|
165
|
+
say "https://vite-ruby.netlify.app/guide/migration.html#webpacker-%F0%9F%93%A6", :yellow
|
166
|
+
else
|
167
|
+
say_status "Could not find a Vite configuration files (`config/vite.json` & `vite.config.{ts,js,mjs,cjs,mts,cts}`).", nil
|
168
|
+
end
|
169
|
+
false
|
170
|
+
end
|
171
|
+
|
172
|
+
def gem_installed?(name)
|
173
|
+
regex = /^[^#]*gem\s+['"]#{name}['"]/
|
174
|
+
File.read(file_path("Gemfile")).match?(regex)
|
175
|
+
end
|
176
|
+
|
177
|
+
def application_layout
|
178
|
+
@application_layout ||= Pathname.new(file_path("app/views/layouts/application.html.erb"))
|
179
|
+
end
|
180
|
+
|
116
181
|
def ruby_vite?
|
117
|
-
|
182
|
+
file?("config/vite.json") && vite_config_path
|
118
183
|
end
|
119
184
|
|
120
185
|
def package_manager
|
121
|
-
|
122
|
-
|
123
|
-
@package_manager = detect_package_manager
|
186
|
+
options[:package_manager] || detect_package_manager
|
124
187
|
end
|
125
188
|
|
126
189
|
def add_packages(*packages)
|
127
|
-
|
190
|
+
in_root do
|
191
|
+
run "#{package_manager} add #{packages.join(" ")} #{verbose? ? "" : "--silent"}"
|
192
|
+
end
|
128
193
|
end
|
129
194
|
|
130
195
|
def detect_package_manager
|
131
|
-
return nil unless
|
196
|
+
return nil unless file?("package.json")
|
132
197
|
|
133
|
-
if
|
198
|
+
if file?("package-lock.json")
|
134
199
|
"npm"
|
135
|
-
elsif
|
200
|
+
elsif file?("bun.lockb")
|
136
201
|
"bun"
|
202
|
+
elsif file?("pnpm-lock.yaml")
|
203
|
+
"pnpm"
|
137
204
|
else
|
138
205
|
"yarn"
|
139
206
|
end
|
140
207
|
end
|
141
208
|
|
142
209
|
def vite_config_path
|
143
|
-
@vite_config_path ||= Dir.glob(
|
210
|
+
@vite_config_path ||= Dir.glob(file_path("vite.config.{ts,js,mjs,cjs,mts,cts}")).first
|
211
|
+
end
|
212
|
+
|
213
|
+
def install_vite?
|
214
|
+
return @install_vite if defined?(@install_vite)
|
215
|
+
|
216
|
+
@install_vite = options[:install_vite] || yes?("Would you like to install Vite Ruby? (y/n)", :green)
|
217
|
+
end
|
218
|
+
|
219
|
+
def install_tailwind?
|
220
|
+
return @install_tailwind if defined?(@install_tailwind)
|
221
|
+
|
222
|
+
@install_tailwind = options[:install_tailwind] || yes?("Would you like to install Tailwind CSS? (y/n)", :green)
|
223
|
+
end
|
224
|
+
|
225
|
+
def verbose?
|
226
|
+
options[:verbose]
|
144
227
|
end
|
145
228
|
|
146
229
|
def framework
|
147
|
-
@framework ||= ask("What framework do you want to use with
|
230
|
+
@framework ||= options[:framework] || ask("What framework do you want to use with Inertia?", :green, limited_to: FRAMEWORKS.keys, default: "react")
|
148
231
|
end
|
149
232
|
end
|
150
233
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env sh
|
2
|
+
|
3
|
+
export PORT="${PORT:-3000}"
|
4
|
+
|
5
|
+
if command -v overmind 1> /dev/null 2>&1
|
6
|
+
then
|
7
|
+
overmind start -f Procfile.dev "$@"
|
8
|
+
exit $?
|
9
|
+
fi
|
10
|
+
|
11
|
+
if command -v hivemind 1> /dev/null 2>&1
|
12
|
+
then
|
13
|
+
echo "Hivemind is installed. Running the application with Hivemind..."
|
14
|
+
exec hivemind Procfile.dev "$@"
|
15
|
+
exit $?
|
16
|
+
fi
|
17
|
+
|
18
|
+
if gem list --no-installed --exact --silent foreman; then
|
19
|
+
echo "Installing foreman..."
|
20
|
+
gem install foreman
|
21
|
+
fi
|
22
|
+
|
23
|
+
foreman start -f Procfile.dev "$@"
|
@@ -21,7 +21,7 @@ createInertiaApp({
|
|
21
21
|
// and use the following lines.
|
22
22
|
// see https://inertia-rails.netlify.app/guide/pages#default-layouts
|
23
23
|
//
|
24
|
-
// const page = pages[
|
24
|
+
// const page = pages[`../pages/${name}.jsx`]
|
25
25
|
// page.default.layout ||= (page) => createElement(Layout, null, page)
|
26
26
|
// return page
|
27
27
|
},
|
@@ -19,7 +19,7 @@ createInertiaApp({
|
|
19
19
|
// and use the following lines.
|
20
20
|
// see https://inertia-rails.netlify.app/guide/pages#default-layouts
|
21
21
|
//
|
22
|
-
// const page = pages[
|
22
|
+
// const page = pages[`../pages/${name}.vue`]
|
23
23
|
// page.default.layout ||= (page) => createElement(Layout, null, page)
|
24
24
|
// return page
|
25
25
|
},
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/** @type {import('tailwindcss').Config} */
|
2
|
+
|
3
|
+
module.exports = {
|
4
|
+
content: [
|
5
|
+
'./public/*.html',
|
6
|
+
'./app/helpers/**/*.rb',
|
7
|
+
'./<%= js_destination_path %>/**/*.{js,ts,jsx,tsx,vue,svelte}',
|
8
|
+
'./app/views/**/*.{erb,haml,html,slim}'
|
9
|
+
],
|
10
|
+
theme: {
|
11
|
+
extend: {},
|
12
|
+
},
|
13
|
+
plugins: [
|
14
|
+
require('@tailwindcss/forms'),
|
15
|
+
require('@tailwindcss/typography'),
|
16
|
+
require('@tailwindcss/container-queries'),
|
17
|
+
]
|
18
|
+
}
|
@@ -20,7 +20,7 @@ createInertiaApp({
|
|
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[
|
23
|
+
// const page = pages[`../pages/${name}.vue`]
|
24
24
|
// page.default.layout ||= (page) => createElement(Layout, null, page)
|
25
25
|
// return page
|
26
26
|
},
|
@@ -84,19 +84,17 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
84
84
|
def <%= "serialize_#{singular_table_name}" %>(<%= singular_table_name %>)
|
85
85
|
<%= singular_table_name %>.as_json(only: [
|
86
86
|
<%= attributes_to_serialize.map { |attribute| ":#{attribute}" }.join(", ") %>
|
87
|
-
])
|
88
|
-
|
87
|
+
])<%- if attributes.any?(&:attachment?) || attributes.any?(&:attachments?) -%>.tap do |hash|
|
88
|
+
<%- attributes.filter(&:attachment?).map do |attribute| -%>
|
89
89
|
hash["<%= attribute.column_name %>"] = {filename: <%= singular_table_name %>.<%= attribute.column_name %>.filename, url: url_for(<%= singular_table_name %>.<%= attribute.column_name %>)} if <%= singular_table_name %>.<%= attribute.column_name %>.attached?
|
90
|
-
|
91
|
-
|
92
|
-
<% attributes.filter(&:attachments?).map do |attribute| -%>
|
90
|
+
<%- end -%>
|
91
|
+
<%- attributes.filter(&:attachments?).map do |attribute| -%>
|
93
92
|
hash["<%= attribute.column_name %>"] =
|
94
93
|
<%= singular_table_name %>.<%= attribute.column_name %>.flat_map do |file|
|
95
94
|
{filename: file.filename.to_s, url: url_for(file)}
|
96
95
|
end
|
97
|
-
|
98
|
-
end
|
99
|
-
<% end -%>
|
96
|
+
<%- end -%>
|
97
|
+
end<% end %>
|
100
98
|
end
|
101
99
|
end
|
102
100
|
<% end -%>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inertia_rails-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Svyatoslav Kryukov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -50,6 +50,8 @@ files:
|
|
50
50
|
- README.md
|
51
51
|
- lib/generators/inertia/controller/controller_generator.rb
|
52
52
|
- lib/generators/inertia/controller/templates/controller.rb.tt
|
53
|
+
- lib/generators/inertia/install/frameworks.yml
|
54
|
+
- lib/generators/inertia/install/helpers.rb
|
53
55
|
- lib/generators/inertia/install/install_generator.rb
|
54
56
|
- lib/generators/inertia/install/templates/assets/inertia.svg
|
55
57
|
- lib/generators/inertia/install/templates/assets/react.svg
|
@@ -57,6 +59,7 @@ files:
|
|
57
59
|
- lib/generators/inertia/install/templates/assets/vite_ruby.svg
|
58
60
|
- lib/generators/inertia/install/templates/assets/vue.svg
|
59
61
|
- lib/generators/inertia/install/templates/controller.rb
|
62
|
+
- lib/generators/inertia/install/templates/dev
|
60
63
|
- lib/generators/inertia/install/templates/initializer.rb
|
61
64
|
- lib/generators/inertia/install/templates/react/InertiaExample.jsx
|
62
65
|
- lib/generators/inertia/install/templates/react/InertiaExample.module.css
|
@@ -64,6 +67,9 @@ files:
|
|
64
67
|
- lib/generators/inertia/install/templates/svelte/InertiaExample.svelte
|
65
68
|
- lib/generators/inertia/install/templates/svelte/inertia.js
|
66
69
|
- lib/generators/inertia/install/templates/svelte/svelte.config.js
|
70
|
+
- lib/generators/inertia/install/templates/tailwind/application.css
|
71
|
+
- lib/generators/inertia/install/templates/tailwind/postcss.config.js
|
72
|
+
- lib/generators/inertia/install/templates/tailwind/tailwind.config.js.tt
|
67
73
|
- lib/generators/inertia/install/templates/vue/InertiaExample.vue
|
68
74
|
- lib/generators/inertia/install/templates/vue/inertia.js
|
69
75
|
- lib/generators/inertia/scaffold/scaffold_generator.rb
|