labelled_form 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf2e678a306b64f579f1e9a167d30adf57e88a2dad95e9600fe308346b409fd6
4
- data.tar.gz: 5d618af8d5e5d28ac69bce680c2497645e528bd762d7f1e78c72bd38ad4605ca
3
+ metadata.gz: 9ec298f96f953aad1ad198a45a75611a7a3a27652fae73aa935975396f9c9d56
4
+ data.tar.gz: 2f4960bcaf2112185a3672b16d63a9d624aedad392f69cbc4eeca562e280242a
5
5
  SHA512:
6
- metadata.gz: f3f3b2b4a8c57dfa5db9a0303a425a591f00cf2fafc1c8c004eff1d37052eb5648b04aa9069e6d6ef1bad79019f3170100c535182b1dec8d652312efab17177c
7
- data.tar.gz: b71ef44c740f78dd190a3c64242c63d784a04be8dab2cda2f1ca1d814ca9ad1b9d66af96f39770a718f5b826b404f4c472aef0a0672af5e9db62b2a2fa0c398f
6
+ metadata.gz: cd404ae96eea31826c3d853e6de81a69f07ff5d66c9c50d22642c9ba0232a936fe40658a6b797c2478fb51b2913f62ccfa5d18f19adb5506f5d646e678d4b548
7
+ data.tar.gz: bc872bd571500ab766ea0e6eb5573d3f1c7b2b1e116e01df38edfe1c80ae783ea88243d37590f9b3b23d58696b3ed83158ffa3f7aac7dc9c67a30cb8121f1911
@@ -1,3 +1,3 @@
1
1
  module LabelledForm
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
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
- config.after_initialize do
6
- ActionView::Base.default_form_builder.include FormBuilder
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
- module FormBuilder
11
- def with_label method, options
12
- wrap_in_dfn = options.delete(:wrap_in_dfn)
13
- label_class = options.delete(:label_class)
14
- label_with_colon = options.delete(:label_with_colon)
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
- label_text = method.to_s.humanize if label_text === true
18
- label_text&.sub!(/_id$/,"")
19
- label_text << ":" if label_with_colon && !label_text.ends_with?(":")
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
- field_html = yield
20
+ field_html = yield
22
21
 
23
- if label_text
24
- if wrap_in_dfn
25
- @template.tag.dfn do
26
- @template.tag.dt(label(method, label_text, class: label_class)) +
27
- @template.tag.dd(field_html)
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
- def text_area method, options = {}
38
- with_label(method, options) do
39
- super
40
- end
36
+ def text_area method, options = {}
37
+ with_label(method, options) do
38
+ super
41
39
  end
40
+ end
42
41
 
43
- def date_field method, options = {}
44
- with_label(method, options) do
45
- super
46
- end
42
+ def date_field method, options = {}
43
+ with_label(method, options) do
44
+ super
47
45
  end
46
+ end
48
47
 
49
- def phone_field method, options = {}
50
- with_label(method, options) do
51
- super
52
- end
48
+ def phone_field method, options = {}
49
+ with_label(method, options) do
50
+ super
53
51
  end
52
+ end
54
53
 
55
- def email_field method, options = {}
56
- with_label(method, options) do
57
- super
58
- end
54
+ def email_field method, options = {}
55
+ with_label(method, options) do
56
+ super
59
57
  end
58
+ end
60
59
 
61
- def url_field method, options = {}
62
- with_label(method, options) do
63
- super
64
- end
60
+ def url_field method, options = {}
61
+ with_label(method, options) do
62
+ super
65
63
  end
64
+ end
66
65
 
67
- def text_field method, options = {}
68
- with_label(method, options) do
69
- super
70
- end
66
+ def text_field method, options = {}
67
+ with_label(method, options) do
68
+ super
71
69
  end
70
+ end
72
71
 
73
- def file_field method, options = {}
74
- with_label(method, options) do
75
- super
76
- end
72
+ def file_field method, options = {}
73
+ with_label(method, options) do
74
+ super
77
75
  end
76
+ end
78
77
 
79
- def select(method, choices = nil, options = {}, html_options = {}, &block)
80
- label_options = (options.keys & %i[wrap_in_dfn label_class label_with_colon label]).any? ? options : html_options
81
- with_label(method, label_options) do
82
- super
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
- def collection_select(method, collection, value_method, text_method, options = {}, html_options = {})
87
- label_options = (options.keys & %i[wrap_in_dfn label_class label_with_colon label]).any? ? options : html_options
88
- with_label(method, label_options) do
89
- super
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
- def number_field method, options = {}
94
- with_label(method, options) do
95
- super
96
- end
92
+ def number_field method, options = {}
93
+ with_label(method, options) do
94
+ super
97
95
  end
96
+ end
98
97
 
99
- def radio_button(method, tag_value, options = {})
100
- options = options.dup
101
- label_text = options.delete(:label)
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
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
- def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
113
- options = options.dup
114
- label_text = options.delete(:label)
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
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
- def multiple_check_box method, value, options={}
127
- options = options.dup
128
- label_text = options.delete(:label)
129
- label_class = options.delete(:label_class)
130
- out = "".html_safe
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
- out << check_box(method, { multiple: true }.reverse_merge(options), value, nil)
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
- if label_text
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
- out
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
- private def multiple_check_box_fields
149
- @multiple_check_box_fields ||= Set.new
150
- end
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.2
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-19 00:00:00.000000000 Z
11
+ date: 2024-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview