labelled_form 0.3.2 → 0.3.4
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/lib/labelled_form/version.rb +1 -1
- data/lib/labelled_form.rb +112 -102
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a1280a6bebb9d597a15f992956eae560c7bcd104709849e046ee6f70258ee14
|
4
|
+
data.tar.gz: 398f8e56bf0b6630c52b2e26bdd4c562b3c95aca05942ee39d14a2f5fa87e6ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49fe9412c9082aa06b950e47b14b4c3a29ec66b622460a072581f1bd70ecfdba92bdd6b26056d116f787d463cca4a3a7ec974ac281b28164575302eb6db32019
|
7
|
+
data.tar.gz: 5c0cc1b9c8cffb09036ab46b874e1439c92bfdfdaeff60ffdc073fd04decdac3722fc618f9a8a5f9b8ac30672efc0137f1a8e7ebe57a71501fb0fcc706012cc8
|
data/lib/labelled_form.rb
CHANGED
@@ -2,151 +2,161 @@ require "labelled_form/version"
|
|
2
2
|
|
3
3
|
module LabelledForm
|
4
4
|
class Rails < ::Rails::Engine
|
5
|
-
|
6
|
-
ActionView::Base.default_form_builder.
|
5
|
+
initializer "labeled_form.extend_form_builder" do
|
6
|
+
ActionView::Base.default_form_builder.prepend LabelledForm
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
label_text = options.delete(:label) || label_class.present? || label_with_colon
|
10
|
+
def with_label method, options
|
11
|
+
wrap_in_dfn = options.delete(:wrap_in_dfn)
|
12
|
+
label_class = options.delete(:label_class)
|
13
|
+
label_with_colon = options.delete(:label_with_colon)
|
14
|
+
label_text = options.delete(:label) || label_class.present? || label_with_colon
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
label_text = method.to_s.humanize if label_text === true
|
17
|
+
label_text&.sub!(/_id$/,"")
|
18
|
+
label_text << ":" if label_with_colon && !label_text.ends_with?(":")
|
20
19
|
|
21
|
-
|
20
|
+
field_html = yield
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
else
|
30
|
-
label(method, label_text, class: label_class) + " ".html_safe + field_html
|
22
|
+
if label_text
|
23
|
+
if wrap_in_dfn
|
24
|
+
@template.tag.dfn do
|
25
|
+
@template.tag.dt(label(method, label_text, class: label_class)) +
|
26
|
+
@template.tag.dd(field_html)
|
31
27
|
end
|
32
28
|
else
|
33
|
-
field_html
|
29
|
+
label(method, label_text, class: label_class) + " ".html_safe + field_html
|
34
30
|
end
|
31
|
+
else
|
32
|
+
field_html
|
35
33
|
end
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
36
|
+
def text_area method, options = {}
|
37
|
+
with_label(method, options) do
|
38
|
+
super
|
41
39
|
end
|
40
|
+
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
42
|
+
def date_field method, options = {}
|
43
|
+
with_label(method, options) do
|
44
|
+
super
|
47
45
|
end
|
46
|
+
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
48
|
+
def phone_field method, options = {}
|
49
|
+
with_label(method, options) do
|
50
|
+
super
|
53
51
|
end
|
52
|
+
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
54
|
+
def email_field method, options = {}
|
55
|
+
with_label(method, options) do
|
56
|
+
super
|
59
57
|
end
|
58
|
+
end
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
end
|
60
|
+
def url_field method, options = {}
|
61
|
+
with_label(method, options) do
|
62
|
+
super
|
65
63
|
end
|
64
|
+
end
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
66
|
+
def password_field method, options = {}
|
67
|
+
with_label(method, options) do
|
68
|
+
super
|
71
69
|
end
|
70
|
+
end
|
72
71
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
72
|
+
def text_field method, options = {}
|
73
|
+
with_label(method, options) do
|
74
|
+
super
|
77
75
|
end
|
76
|
+
end
|
78
77
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
super
|
83
|
-
end
|
78
|
+
def file_field method, options = {}
|
79
|
+
with_label(method, options) do
|
80
|
+
super
|
84
81
|
end
|
82
|
+
end
|
85
83
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
end
|
84
|
+
def select(method, choices = nil, options = {}, html_options = {}, &block)
|
85
|
+
label_options = (options.keys & %i[wrap_in_dfn label_class label_with_colon label]).any? ? options : html_options
|
86
|
+
with_label(method, label_options) do
|
87
|
+
super
|
91
88
|
end
|
89
|
+
end
|
92
90
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
91
|
+
def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
|
92
|
+
label_options = (options.keys & %i[wrap_in_dfn label_class label_with_colon label]).any? ? options : html_options
|
93
|
+
with_label(method, label_options) do
|
94
|
+
super
|
97
95
|
end
|
96
|
+
end
|
98
97
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
label_class = options.delete(:label_class)
|
103
|
-
super.tap do |out|
|
104
|
-
if label_text
|
105
|
-
label_text = tag_value if label_text === true
|
106
|
-
out << " ".html_safe
|
107
|
-
out << label(method, label_text, value: tag_value, class: label_class)
|
108
|
-
end
|
109
|
-
end
|
98
|
+
def number_field method, options = {}
|
99
|
+
with_label(method, options) do
|
100
|
+
super
|
110
101
|
end
|
102
|
+
end
|
111
103
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
label_class = options.delete(:label_class)
|
116
|
-
super.tap do |out|
|
117
|
-
if label_text
|
118
|
-
label_text = checked_value == "1" ? nil : checked_value if label_text === true
|
119
|
-
out << " ".html_safe
|
120
|
-
label_options = options[:multiple] ? { value: checked_value } : {}
|
121
|
-
out << label(method, label_text, label_options.merge(class: label_class))
|
122
|
-
end
|
123
|
-
end
|
104
|
+
def range_field method, options = {}
|
105
|
+
with_label(method, options) do
|
106
|
+
super
|
124
107
|
end
|
108
|
+
end
|
125
109
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
out <<
|
110
|
+
def radio_button(method, tag_value, options = {})
|
111
|
+
options = options.dup
|
112
|
+
label_text = options.delete(:label)
|
113
|
+
label_class = options.delete(:label_class)
|
114
|
+
super.tap do |out|
|
115
|
+
if label_text
|
116
|
+
label_text = tag_value if label_text === true
|
117
|
+
out << " ".html_safe
|
118
|
+
out << label(method, label_text, value: tag_value, class: label_class)
|
135
119
|
end
|
120
|
+
end
|
121
|
+
end
|
136
122
|
|
137
|
-
|
138
|
-
|
123
|
+
def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
|
124
|
+
options = options.dup
|
125
|
+
label_text = options.delete(:label)
|
126
|
+
label_class = options.delete(:label_class)
|
127
|
+
super.tap do |out|
|
139
128
|
if label_text
|
140
|
-
label_text =
|
129
|
+
label_text = checked_value == "1" ? nil : checked_value if label_text === true
|
141
130
|
out << " ".html_safe
|
142
|
-
|
131
|
+
label_options = options[:multiple] ? { value: checked_value } : {}
|
132
|
+
out << label(method, label_text, label_options.merge(class: label_class))
|
143
133
|
end
|
134
|
+
end
|
135
|
+
end
|
144
136
|
|
145
|
-
|
137
|
+
def multiple_check_box method, value, options={}
|
138
|
+
options = options.dup
|
139
|
+
label_text = options.delete(:label)
|
140
|
+
label_class = options.delete(:label_class)
|
141
|
+
out = "".html_safe
|
142
|
+
|
143
|
+
if !multiple_check_box_fields.include?(method)
|
144
|
+
multiple_check_box_fields << method
|
145
|
+
out << hidden_field(method, value: "", multiple: true)
|
146
146
|
end
|
147
147
|
|
148
|
-
|
149
|
-
|
148
|
+
out << check_box(method, { multiple: true }.reverse_merge(options), value, nil)
|
149
|
+
|
150
|
+
if label_text
|
151
|
+
label_text = value == "1" ? nil : value if label_text === true
|
152
|
+
out << " ".html_safe
|
153
|
+
out << label(method, label_text, value: value, class: label_class)
|
150
154
|
end
|
155
|
+
|
156
|
+
out
|
157
|
+
end
|
158
|
+
|
159
|
+
private def multiple_check_box_fields
|
160
|
+
@multiple_check_box_fields ||= Set.new
|
151
161
|
end
|
152
162
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: labelled_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micah Geisel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|