superform 0.6.0 → 0.6.1
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/superform/field.rb +22 -0
- data/lib/superform/rails/field.rb +137 -0
- data/lib/superform/rails/form.rb +18 -129
- data/lib/superform/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: accaaea2d3dd94355732e750093516e12c4dd1b113fcaecf6aae4f3cce30139d
|
4
|
+
data.tar.gz: 9696d2b2de96dda5d6a7a4c80c23aaed95e3db27223daf6b1744bd5cbe842417
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6bfa1a54025fce5d9caabafce96fdad1564bbdc95eaf1e7b8959d3fd7c021c595ac66de5da05cc511631f85f1791ed501a0ec7c973705712b227fa04cc4ba04
|
7
|
+
data.tar.gz: c908864725edfc61446f4bbf678758b4efb4a171dd2634ea96d423876e3b36b3356842b075372c9559201bef26d170c3f10e696d26928841ca413d7476106593
|
data/Gemfile.lock
CHANGED
data/lib/superform/field.rb
CHANGED
@@ -42,6 +42,28 @@ module Superform
|
|
42
42
|
self
|
43
43
|
end
|
44
44
|
|
45
|
+
# A helper, borrowed from Phlex, that makes it easy to "grab" values
|
46
|
+
# passed into a method that are reserved keywords. For example, this
|
47
|
+
# would throw a syntax error because `class` and `end` are reserved:
|
48
|
+
#
|
49
|
+
# def foo(end:, class:)
|
50
|
+
# puts class
|
51
|
+
# puts end
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# So you "grab" them like this:
|
55
|
+
# def foo(end:, class:)
|
56
|
+
# puts grab(end:)
|
57
|
+
# puts grab(class:)
|
58
|
+
# end
|
59
|
+
private def grab(**bindings)
|
60
|
+
if bindings.size > 1
|
61
|
+
bindings.values
|
62
|
+
else
|
63
|
+
bindings.values.first
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
45
67
|
# High-performance Kit proxy that wraps field methods with form.render calls.
|
46
68
|
# Uses Ruby class hooks to define methods at the class level for maximum speed:
|
47
69
|
# - Methods are defined once per Field class, not per Kit instance
|
@@ -0,0 +1,137 @@
|
|
1
|
+
module Superform
|
2
|
+
module Rails
|
3
|
+
# The Field class is designed to be extended to create custom forms. To override,
|
4
|
+
# in your subclass you may have something like this:
|
5
|
+
#
|
6
|
+
# ```ruby
|
7
|
+
# class MyForm < Superform::Rails::Form
|
8
|
+
# class MyLabel < Superform::Rails::Components::Label
|
9
|
+
# def view_template(&content)
|
10
|
+
# label(form: @field.dom.name, class: "text-bold", &content)
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# class Field < Field
|
15
|
+
# def label(**, &)
|
16
|
+
# MyLabel.new(self, **, &)
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# def input(class: nil, **)
|
20
|
+
# super(class: ["input input-outline", grab(class:)])
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
# ```
|
25
|
+
#
|
26
|
+
# Now all calls to `label` will have the `text-bold` class applied to it.
|
27
|
+
class Field < Superform::Field
|
28
|
+
def button(**attributes)
|
29
|
+
Components::Button.new(field, attributes:)
|
30
|
+
end
|
31
|
+
|
32
|
+
def input(**attributes)
|
33
|
+
Components::Input.new(field, attributes:)
|
34
|
+
end
|
35
|
+
|
36
|
+
def checkbox(**attributes)
|
37
|
+
Components::Checkbox.new(field, attributes:)
|
38
|
+
end
|
39
|
+
|
40
|
+
def label(**attributes, &)
|
41
|
+
Components::Label.new(field, attributes:, &)
|
42
|
+
end
|
43
|
+
|
44
|
+
def textarea(**attributes)
|
45
|
+
Components::Textarea.new(field, attributes:)
|
46
|
+
end
|
47
|
+
|
48
|
+
def select(*collection, **attributes, &)
|
49
|
+
Components::Select.new(field, attributes:, collection:, &)
|
50
|
+
end
|
51
|
+
|
52
|
+
# HTML5 input type convenience methods - clean API without _field suffix
|
53
|
+
# Examples:
|
54
|
+
# field(:email).email(class: "form-input")
|
55
|
+
# field(:age).number(min: 18, max: 99)
|
56
|
+
# field(:birthday).date
|
57
|
+
# field(:secret).hidden(value: "token123")
|
58
|
+
# field(:gender).radio("male", id: "user_gender_male")
|
59
|
+
def text(*, **, &)
|
60
|
+
input(*, **, type: :text, &)
|
61
|
+
end
|
62
|
+
|
63
|
+
def hidden(*, **, &)
|
64
|
+
input(*, **, type: :hidden, &)
|
65
|
+
end
|
66
|
+
|
67
|
+
def password(*, **, &)
|
68
|
+
input(*, **, type: :password, &)
|
69
|
+
end
|
70
|
+
|
71
|
+
def email(*, **, &)
|
72
|
+
input(*, **, type: :email, &)
|
73
|
+
end
|
74
|
+
|
75
|
+
def url(*, **, &)
|
76
|
+
input(*, **, type: :url, &)
|
77
|
+
end
|
78
|
+
|
79
|
+
def tel(*, **, &)
|
80
|
+
input(*, **, type: :tel, &)
|
81
|
+
end
|
82
|
+
alias_method :phone, :tel
|
83
|
+
|
84
|
+
def number(*, **, &)
|
85
|
+
input(*, **, type: :number, &)
|
86
|
+
end
|
87
|
+
|
88
|
+
def range(*, **, &)
|
89
|
+
input(*, **, type: :range, &)
|
90
|
+
end
|
91
|
+
|
92
|
+
def date(*, **, &)
|
93
|
+
input(*, **, type: :date, &)
|
94
|
+
end
|
95
|
+
|
96
|
+
def time(*, **, &)
|
97
|
+
input(*, **, type: :time, &)
|
98
|
+
end
|
99
|
+
|
100
|
+
def datetime(*, **, &)
|
101
|
+
input(*, **, type: :"datetime-local", &)
|
102
|
+
end
|
103
|
+
|
104
|
+
def month(*, **, &)
|
105
|
+
input(*, **, type: :month, &)
|
106
|
+
end
|
107
|
+
|
108
|
+
def week(*, **, &)
|
109
|
+
input(*, **, type: :week, &)
|
110
|
+
end
|
111
|
+
|
112
|
+
def color(*, **, &)
|
113
|
+
input(*, **, type: :color, &)
|
114
|
+
end
|
115
|
+
|
116
|
+
def search(*, **, &)
|
117
|
+
input(*, **, type: :search, &)
|
118
|
+
end
|
119
|
+
|
120
|
+
def file(*, **, &)
|
121
|
+
input(*, **, type: :file, &)
|
122
|
+
end
|
123
|
+
|
124
|
+
def radio(value, *, **, &)
|
125
|
+
input(*, **, type: :radio, value: value, &)
|
126
|
+
end
|
127
|
+
|
128
|
+
# Rails compatibility aliases
|
129
|
+
alias_method :check_box, :checkbox
|
130
|
+
alias_method :text_area, :textarea
|
131
|
+
|
132
|
+
def title
|
133
|
+
key.to_s.titleize
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
data/lib/superform/rails/form.rb
CHANGED
@@ -14,146 +14,35 @@ module Superform
|
|
14
14
|
include Phlex::Rails::Helpers::FormAuthenticityToken
|
15
15
|
include Phlex::Rails::Helpers::URLFor
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
:Field,
|
21
|
-
:field,
|
22
|
-
:collection,
|
23
|
-
:namespace,
|
24
|
-
:assign,
|
25
|
-
:serialize,
|
26
|
-
to: :@namespace
|
27
|
-
|
28
|
-
# The Field class is designed to be extended to create custom forms. To override,
|
29
|
-
# in your subclass you may have something like this:
|
17
|
+
# The `Field` class is nested inside the `Form` class so it can be easily extended
|
18
|
+
# to customize the form inputs for your application. For example, if you wanted to
|
19
|
+
# add some default classes to all your inputs and labels you could do something like:
|
30
20
|
#
|
31
21
|
# ```ruby
|
32
22
|
# class MyForm < Superform::Rails::Form
|
33
|
-
# class
|
34
|
-
# def
|
35
|
-
#
|
23
|
+
# class Field < self::Field
|
24
|
+
# def input(**attributes)
|
25
|
+
# super(class: "input input-bordered", **attributes)
|
36
26
|
# end
|
37
|
-
# end
|
38
27
|
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
# MyLabel.new(self, **attributes)
|
28
|
+
# def label(**attributes, &block)
|
29
|
+
# super(class: "label", **attributes, &block)
|
42
30
|
# end
|
43
31
|
# end
|
44
32
|
# end
|
45
33
|
# ```
|
46
|
-
|
47
|
-
# Now all calls to `label` will have the `text-bold` class applied to it.
|
48
|
-
class Field < Superform::Field
|
49
|
-
def button(**attributes)
|
50
|
-
Components::Button.new(self, attributes:)
|
51
|
-
end
|
52
|
-
|
53
|
-
def input(**attributes)
|
54
|
-
Components::Input.new(self, attributes:)
|
55
|
-
end
|
56
|
-
|
57
|
-
def text(*, **, &)
|
58
|
-
input(*, **, type: :text, &)
|
59
|
-
end
|
34
|
+
Field = Superform::Rails::Field
|
60
35
|
|
61
|
-
|
62
|
-
Components::Checkbox.new(self, attributes:)
|
63
|
-
end
|
64
|
-
|
65
|
-
def label(**attributes, &)
|
66
|
-
Components::Label.new(self, attributes:, &)
|
67
|
-
end
|
68
|
-
|
69
|
-
def textarea(**attributes)
|
70
|
-
Components::Textarea.new(self, attributes:)
|
71
|
-
end
|
72
|
-
|
73
|
-
def select(*collection, **attributes, &)
|
74
|
-
Components::Select.new(self, attributes:, collection:, &)
|
75
|
-
end
|
76
|
-
|
77
|
-
# HTML5 input type convenience methods - clean API without _field suffix
|
78
|
-
# Examples:
|
79
|
-
# field(:email).email(class: "form-input")
|
80
|
-
# field(:age).number(min: 18, max: 99)
|
81
|
-
# field(:birthday).date
|
82
|
-
# field(:secret).hidden(value: "token123")
|
83
|
-
# field(:gender).radio("male", id: "user_gender_male")
|
84
|
-
def hidden(*, **, &)
|
85
|
-
input(*, **, type: :hidden, &)
|
86
|
-
end
|
87
|
-
|
88
|
-
def password(*, **, &)
|
89
|
-
input(*, **, type: :password, &)
|
90
|
-
end
|
91
|
-
|
92
|
-
def email(*, **, &)
|
93
|
-
input(*, **, type: :email, &)
|
94
|
-
end
|
95
|
-
|
96
|
-
def url(*, **, &)
|
97
|
-
input(*, **, type: :url, &)
|
98
|
-
end
|
99
|
-
|
100
|
-
def tel(*, **, &)
|
101
|
-
input(*, **, type: :tel, &)
|
102
|
-
end
|
103
|
-
alias_method :phone, :tel
|
104
|
-
|
105
|
-
def number(*, **, &)
|
106
|
-
input(*, **, type: :number, &)
|
107
|
-
end
|
108
|
-
|
109
|
-
def range(*, **, &)
|
110
|
-
input(*, **, type: :range, &)
|
111
|
-
end
|
112
|
-
|
113
|
-
def date(*, **, &)
|
114
|
-
input(*, **, type: :date, &)
|
115
|
-
end
|
116
|
-
|
117
|
-
def time(*, **, &)
|
118
|
-
input(*, **, type: :time, &)
|
119
|
-
end
|
120
|
-
|
121
|
-
def datetime(*, **, &)
|
122
|
-
input(*, **, type: :"datetime-local", &)
|
123
|
-
end
|
124
|
-
|
125
|
-
def month(*, **, &)
|
126
|
-
input(*, **, type: :month, &)
|
127
|
-
end
|
128
|
-
|
129
|
-
def week(*, **, &)
|
130
|
-
input(*, **, type: :week, &)
|
131
|
-
end
|
132
|
-
|
133
|
-
def color(*, **, &)
|
134
|
-
input(*, **, type: :color, &)
|
135
|
-
end
|
136
|
-
|
137
|
-
def search(*, **, &)
|
138
|
-
input(*, **, type: :search, &)
|
139
|
-
end
|
140
|
-
|
141
|
-
def file(*, **, &)
|
142
|
-
input(*, **, type: :file, &)
|
143
|
-
end
|
144
|
-
|
145
|
-
def radio(value, *, **, &)
|
146
|
-
input(*, **, type: :radio, value: value, &)
|
147
|
-
end
|
148
|
-
|
149
|
-
# Rails compatibility aliases
|
150
|
-
alias_method :check_box, :checkbox
|
151
|
-
alias_method :text_area, :textarea
|
36
|
+
attr_accessor :model
|
152
37
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
38
|
+
delegate \
|
39
|
+
:Field,
|
40
|
+
:field,
|
41
|
+
:collection,
|
42
|
+
:namespace,
|
43
|
+
:assign,
|
44
|
+
:serialize,
|
45
|
+
to: :@namespace
|
157
46
|
|
158
47
|
def build_field(...)
|
159
48
|
self.class::Field.new(...)
|
data/lib/superform/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: superform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Gessler
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 2025-08-29 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: phlex-rails
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- lib/superform/rails/components/label.rb
|
75
75
|
- lib/superform/rails/components/select.rb
|
76
76
|
- lib/superform/rails/components/textarea.rb
|
77
|
+
- lib/superform/rails/field.rb
|
77
78
|
- lib/superform/rails/form.rb
|
78
79
|
- lib/superform/rails/option_mapper.rb
|
79
80
|
- lib/superform/rails/strong_parameters.rb
|
@@ -101,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
102
|
- !ruby/object:Gem::Version
|
102
103
|
version: '0'
|
103
104
|
requirements: []
|
104
|
-
rubygems_version: 3.6.
|
105
|
+
rubygems_version: 3.6.2
|
105
106
|
specification_version: 4
|
106
107
|
summary: Build forms in Rails
|
107
108
|
test_files: []
|