labelled_form 0.3.1 → 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 +103 -106
- metadata +3 -3
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
@@ -1,153 +1,150 @@
|
|
1
1
|
require "labelled_form/version"
|
2
|
-
require "action_view"
|
3
2
|
|
4
3
|
module LabelledForm
|
5
4
|
class Rails < ::Rails::Engine
|
6
|
-
initializer "
|
7
|
-
ActionView::Base.default_form_builder
|
5
|
+
initializer "labeled_form.extend_form_builder" do
|
6
|
+
ActionView::Base.default_form_builder.prepend LabelledForm
|
8
7
|
end
|
9
|
-
end
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
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
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
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?(":")
|
21
19
|
|
22
|
-
|
20
|
+
field_html = yield
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
else
|
31
|
-
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)
|
32
27
|
end
|
33
28
|
else
|
34
|
-
field_html
|
29
|
+
label(method, label_text, class: label_class) + " ".html_safe + field_html
|
35
30
|
end
|
31
|
+
else
|
32
|
+
field_html
|
36
33
|
end
|
34
|
+
end
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
36
|
+
def text_area method, options = {}
|
37
|
+
with_label(method, options) do
|
38
|
+
super
|
42
39
|
end
|
40
|
+
end
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
42
|
+
def date_field method, options = {}
|
43
|
+
with_label(method, options) do
|
44
|
+
super
|
48
45
|
end
|
46
|
+
end
|
49
47
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
end
|
48
|
+
def phone_field method, options = {}
|
49
|
+
with_label(method, options) do
|
50
|
+
super
|
54
51
|
end
|
52
|
+
end
|
55
53
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
54
|
+
def email_field method, options = {}
|
55
|
+
with_label(method, options) do
|
56
|
+
super
|
60
57
|
end
|
58
|
+
end
|
61
59
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
60
|
+
def url_field method, options = {}
|
61
|
+
with_label(method, options) do
|
62
|
+
super
|
66
63
|
end
|
64
|
+
end
|
67
65
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
66
|
+
def text_field method, options = {}
|
67
|
+
with_label(method, options) do
|
68
|
+
super
|
72
69
|
end
|
70
|
+
end
|
73
71
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
end
|
72
|
+
def file_field method, options = {}
|
73
|
+
with_label(method, options) do
|
74
|
+
super
|
78
75
|
end
|
76
|
+
end
|
79
77
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
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
|
85
82
|
end
|
83
|
+
end
|
86
84
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
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
|
92
89
|
end
|
90
|
+
end
|
93
91
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
92
|
+
def number_field method, options = {}
|
93
|
+
with_label(method, options) do
|
94
|
+
super
|
98
95
|
end
|
96
|
+
end
|
99
97
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
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)
|
110
107
|
end
|
111
108
|
end
|
109
|
+
end
|
112
110
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
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))
|
124
121
|
end
|
125
122
|
end
|
123
|
+
end
|
126
124
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
if !multiple_check_box_fields.include?(method)
|
134
|
-
multiple_check_box_fields << method
|
135
|
-
out << hidden_field(method, value: "", multiple: true)
|
136
|
-
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
|
137
130
|
|
138
|
-
|
131
|
+
if !multiple_check_box_fields.include?(method)
|
132
|
+
multiple_check_box_fields << method
|
133
|
+
out << hidden_field(method, value: "", multiple: true)
|
134
|
+
end
|
139
135
|
|
140
|
-
|
141
|
-
label_text = value == "1" ? nil : value if label_text === true
|
142
|
-
out << " ".html_safe
|
143
|
-
out << label(method, label_text, value: value, class: label_class)
|
144
|
-
end
|
136
|
+
out << check_box(method, { multiple: true }.reverse_merge(options), value, nil)
|
145
137
|
|
146
|
-
|
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)
|
147
142
|
end
|
148
143
|
|
149
|
-
|
150
|
-
|
151
|
-
|
144
|
+
out
|
145
|
+
end
|
146
|
+
|
147
|
+
private def multiple_check_box_fields
|
148
|
+
@multiple_check_box_fields ||= Set.new
|
152
149
|
end
|
153
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:
|
11
|
+
date: 2024-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
|
-
rubygems_version: 3.
|
107
|
+
rubygems_version: 3.2.32
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: Adds label option to Rails form helpers
|