hotwire_scaffold_generator 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rubocop.yml +14 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +21 -0
- data/README.md +52 -0
- data/Rakefile +9 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/hotwire_scaffold_generator.gemspec +39 -0
- data/lib/generators/hotwire_scaffold/client/client_generator.rb +14 -0
- data/lib/generators/hotwire_scaffold/client_controller/client_controller_generator.rb +57 -0
- data/lib/generators/hotwire_scaffold/client_controller/templates/controller.rb.tt +70 -0
- data/lib/generators/hotwire_scaffold/client_controller/templates/stimulus_controller.js.tt +8 -0
- data/lib/generators/hotwire_scaffold/client_controller/templates/views/_form.html.erb.tt +39 -0
- data/lib/generators/hotwire_scaffold/client_controller/templates/views/create.turbo_stream.erb.tt +1 -0
- data/lib/generators/hotwire_scaffold/client_controller/templates/views/destroy.turbo_stream.erb.tt +1 -0
- data/lib/generators/hotwire_scaffold/client_controller/templates/views/edit.html.erb.tt +11 -0
- data/lib/generators/hotwire_scaffold/client_controller/templates/views/index.html.erb.tt +12 -0
- data/lib/generators/hotwire_scaffold/client_controller/templates/views/new.html.erb.tt +5 -0
- data/lib/generators/hotwire_scaffold/client_controller/templates/views/partial.html.erb.tt +22 -0
- data/lib/generators/hotwire_scaffold/client_controller/templates/views/show.html.erb.tt +3 -0
- data/lib/generators/hotwire_scaffold/client_controller/templates/views/update.turbo_stream.erb.tt +1 -0
- data/lib/hotwire_scaffold_generator/version.rb +5 -0
- data/lib/hotwire_scaffold_generator.rb +8 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '081ff21d8bc03035d45cf5d3a52b942c078c4a39b555faab8020b7d575cb374c'
|
4
|
+
data.tar.gz: 3ea7a75bb0d7647df82d1d6ab9e67d5c8dfa8cb46da04a5538e16a47bd79a2a2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 10619b3ebc64c0c7f691026065deb2f923e51f513e6ed514ec60ed592d433c0669cd2daa6cee1a08da4b8819e32675b4e041032a05d14cc38954217d25ac7543
|
7
|
+
data.tar.gz: 7f68ae755e957b2c6f63a3aea7b78026d33f30896016c2ee3eb5a62378855ca07b5cf2111b9656f0c5deafc631f4de040bc3d45da25fd7b62d0f9e865e180930
|
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at mchasecov@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hotwire_scaffold_generator (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
parallel (1.21.0)
|
11
|
+
parser (3.0.2.0)
|
12
|
+
ast (~> 2.4.1)
|
13
|
+
rainbow (3.0.0)
|
14
|
+
rake (13.0.6)
|
15
|
+
regexp_parser (2.2.0)
|
16
|
+
rexml (3.2.5)
|
17
|
+
rubocop (1.21.0)
|
18
|
+
parallel (~> 1.10)
|
19
|
+
parser (>= 3.0.0.0)
|
20
|
+
rainbow (>= 2.2.2, < 4.0)
|
21
|
+
regexp_parser (>= 1.8, < 3.0)
|
22
|
+
rexml
|
23
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
24
|
+
ruby-progressbar (~> 1.7)
|
25
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
26
|
+
rubocop-ast (1.11.0)
|
27
|
+
parser (>= 3.0.1.1)
|
28
|
+
ruby-progressbar (1.11.0)
|
29
|
+
unicode-display_width (2.0.0)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
x86_64-linux
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
hotwire_scaffold_generator!
|
36
|
+
rake (~> 13.0)
|
37
|
+
rubocop (~> 1.21)
|
38
|
+
|
39
|
+
BUNDLED WITH
|
40
|
+
2.2.32
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Chase Covington
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Hotwire Scaffold Generator
|
2
|
+
|
3
|
+
This is a simple gem that builds off of the existing Rails generators to create Hotwire-ready applications! Currently, there are only two options.
|
4
|
+
You can generate either an entire scaffold (full MVC suite), or just the controller and views.
|
5
|
+
|
6
|
+
Currently, the generator is designed to make use of Turbo Stream over client request formats. This means that these generators do not involve the setup for a model to be streamed over websocket, but rather respond with `.turbo_stream.erb` format responses to make use of Turbo Stream.
|
7
|
+
|
8
|
+
I would like to add a scaffold generator that deals with Broadcast as opposed to Client so you have the option, but I need to do more research on that topic. This is my first gem and first time creating Rails generators.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'hotwire_scaffold_generator'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle install
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install hotwire_scaffold_generator
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
After adding the gem to your application, you can now generate the files using `rails g hotwire_scaffold:client` for the full scaffold, or `rails g hotwire_scaffold:client_controller` to skip creating the model and migration.
|
29
|
+
|
30
|
+
Just like the Rails base generators, if you supply your model's attributes (even with the controller generator) it will automatically include them in the `def foo_params` method of your controller and list them in your view files in the `_partial.html.erb` view.
|
31
|
+
|
32
|
+
## Arguments
|
33
|
+
|
34
|
+
#### --no-stimulus
|
35
|
+
In addition to the baseline Rails arguments, you can use `--no-stimulus` to disable the generation of the form reset Stimulus controller that is included. I include this as it is is needed to polish the submission form when using Hotwire, else your forms will not clear out after submission. However you may prefer to have an agnostic approach where you have one form reset controller for all of your methods rather than repeating it multiple times.
|
36
|
+
|
37
|
+
I chose to name it after your model, rather than name it a generic name, so that it would not overwrite or conflict any existing controllers you may have.
|
38
|
+
|
39
|
+
#### --jbuilder
|
40
|
+
the Jbuilder argument is false by default
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hotwire_scaffold_generator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/hotwire_scaffold_generator/blob/master/CODE_OF_CONDUCT.md).
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
49
|
+
|
50
|
+
## Code of Conduct
|
51
|
+
|
52
|
+
Everyone interacting in the HotwireScaffoldGenerator project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/hotwire_scaffold_generator/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "hotwire_scaffold_generator"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/hotwire_scaffold_generator/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "hotwire_scaffold_generator"
|
7
|
+
spec.version = HotwireScaffoldGenerator::VERSION
|
8
|
+
spec.authors = ["Chase Covington"]
|
9
|
+
spec.email = ["mchasecov@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "A gem to generate a MVC scaffold to quickly get started with Turbo Streams."
|
12
|
+
spec.description = "A gem to generate a MVC scaffold to quickly get started with Turbo Streams. This gem includes the
|
13
|
+
model callbacks, controller actions, and view stream recievers that you need for your model to be broadcasted live
|
14
|
+
when instances are created, updated, and deleted."
|
15
|
+
spec.homepage = "https://github.com/MchaseCov/hotwire_scaffold_generator"
|
16
|
+
spec.license = "MIT"
|
17
|
+
spec.required_ruby_version = ">= 2.6.0"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/MchaseCov/hotwire_scaffold_generator"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/MchaseCov/hotwire_scaffold_generator/blob/master/CHANGELOG.md"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
36
|
+
|
37
|
+
# For more information and examples about making a new gem, checkout our
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
39
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "generators/hotwire_scaffold/client_controller/client_controller_generator"
|
4
|
+
require "rails/generators/rails/resource/resource_generator"
|
5
|
+
module HotwireScaffold
|
6
|
+
module Generators
|
7
|
+
class ClientGenerator < Rails::Generators::ResourceGenerator
|
8
|
+
remove_hook_for :resource_controller
|
9
|
+
remove_class_option :actions
|
10
|
+
|
11
|
+
invoke ClientControllerGenerator
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HotwireScaffold
|
4
|
+
module Generators
|
5
|
+
# Custom scaffolding generator
|
6
|
+
class ClientControllerGenerator < Rails::Generators::ScaffoldControllerGenerator
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
# Overrides ScaffoldControllerGenerator
|
10
|
+
class_option :jbuilder, type: :boolean, default: false
|
11
|
+
class_option :stimulus, type: :boolean, default: true, desc: "Do not generate a stimulus javascript controller"
|
12
|
+
|
13
|
+
# Overrides ScaffoldControllerGenerator
|
14
|
+
def create_controller_files
|
15
|
+
template "controller.rb",
|
16
|
+
File.join("app/controllers", controller_class_path, "#{controller_file_name}_controller.rb")
|
17
|
+
end
|
18
|
+
|
19
|
+
def create_stimulus_controller
|
20
|
+
return if no_stimulus?
|
21
|
+
|
22
|
+
template "stimulus_controller.js",
|
23
|
+
File.join("app/javascript/controllers", "#{controller_file_name}_controller.js")
|
24
|
+
end
|
25
|
+
|
26
|
+
def copy_view_files
|
27
|
+
directory_path = File.join("app/views", controller_file_path)
|
28
|
+
available_views.each do |file_name|
|
29
|
+
template "views/#{file_name}.html.erb", File.join(directory_path, "#{file_name}.html.erb")
|
30
|
+
end
|
31
|
+
turbo_files.each do |file_name|
|
32
|
+
template "views/#{file_name}.turbo_stream.erb", File.join(directory_path, "#{file_name}.turbo_stream.erb")
|
33
|
+
end
|
34
|
+
template "views/partial.html.erb", File.join(directory_path, "_#{singular_name}.html.erb")
|
35
|
+
end
|
36
|
+
|
37
|
+
# Overrides ScaffoldControllerGenerator
|
38
|
+
hook_for :template_engine, as: :scaffold do
|
39
|
+
return
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def turbo_files
|
45
|
+
%w[create update destroy]
|
46
|
+
end
|
47
|
+
|
48
|
+
def available_views
|
49
|
+
%w[index edit show new _form]
|
50
|
+
end
|
51
|
+
|
52
|
+
def no_stimulus?
|
53
|
+
!options["stimulus"]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class <%= class_name.pluralize %>Controller < ApplicationController
|
2
|
+
before_action :set_<%= singular_table_name %>, only: %i[show edit update destroy]
|
3
|
+
# GET /<%= plural_name %>
|
4
|
+
def index
|
5
|
+
@<%= plural_name %> = <%= class_name %>.all
|
6
|
+
end
|
7
|
+
|
8
|
+
# GET /<%= plural_name %>/1
|
9
|
+
def show; end
|
10
|
+
|
11
|
+
# GET /<%= plural_name %>/new
|
12
|
+
def new
|
13
|
+
@<%= singular_table_name %> = <%= class_name %>.new
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /<%= plural_name %>/1/edit
|
17
|
+
def edit; end
|
18
|
+
|
19
|
+
# POST /<%= plural_name %>
|
20
|
+
def create
|
21
|
+
@<%= singular_table_name %> = <%= class_name %>.new(<%= singular_table_name %>_params)
|
22
|
+
|
23
|
+
respond_to do |format|
|
24
|
+
if @<%= singular_table_name %>.save
|
25
|
+
format.turbo_stream
|
26
|
+
format.html { redirect_to <%= singular_table_name %>_url(@<%= singular_table_name %>), notice: "<%= singular_table_name %> was successfully created." }
|
27
|
+
else
|
28
|
+
format.html { render :new, status: :unprocessable_entity }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# PATCH/PUT /<%plural_name%>/1
|
34
|
+
def update
|
35
|
+
respond_to do |format|
|
36
|
+
if @<%= singular_table_name %>.update(<%= singular_table_name %>_params)
|
37
|
+
format.turbo_stream
|
38
|
+
format.html { redirect_to <%= singular_table_name %>_url(<%= singular_table_name %>), notice: "<%= singular_table_name %> was successfully updated." }
|
39
|
+
else
|
40
|
+
format.html { render :edit, status: :unprocessable_entity }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# DELETE /<%plural_name%>/1
|
46
|
+
def destroy
|
47
|
+
@<%= singular_table_name %>.destroy
|
48
|
+
|
49
|
+
respond_to do |format|
|
50
|
+
format.turbo_stream
|
51
|
+
format.html { redirect_to <%= plural_name %>_url, notice: "<%= singular_table_name %> was successfully destroyed." }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
# Use callbacks to share common setup or constraints between actions.
|
58
|
+
def set_<%= singular_table_name %>
|
59
|
+
@<%= singular_table_name %> = <%= class_name %>.find(params[:id])
|
60
|
+
end
|
61
|
+
|
62
|
+
# Only allow a list of trusted parameters through.
|
63
|
+
def <%= "#{singular_table_name}_params" %>
|
64
|
+
<%- if attributes_names.empty? -%>
|
65
|
+
params.fetch(:<%= singular_table_name %>, {})
|
66
|
+
<%- else -%>
|
67
|
+
params.require(:<%= singular_table_name %>).permit(<%= permitted_params %>)
|
68
|
+
<%- end -%>
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<div>
|
2
|
+
<%%= form_with model: <%= model_resource_name %>, data: { controller: "<%=table_name%>", action: "turbo:submit-end-><%=table_name%>#reset" } do |form| %>
|
3
|
+
<%% if <%= singular_table_name %>.errors.any? %>
|
4
|
+
<div style="color: red">
|
5
|
+
<h2><%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
|
6
|
+
|
7
|
+
<ul>
|
8
|
+
<%% <%= singular_table_name %>.errors.each do |error| %>
|
9
|
+
<li><%%= error.full_message %></li>
|
10
|
+
<%% end %>
|
11
|
+
</ul>
|
12
|
+
</div>
|
13
|
+
<%% end %>
|
14
|
+
|
15
|
+
<% attributes.each do |attribute| -%>
|
16
|
+
<div>
|
17
|
+
<% if attribute.password_digest? -%>
|
18
|
+
<%%= form.label :password, style: "display: block" %>
|
19
|
+
<%%= form.password_field :password %>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<div>
|
23
|
+
<%%= form.label :password_confirmation, style: "display: block" %>
|
24
|
+
<%%= form.password_field :password_confirmation %>
|
25
|
+
<% elsif attribute.attachments? -%>
|
26
|
+
<%%= form.label :<%= attribute.column_name %>, style: "display: block" %>
|
27
|
+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %>, multiple: true %>
|
28
|
+
<% else -%>
|
29
|
+
<%%= form.label :<%= attribute.column_name %>, style: "display: block" %>
|
30
|
+
<%%= form.<%= attribute.field_type %> :<%= attribute.column_name %> %>
|
31
|
+
<% end -%>
|
32
|
+
</div>
|
33
|
+
|
34
|
+
<% end -%>
|
35
|
+
<div>
|
36
|
+
<%%= form.submit %>
|
37
|
+
</div>
|
38
|
+
<%% end %>
|
39
|
+
</div>
|
data/lib/generators/hotwire_scaffold/client_controller/templates/views/create.turbo_stream.erb.tt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<%%= turbo_stream.append "<%= human_name.pluralize.downcase %>", @<%= singular_table_name %> %>
|
data/lib/generators/hotwire_scaffold/client_controller/templates/views/destroy.turbo_stream.erb.tt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<%%= turbo_stream.remove @<%= singular_table_name %> %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%%= turbo_frame_tag @<%= singular_table_name %> do %>
|
2
|
+
<h1>Editing <%= human_name.downcase %></h1>
|
3
|
+
|
4
|
+
<%%= render "form", <%= singular_table_name %>: @<%= singular_table_name %> %>
|
5
|
+
|
6
|
+
<br>
|
7
|
+
|
8
|
+
<div>
|
9
|
+
<%%= button_to "Destroy this <%= human_name.downcase %>", <%= model_resource_name(prefix: "@") %>, method: :delete %>
|
10
|
+
</div>
|
11
|
+
<%% end %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<p style="color: green"><%%= notice %></p>
|
2
|
+
|
3
|
+
<h1><%= human_name.pluralize %></h1>
|
4
|
+
|
5
|
+
<%%= turbo_frame_tag id="new_<%= human_name.downcase %>_form" do %>
|
6
|
+
<%%= link_to "New <%= human_name.downcase %>", <%= new_helper(type: :path) %> %>
|
7
|
+
<%% end %>
|
8
|
+
|
9
|
+
<div id="<%= plural_table_name %>">
|
10
|
+
<%%= render @<%= plural_table_name %> %>
|
11
|
+
</div>
|
12
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<%%= turbo_frame_tag <%= singular_table_name %> do %>
|
2
|
+
<div>
|
3
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
4
|
+
<p>
|
5
|
+
<strong><%= attribute.human_name %>:</strong>
|
6
|
+
<% if attribute.attachment? -%>
|
7
|
+
<%%= link_to <%= singular_name %>.<%= attribute.column_name %>.filename, <%= singular_name %>.<%= attribute.column_name %> if <%= singular_name %>.<%= attribute.column_name %>.attached? %>
|
8
|
+
<% elsif attribute.attachments? -%>
|
9
|
+
<%% <%= singular_name %>.<%= attribute.column_name %>.each do |<%= attribute.singular_name %>| %>
|
10
|
+
<div><%%= link_to <%= attribute.singular_name %>.filename, <%= attribute.singular_name %> %></div>
|
11
|
+
<%% end %>
|
12
|
+
<% else -%>
|
13
|
+
<%%= <%= singular_name %>.<%= attribute.column_name %> %>
|
14
|
+
<% end -%>
|
15
|
+
</p>
|
16
|
+
<% end -%>
|
17
|
+
<div>
|
18
|
+
<%%= link_to "Edit this <%= human_name.downcase %>", edit_<%= model_resource_name %>_path(<%= model_resource_name %>) %> |
|
19
|
+
<%%= button_to "Destroy this <%= human_name.downcase %>", <%= model_resource_name %>, method: :delete %>
|
20
|
+
</div>
|
21
|
+
</div>
|
22
|
+
<%% end %>
|
data/lib/generators/hotwire_scaffold/client_controller/templates/views/update.turbo_stream.erb.tt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<%%= turbo_stream.update @<%= singular_table_name %> %>
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hotwire_scaffold_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chase Covington
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |-
|
14
|
+
A gem to generate a MVC scaffold to quickly get started with Turbo Streams. This gem includes the
|
15
|
+
model callbacks, controller actions, and view stream recievers that you need for your model to be broadcasted live
|
16
|
+
when instances are created, updated, and deleted.
|
17
|
+
email:
|
18
|
+
- mchasecov@gmail.com
|
19
|
+
executables: []
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- ".rubocop.yml"
|
24
|
+
- CHANGELOG.md
|
25
|
+
- CODE_OF_CONDUCT.md
|
26
|
+
- Gemfile
|
27
|
+
- Gemfile.lock
|
28
|
+
- LICENSE.txt
|
29
|
+
- README.md
|
30
|
+
- Rakefile
|
31
|
+
- bin/console
|
32
|
+
- bin/setup
|
33
|
+
- hotwire_scaffold_generator.gemspec
|
34
|
+
- lib/generators/hotwire_scaffold/client/client_generator.rb
|
35
|
+
- lib/generators/hotwire_scaffold/client_controller/client_controller_generator.rb
|
36
|
+
- lib/generators/hotwire_scaffold/client_controller/templates/controller.rb.tt
|
37
|
+
- lib/generators/hotwire_scaffold/client_controller/templates/stimulus_controller.js.tt
|
38
|
+
- lib/generators/hotwire_scaffold/client_controller/templates/views/_form.html.erb.tt
|
39
|
+
- lib/generators/hotwire_scaffold/client_controller/templates/views/create.turbo_stream.erb.tt
|
40
|
+
- lib/generators/hotwire_scaffold/client_controller/templates/views/destroy.turbo_stream.erb.tt
|
41
|
+
- lib/generators/hotwire_scaffold/client_controller/templates/views/edit.html.erb.tt
|
42
|
+
- lib/generators/hotwire_scaffold/client_controller/templates/views/index.html.erb.tt
|
43
|
+
- lib/generators/hotwire_scaffold/client_controller/templates/views/new.html.erb.tt
|
44
|
+
- lib/generators/hotwire_scaffold/client_controller/templates/views/partial.html.erb.tt
|
45
|
+
- lib/generators/hotwire_scaffold/client_controller/templates/views/show.html.erb.tt
|
46
|
+
- lib/generators/hotwire_scaffold/client_controller/templates/views/update.turbo_stream.erb.tt
|
47
|
+
- lib/hotwire_scaffold_generator.rb
|
48
|
+
- lib/hotwire_scaffold_generator/version.rb
|
49
|
+
homepage: https://github.com/MchaseCov/hotwire_scaffold_generator
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata:
|
53
|
+
homepage_uri: https://github.com/MchaseCov/hotwire_scaffold_generator
|
54
|
+
source_code_uri: https://github.com/MchaseCov/hotwire_scaffold_generator
|
55
|
+
changelog_uri: https://github.com/MchaseCov/hotwire_scaffold_generator/blob/master/CHANGELOG.md
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 2.6.0
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubygems_version: 3.2.22
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: A gem to generate a MVC scaffold to quickly get started with Turbo Streams.
|
75
|
+
test_files: []
|