superform 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +199 -0
- data/Rakefile +8 -0
- data/lib/superform/version.rb +5 -0
- data/lib/superform.rb +8 -0
- data/sig/superform.rbs +4 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1f11fa90121336cea5cba3e376930c7c03c59f1a4cad8383de46482921651a94
|
4
|
+
data.tar.gz: cfec05650064dcb07e6eadb0b78c501317cace17bd7062c666ad3972379e4c1b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ec98e31913b9ca5f3aac6c75952b2ee51a19c01c82368f2dc5c87f58c91eb6dd0f41dfae969165f6be7fc1ac2e87595f85c30d19ef43938e3c95a58e2cd1c7ba
|
7
|
+
data.tar.gz: b138902a808ecbff61fbc8b3ae37a34e576895972512a7c0c5d78e8c318130fa567d53570d9163210d2015141ea47a38e3c0b021082be936341d9f5c951a4b25
|
data/.rspec
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 bradgessler@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/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Brad Gessler
|
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,199 @@
|
|
1
|
+
# Superform
|
2
|
+
|
3
|
+
Superform aims to be the best way to build forms in Rails applications. Here's what it does differently.
|
4
|
+
|
5
|
+
* **Everything is a component.** Superform is built on top of [Phlex](https://phlex.fun), so every bit of HTML in the form can be customized to your precise needs. Use it with your own CSS Framework or go crazy customizing every last bit of TailwindCSS.
|
6
|
+
|
7
|
+
* **Strong Params are built in.** Superform automatically permits the form fields for you. How many times have you changed the form and forgot to permit a param from the controller? No more! Superform has you covered.
|
8
|
+
|
9
|
+
* **Compose forms with Plain 'ol Ruby Objects**. Superform is built on top of POROs, so you can easily compose forms together to create complex forms. You can even extend forms to create new forms with a different look and feel.
|
10
|
+
|
11
|
+
It's a complete rewrite of Rails form's internals that's inspired by Reactive component system. [Chris McCord said it very eloquently in a love letter to react](https://fly.io/blog/love-letter-react/). This aspires to be that, but in Ruby.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Install the gem and add to the Rails application's Gemfile by executing:
|
16
|
+
|
17
|
+
$ bundle add superform
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Super Forms streamlines the development of forms on Rails applications by making everything a component.
|
22
|
+
|
23
|
+
Here's what a Superform looks in your Erb files.
|
24
|
+
|
25
|
+
```erb
|
26
|
+
<%= render ApplicationForm.new model: @user do
|
27
|
+
render field(:email).input(type: :email)
|
28
|
+
render field(:name).input
|
29
|
+
|
30
|
+
button(type: :submit) { "Sign up" }
|
31
|
+
end %>
|
32
|
+
```
|
33
|
+
|
34
|
+
That's very spartan form! Let's add labels and HTML between each form row so we have something to work with.
|
35
|
+
|
36
|
+
```erb
|
37
|
+
<%= render ApplicationForm.new do
|
38
|
+
div class: "form-row" do
|
39
|
+
render field(:email).label
|
40
|
+
render field(:email).input(type: :email)
|
41
|
+
end
|
42
|
+
div class: "form-row" do
|
43
|
+
render field(:name).label
|
44
|
+
render field(:name).input
|
45
|
+
end
|
46
|
+
|
47
|
+
button(type: :submit) { "Sign up" }
|
48
|
+
end %>
|
49
|
+
```
|
50
|
+
|
51
|
+
Jumpin' Jimmidy! That's starting to get purty verbose. Let's add some helpers to `ApplicationForm` and tighten things up.
|
52
|
+
|
53
|
+
## Customizing Look & Feel
|
54
|
+
|
55
|
+
Superforms are built entirely out of Phlex components. The method names correspeond with the tag, its arguments are attributes, and the blocks are the contents of the element.
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
class ApplicationForm < Superform::Base
|
59
|
+
class MyInputComponent < ApplicationComponent
|
60
|
+
def template(&)
|
61
|
+
div class: "form-field" do
|
62
|
+
input(**attributes)
|
63
|
+
if field.errors?
|
64
|
+
p(class: "form-field-error") { field.errors.to_sentence }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class Field < Field
|
71
|
+
def input(**attributes)
|
72
|
+
MyInputComponent.new(self, attributes: attributes)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def labeled(component)
|
77
|
+
div class: "form-row" do
|
78
|
+
render component.field.label
|
79
|
+
render component
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def submit(text)
|
84
|
+
button(type: :submit) { text }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
That looks like a LOT of code, and it is, but look at how easy it is to create forms.
|
90
|
+
|
91
|
+
```erb
|
92
|
+
<%= render ApplicationForm.new model: @user do
|
93
|
+
labeled field(:name).input
|
94
|
+
labeled field(:email).input(type: :email)
|
95
|
+
|
96
|
+
submit "Sign up"
|
97
|
+
end %>
|
98
|
+
```
|
99
|
+
|
100
|
+
Much better!
|
101
|
+
|
102
|
+
### Extending Forms
|
103
|
+
|
104
|
+
The best part? If you have forms with a completely different look and feel, you can extend the forms just like you would a Ruby class:
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
class AdminForm < ApplicationForm
|
108
|
+
class AdminInput < ApplicationComponent
|
109
|
+
def template(&)
|
110
|
+
input(**attributes)
|
111
|
+
small { admin_tool_tip_for field.key }
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
class Field < Field
|
116
|
+
def tooltip_input(**attributes)
|
117
|
+
AdminInput.new(self, attributes: attributes)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
```
|
122
|
+
|
123
|
+
Then, just like you did in your Erb, you create the form:
|
124
|
+
|
125
|
+
```erb
|
126
|
+
<%= render AdminForm.new model: @user do
|
127
|
+
labeled field(:name).tooltip_input
|
128
|
+
labeled field(:email).tooltip_input(type: :email)
|
129
|
+
|
130
|
+
submit "Save"
|
131
|
+
end %>
|
132
|
+
```
|
133
|
+
|
134
|
+
### Self-permitting Parameters
|
135
|
+
|
136
|
+
Guess what? It also permits form fields for you in your controller, like this:
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
class UserController < ApplicationController
|
140
|
+
# Your actions
|
141
|
+
|
142
|
+
private
|
143
|
+
|
144
|
+
def permitted_params
|
145
|
+
@form.permit params
|
146
|
+
end
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
150
|
+
To do that though you need to move the form into your controller, which is pretty easy:
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
class UserController < ApplicationController
|
154
|
+
class Form < ApplicationForm
|
155
|
+
render field(:email).input(type: :email)
|
156
|
+
render field(:name).input
|
157
|
+
|
158
|
+
button(type: :submit) { "Sign up" }
|
159
|
+
end
|
160
|
+
|
161
|
+
before_action :assign_form
|
162
|
+
|
163
|
+
# Your actions
|
164
|
+
|
165
|
+
private
|
166
|
+
|
167
|
+
def assign_form
|
168
|
+
@form = Form.new(model: @user)
|
169
|
+
end
|
170
|
+
|
171
|
+
def permitted_params
|
172
|
+
@form.permit params
|
173
|
+
end
|
174
|
+
end
|
175
|
+
```
|
176
|
+
|
177
|
+
Then render it from your Erb in less lines, like this:
|
178
|
+
|
179
|
+
```
|
180
|
+
<%= render @form %>
|
181
|
+
```
|
182
|
+
|
183
|
+
## Development
|
184
|
+
|
185
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
186
|
+
|
187
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
188
|
+
|
189
|
+
## Contributing
|
190
|
+
|
191
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rubymonolith/superform. 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/rubymonolith/superform/blob/main/CODE_OF_CONDUCT.md).
|
192
|
+
|
193
|
+
## License
|
194
|
+
|
195
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
196
|
+
|
197
|
+
## Code of Conduct
|
198
|
+
|
199
|
+
Everyone interacting in the Superform project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rubymonolith/superform/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/lib/superform.rb
ADDED
data/sig/superform.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: superform
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brad Gessler
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-06-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A better way to customize and build forms for your Rails application
|
14
|
+
email:
|
15
|
+
- bradgessler@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".rspec"
|
21
|
+
- CHANGELOG.md
|
22
|
+
- CODE_OF_CONDUCT.md
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- lib/superform.rb
|
28
|
+
- lib/superform/version.rb
|
29
|
+
- sig/superform.rbs
|
30
|
+
homepage: https://github.com/rubymonolith/superform
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata:
|
34
|
+
allowed_push_host: https://rubygems.org
|
35
|
+
homepage_uri: https://github.com/rubymonolith/superform
|
36
|
+
source_code_uri: https://github.com/rubymonolith/superform
|
37
|
+
changelog_uri: https://github.com/rubymonolith/superform
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.6.0
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubygems_version: 3.4.6
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: Build forms in Rails
|
57
|
+
test_files: []
|