phlexi-field 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0be36da5b3ce1dae979b31c55d9a0ad18e9b4aa9f206e47f29ea97f55bc2c89b
4
+ data.tar.gz: 73584d4874fa1fa59746b34053f5e5d77edf6f3780f73be42b3d2ca677167c12
5
+ SHA512:
6
+ metadata.gz: de662238d5a8716422335d4d33b21e5b317e78c0fd247eb9c6185f3a0cd1294faab5192fcd1d1887a548825953c04ebfb2fc5696e3c7762fed662ae0199ee7d5
7
+ data.tar.gz: 631cdd6a03e32750863c632e61b0a447dde1ce20ccb5f20e1b513aba7937ea120f0733b1a6327c39f729561898c3f7a99e7bbefaf81736f0b27bd359d2cf23b8
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.2.2
data/Appraisals ADDED
@@ -0,0 +1,8 @@
1
+ appraise "default" do
2
+ # gem "phlex", "~> 1.10"
3
+ end
4
+
5
+ appraise "rails-7" do
6
+ gem "rails", "~> 7.1.3", ">= 7.1.3.4"
7
+ gem "sqlite3", "~> 1.4"
8
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.2.0] - 2024-07-31
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Stefan Froelich
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,196 @@
1
+ # Phlexi::Form
2
+
3
+ Phlexi::Form is a flexible and powerful form builder for Ruby applications. It provides a more customizable and extensible way to create forms compared to traditional form helpers.
4
+
5
+ [![Ruby](https://github.com/radioactive-labs/phlexi-form/actions/workflows/main.yml/badge.svg)](https://github.com/radioactive-labs/phlexi-form/actions/workflows/main.yml)
6
+
7
+ ## Features
8
+
9
+ - Customizable form components (input, select, checkbox, radio button, etc.)
10
+ - Automatic field type and attribute inference based on model attributes
11
+ - Built-in support for validations and error handling
12
+ - Flexible form structure with support for nested attributes
13
+ - Works with Phlex or erb views
14
+ - Extract input from parameters that match your form definition. No need to strong paramters.
15
+ - Rails compatible form inputs
16
+
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem 'phlexi-form'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ ```
29
+ $ bundle install
30
+ ```
31
+
32
+ Or install it yourself as:
33
+
34
+ ```
35
+ $ gem install phlexi-form
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ There are 2 ways to use Phlexi::Form:
41
+
42
+ ### Direct Usage
43
+
44
+ ```ruby
45
+ Phlexi::Form(User.new) do
46
+ field(:name) do |name|
47
+ render name.label_tag
48
+ render name.input_tag
49
+ end
50
+
51
+ field(:email) do |email|
52
+ render email.label_tag
53
+ render email.input_tag
54
+ end
55
+
56
+ nest_one(:address) do |address|
57
+ address.field(:street) do |street|
58
+ render street.label_tag
59
+ render street.input_tag
60
+ end
61
+
62
+ address.field(:city) do |city|
63
+ render city.label_tag
64
+ render city.input_tag
65
+ end
66
+ end
67
+
68
+ render submit_button
69
+ end
70
+ ```
71
+
72
+ > **Important**
73
+ >
74
+ > If you are rendering your form inline e.g.
75
+ > ```ruby
76
+ > render Phlexi::Form(User.new) {
77
+ > render field(:name).label_tag
78
+ > render field(:name).input_tag
79
+ > }
80
+ > ```
81
+ >
82
+ > Make sure you use `{...}` in defining your block instead of `do...end`
83
+ > This might be fixed in a future version.
84
+
85
+ ### Inherit form
86
+
87
+ ```ruby
88
+ class UserForm < Phlexi::Form::Base
89
+ def form_template
90
+ field(:name) do |name|
91
+ render name.label_tag
92
+ render name.input_tag
93
+ end
94
+
95
+ field(:email) do |email|
96
+ render email.label_tag
97
+ render email.input_tag
98
+ end
99
+
100
+ nest_one(:address) do |address|
101
+ address.field(:street) do |street|
102
+ render street.label_tag
103
+ render street.input_tag
104
+ end
105
+
106
+ address.field(:city) do |city|
107
+ render city.label_tag
108
+ render city.input_tag
109
+ end
110
+ end
111
+
112
+ render submit_button
113
+ end
114
+ end
115
+
116
+
117
+ # In your view or controller
118
+ form = UserForm.new(User.new)
119
+
120
+ # Render the form
121
+ render form
122
+
123
+ # Extract params
124
+ form.extract_input({
125
+ name: "Brad Pitt",
126
+ email: "brad@pitt.com",
127
+ address: {
128
+ street: "Plumbago",
129
+ city: "Accra",
130
+ }
131
+ })
132
+ ```
133
+
134
+ ## Advanced Usage
135
+
136
+ ### Custom Components
137
+
138
+ You can create custom form components by inheriting from `Phlexi::Form::Components::Base`:
139
+
140
+ ```ruby
141
+ class CustomInput < Phlexi::Form::Components::Base
142
+ def template
143
+ div(class: "custom-input") do
144
+ input(**attributes)
145
+ span(class: "custom-icon")
146
+ end
147
+ end
148
+ end
149
+
150
+ # Usage in your form
151
+ field(:custom_field) do |field|
152
+ render CustomInput.new(field)
153
+ end
154
+ ```
155
+
156
+ ### Theming
157
+
158
+ Phlexi::Form supports theming through a flexible theming system:
159
+
160
+ ```ruby
161
+ class ThemedForm < Phlexi::Form::Base
162
+ class FieldBuilder < FieldBuilder
163
+ private
164
+
165
+ def default_theme
166
+ {
167
+ input: "border rounded px-2 py-1",
168
+ label: "font-bold text-gray-700",
169
+ # Add more theme options here
170
+ }
171
+ end
172
+ end
173
+ end
174
+ ```
175
+
176
+ <!-- ## Configuration
177
+
178
+ You can configure Phlexi::Form globally by creating an initializer:
179
+
180
+ ```ruby
181
+ # config/initializers/phlexi_form.rb
182
+ Phlexi::Form.configure do |config|
183
+ config.default_theme = {
184
+ # Your default theme options
185
+ }
186
+ # Add more configuration options here
187
+ end
188
+ ``` -->
189
+
190
+ ## Contributing
191
+
192
+ Bug reports and pull requests are welcome on GitHub at https://github.com/radioactive-labs/phlexi-form.
193
+
194
+ ## License
195
+
196
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+ require "standard/rake"
6
+
7
+ task default: %i[test standard]
8
+
9
+ # https://juincc.medium.com/how-to-setup-minitest-for-your-gems-development-f29c4bee13c2
10
+ Rake::TestTask.new do |t|
11
+ t.libs << "test"
12
+ t.test_files = FileList["test/**/*_test.rb"]
13
+ t.verbose = true
14
+ end
data/TODO ADDED
@@ -0,0 +1,4 @@
1
+ - Add tests for primary_key
2
+ - Ensure composite primary keys are supported
3
+ - add tests for formmethod override in submit_button
4
+ - how can we automatically infer the file types accepted by the file_input component
data/config.ru ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubygems"
4
+ require "bundler"
5
+
6
+ Bundler.require :default, :development
@@ -0,0 +1,5 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec path: "../"
@@ -0,0 +1,194 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ phlexi-form (0.3.0.rc1)
5
+ activesupport
6
+ phlex (~> 1.11)
7
+ zeitwerk
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ actionpack (7.1.3.4)
13
+ actionview (= 7.1.3.4)
14
+ activesupport (= 7.1.3.4)
15
+ nokogiri (>= 1.8.5)
16
+ racc
17
+ rack (>= 2.2.4)
18
+ rack-session (>= 1.0.1)
19
+ rack-test (>= 0.6.3)
20
+ rails-dom-testing (~> 2.2)
21
+ rails-html-sanitizer (~> 1.6)
22
+ actionview (7.1.3.4)
23
+ activesupport (= 7.1.3.4)
24
+ builder (~> 3.1)
25
+ erubi (~> 1.11)
26
+ rails-dom-testing (~> 2.2)
27
+ rails-html-sanitizer (~> 1.6)
28
+ activesupport (7.1.3.4)
29
+ base64
30
+ bigdecimal
31
+ concurrent-ruby (~> 1.0, >= 1.0.2)
32
+ connection_pool (>= 2.2.5)
33
+ drb
34
+ i18n (>= 1.6, < 2)
35
+ minitest (>= 5.1)
36
+ mutex_m
37
+ tzinfo (~> 2.0)
38
+ addressable (2.8.7)
39
+ public_suffix (>= 2.0.2, < 7.0)
40
+ ansi (1.5.0)
41
+ appraisal (2.5.0)
42
+ bundler
43
+ rake
44
+ thor (>= 0.14.0)
45
+ ast (2.4.2)
46
+ base64 (0.2.0)
47
+ bigdecimal (3.1.8)
48
+ builder (3.3.0)
49
+ bundle-audit (0.1.0)
50
+ bundler-audit
51
+ bundler-audit (0.9.1)
52
+ bundler (>= 1.2.0, < 3)
53
+ thor (~> 1.0)
54
+ capybara (3.40.0)
55
+ addressable
56
+ matrix
57
+ mini_mime (>= 0.1.3)
58
+ nokogiri (~> 1.11)
59
+ rack (>= 1.6.0)
60
+ rack-test (>= 0.6.3)
61
+ regexp_parser (>= 1.5, < 3.0)
62
+ xpath (~> 3.2)
63
+ combustion (1.5.0)
64
+ activesupport (>= 3.0.0)
65
+ railties (>= 3.0.0)
66
+ thor (>= 0.14.6)
67
+ concurrent-ruby (1.3.3)
68
+ connection_pool (2.4.1)
69
+ crass (1.0.6)
70
+ drb (2.2.1)
71
+ erubi (1.13.0)
72
+ i18n (1.14.5)
73
+ concurrent-ruby (~> 1.0)
74
+ io-console (0.7.2)
75
+ irb (1.14.0)
76
+ rdoc (>= 4.0.0)
77
+ reline (>= 0.4.2)
78
+ json (2.7.2)
79
+ language_server-protocol (3.17.0.3)
80
+ lint_roller (1.1.0)
81
+ loofah (2.22.0)
82
+ crass (~> 1.0.2)
83
+ nokogiri (>= 1.12.0)
84
+ matrix (0.4.2)
85
+ mini_mime (1.1.5)
86
+ minitest (5.24.1)
87
+ minitest-reporters (1.7.1)
88
+ ansi
89
+ builder
90
+ minitest (>= 5.0)
91
+ ruby-progressbar
92
+ mutex_m (0.2.0)
93
+ nokogiri (1.16.7-x86_64-darwin)
94
+ racc (~> 1.4)
95
+ parallel (1.25.1)
96
+ parser (3.3.4.0)
97
+ ast (~> 2.4.1)
98
+ racc
99
+ phlex (1.11.0)
100
+ phlex-testing-capybara (0.1.0)
101
+ capybara (~> 3.38)
102
+ phlex (>= 0.5)
103
+ psych (5.1.2)
104
+ stringio
105
+ public_suffix (6.0.1)
106
+ racc (1.8.1)
107
+ rack (3.1.7)
108
+ rack-session (2.0.0)
109
+ rack (>= 3.0.0)
110
+ rack-test (2.1.0)
111
+ rack (>= 1.3)
112
+ rackup (2.1.0)
113
+ rack (>= 3)
114
+ webrick (~> 1.8)
115
+ rails-dom-testing (2.2.0)
116
+ activesupport (>= 5.0.0)
117
+ minitest
118
+ nokogiri (>= 1.6)
119
+ rails-html-sanitizer (1.6.0)
120
+ loofah (~> 2.21)
121
+ nokogiri (~> 1.14)
122
+ railties (7.1.3.4)
123
+ actionpack (= 7.1.3.4)
124
+ activesupport (= 7.1.3.4)
125
+ irb
126
+ rackup (>= 1.0.0)
127
+ rake (>= 12.2)
128
+ thor (~> 1.0, >= 1.2.2)
129
+ zeitwerk (~> 2.6)
130
+ rainbow (3.1.1)
131
+ rake (13.2.1)
132
+ rdoc (6.7.0)
133
+ psych (>= 4.0.0)
134
+ regexp_parser (2.9.2)
135
+ reline (0.5.9)
136
+ io-console (~> 0.5)
137
+ rexml (3.3.2)
138
+ strscan
139
+ rubocop (1.64.1)
140
+ json (~> 2.3)
141
+ language_server-protocol (>= 3.17.0)
142
+ parallel (~> 1.10)
143
+ parser (>= 3.3.0.2)
144
+ rainbow (>= 2.2.2, < 4.0)
145
+ regexp_parser (>= 1.8, < 3.0)
146
+ rexml (>= 3.2.5, < 4.0)
147
+ rubocop-ast (>= 1.31.1, < 2.0)
148
+ ruby-progressbar (~> 1.7)
149
+ unicode-display_width (>= 2.4.0, < 3.0)
150
+ rubocop-ast (1.31.3)
151
+ parser (>= 3.3.1.0)
152
+ rubocop-performance (1.21.1)
153
+ rubocop (>= 1.48.1, < 2.0)
154
+ rubocop-ast (>= 1.31.1, < 2.0)
155
+ ruby-progressbar (1.13.0)
156
+ standard (1.39.2)
157
+ language_server-protocol (~> 3.17.0.2)
158
+ lint_roller (~> 1.0)
159
+ rubocop (~> 1.64.0)
160
+ standard-custom (~> 1.0.0)
161
+ standard-performance (~> 1.4)
162
+ standard-custom (1.0.2)
163
+ lint_roller (~> 1.0)
164
+ rubocop (~> 1.50)
165
+ standard-performance (1.4.0)
166
+ lint_roller (~> 1.1)
167
+ rubocop-performance (~> 1.21.0)
168
+ stringio (3.1.1)
169
+ strscan (3.1.0)
170
+ thor (1.3.1)
171
+ tzinfo (2.0.6)
172
+ concurrent-ruby (~> 1.0)
173
+ unicode-display_width (2.5.0)
174
+ webrick (1.8.1)
175
+ xpath (3.2.0)
176
+ nokogiri (~> 1.8)
177
+ zeitwerk (2.6.17)
178
+
179
+ PLATFORMS
180
+ x86_64-darwin
181
+
182
+ DEPENDENCIES
183
+ appraisal
184
+ bundle-audit
185
+ combustion
186
+ minitest
187
+ minitest-reporters
188
+ phlex-testing-capybara
189
+ phlexi-form!
190
+ rake
191
+ standard
192
+
193
+ BUNDLED WITH
194
+ 2.5.16
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 7.1.3", ">= 7.1.3.4"
6
+ gem "sqlite3", "~> 1.4"
7
+
8
+ gemspec path: "../"