labelled_form 0.3.2 → 0.3.3
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 +102 -104
- 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: 9ec298f96f953aad1ad198a45a75611a7a3a27652fae73aa935975396f9c9d56
|
4
|
+
data.tar.gz: 2f4960bcaf2112185a3672b16d63a9d624aedad392f69cbc4eeca562e280242a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd404ae96eea31826c3d853e6de81a69f07ff5d66c9c50d22642c9ba0232a936fe40658a6b797c2478fb51b2913f62ccfa5d18f19adb5506f5d646e678d4b548
|
7
|
+
data.tar.gz: bc872bd571500ab766ea0e6eb5573d3f1c7b2b1e116e01df38edfe1c80ae783ea88243d37590f9b3b23d58696b3ed83158ffa3f7aac7dc9c67a30cb8121f1911
|
data/lib/labelled_form.rb
CHANGED
@@ -2,151 +2,149 @@ 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 text_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 file_field method, options = {}
|
73
|
+
with_label(method, options) do
|
74
|
+
super
|
77
75
|
end
|
76
|
+
end
|
78
77
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
78
|
+
def select(method, choices = nil, options = {}, html_options = {}, &block)
|
79
|
+
label_options = (options.keys & %i[wrap_in_dfn label_class label_with_colon label]).any? ? options : html_options
|
80
|
+
with_label(method, label_options) do
|
81
|
+
super
|
84
82
|
end
|
83
|
+
end
|
85
84
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
end
|
85
|
+
def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
|
86
|
+
label_options = (options.keys & %i[wrap_in_dfn label_class label_with_colon label]).any? ? options : html_options
|
87
|
+
with_label(method, label_options) do
|
88
|
+
super
|
91
89
|
end
|
90
|
+
end
|
92
91
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
end
|
92
|
+
def number_field method, options = {}
|
93
|
+
with_label(method, options) do
|
94
|
+
super
|
97
95
|
end
|
96
|
+
end
|
98
97
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
98
|
+
def radio_button(method, tag_value, options = {})
|
99
|
+
options = options.dup
|
100
|
+
label_text = options.delete(:label)
|
101
|
+
label_class = options.delete(:label_class)
|
102
|
+
super.tap do |out|
|
103
|
+
if label_text
|
104
|
+
label_text = tag_value if label_text === true
|
105
|
+
out << " ".html_safe
|
106
|
+
out << label(method, label_text, value: tag_value, class: label_class)
|
109
107
|
end
|
110
108
|
end
|
109
|
+
end
|
111
110
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
end
|
111
|
+
def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
|
112
|
+
options = options.dup
|
113
|
+
label_text = options.delete(:label)
|
114
|
+
label_class = options.delete(:label_class)
|
115
|
+
super.tap do |out|
|
116
|
+
if label_text
|
117
|
+
label_text = checked_value == "1" ? nil : checked_value if label_text === true
|
118
|
+
out << " ".html_safe
|
119
|
+
label_options = options[:multiple] ? { value: checked_value } : {}
|
120
|
+
out << label(method, label_text, label_options.merge(class: label_class))
|
123
121
|
end
|
124
122
|
end
|
123
|
+
end
|
125
124
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
if !multiple_check_box_fields.include?(method)
|
133
|
-
multiple_check_box_fields << method
|
134
|
-
out << hidden_field(method, value: "", multiple: true)
|
135
|
-
end
|
125
|
+
def multiple_check_box method, value, options={}
|
126
|
+
options = options.dup
|
127
|
+
label_text = options.delete(:label)
|
128
|
+
label_class = options.delete(:label_class)
|
129
|
+
out = "".html_safe
|
136
130
|
|
137
|
-
|
131
|
+
if !multiple_check_box_fields.include?(method)
|
132
|
+
multiple_check_box_fields << method
|
133
|
+
out << hidden_field(method, value: "", multiple: true)
|
134
|
+
end
|
138
135
|
|
139
|
-
|
140
|
-
label_text = value == "1" ? nil : value if label_text === true
|
141
|
-
out << " ".html_safe
|
142
|
-
out << label(method, label_text, value: value, class: label_class)
|
143
|
-
end
|
136
|
+
out << check_box(method, { multiple: true }.reverse_merge(options), value, nil)
|
144
137
|
|
145
|
-
|
138
|
+
if label_text
|
139
|
+
label_text = value == "1" ? nil : value if label_text === true
|
140
|
+
out << " ".html_safe
|
141
|
+
out << label(method, label_text, value: value, class: label_class)
|
146
142
|
end
|
147
143
|
|
148
|
-
|
149
|
-
|
150
|
-
|
144
|
+
out
|
145
|
+
end
|
146
|
+
|
147
|
+
private def multiple_check_box_fields
|
148
|
+
@multiple_check_box_fields ||= Set.new
|
151
149
|
end
|
152
150
|
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.3
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|