asbru 0.0.10 → 0.0.13
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/asbru/form_builder.rb +77 -12
- data/lib/asbru/version.rb +1 -1
- 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: 194c37b9783f53f7b84b39fee486d3c29f9f5a029d918ba1eed7da1ae1d3b87f
|
4
|
+
data.tar.gz: 071ae61b5bb46de918193912dc2da817e8460062892d056f2a4be2cfafca1f57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 466498a7a7062e2ebaa82f228e23e755b776fa97930862da21f81c86ca91dc2313a9004394d62cd3fc807670d70f21545448f4feb42379381ce6bff03f78179d
|
7
|
+
data.tar.gz: d1f6950db689f65b81e018f67007d181e5724433ba0e4e65e72970a1bf82322aed16316439844961042b6565c4f9ad102f22cca67527bc6bcc05d6473938fc22
|
data/lib/asbru/form_builder.rb
CHANGED
@@ -35,7 +35,7 @@ module Asbru
|
|
35
35
|
{ check_box: { type: 'checkbox' } },
|
36
36
|
{ file_field: { type: 'file' } },
|
37
37
|
{ text_field: {} },
|
38
|
-
{ telephone_field: { type: 'tel
|
38
|
+
{ telephone_field: { type: 'tel'}}
|
39
39
|
].freeze
|
40
40
|
|
41
41
|
def errors(name)
|
@@ -45,20 +45,12 @@ module Asbru
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def tag_name_for(method, multiple = false)
|
49
|
-
name = ActionView::Helpers::Tags::TextField.new(object_name,
|
50
|
-
method, {})
|
51
|
-
.send(:tag_name)
|
52
|
-
name += '[]' if multiple
|
53
|
-
name
|
54
|
-
end
|
55
|
-
|
56
48
|
def render_form_element(attribute, options)
|
57
49
|
new_options = options.reverse_merge(
|
58
50
|
{
|
59
51
|
name: tag_name_for(attribute),
|
60
52
|
errors: errors(attribute),
|
61
|
-
errorIcon: error_icon
|
53
|
+
errorIcon: error_icon,
|
62
54
|
}
|
63
55
|
)
|
64
56
|
|
@@ -101,13 +93,13 @@ module Asbru
|
|
101
93
|
collection,
|
102
94
|
value_method,
|
103
95
|
text_method,
|
104
|
-
|
96
|
+
options,
|
105
97
|
multiple = false)
|
106
98
|
collection.map do |item|
|
107
99
|
{
|
108
100
|
label: item.send(text_method),
|
109
101
|
value: item.send(value_method),
|
110
|
-
name: tag_name_for(attribute, multiple),
|
102
|
+
name: options[:name] || tag_name_for(attribute, multiple),
|
111
103
|
checked: if @object.nil?
|
112
104
|
false
|
113
105
|
else
|
@@ -122,12 +114,77 @@ module Asbru
|
|
122
114
|
end
|
123
115
|
end
|
124
116
|
|
117
|
+
# def submit(attribute = nil, options = {})
|
118
|
+
# render_form_element attribute,
|
119
|
+
# options.reverse_merge(text: 'Submit', type: 'submit')
|
120
|
+
# end
|
121
|
+
|
122
|
+
# def date_field(attribute = nil, options = {})
|
123
|
+
# render_form_element attribute,
|
124
|
+
# options.reverse_merge(type: 'datepicker')
|
125
|
+
# end
|
126
|
+
|
127
|
+
# def password_field(attribute = nil, options = {})
|
128
|
+
# render_form_element attribute,
|
129
|
+
# options.reverse_merge(type: 'password')
|
130
|
+
# end
|
131
|
+
|
132
|
+
# def text_area(attribute = nil, options = {})
|
133
|
+
# render_form_element attribute,
|
134
|
+
# options.reverse_merge(type: 'textarea')
|
135
|
+
# end
|
136
|
+
|
137
|
+
# def email_field(attribute = nil, options = {})
|
138
|
+
# render_form_element attribute,
|
139
|
+
# options.reverse_merge(type: 'email')
|
140
|
+
# end
|
141
|
+
|
142
|
+
# def check_box(attribute = nil, options = {})
|
143
|
+
# render_form_element attribute,
|
144
|
+
# options.reverse_merge(type: 'check_box')
|
145
|
+
# end
|
146
|
+
|
147
|
+
# def text_field(attribute = nil, options = {})
|
148
|
+
# render_form_element attribute, options
|
149
|
+
# end
|
150
|
+
|
151
|
+
# def telephone_field
|
152
|
+
# render_form_element attribute,
|
153
|
+
# options.reverse_merge(type: 'tel')
|
154
|
+
# end
|
155
|
+
|
125
156
|
BASIC_FORM_FIELDS.each do |item|
|
126
157
|
define_method item.keys.first do |attribute = nil, options = {}|
|
127
158
|
render_form_element(attribute, options.reverse_merge(item.values.first))
|
128
159
|
end
|
129
160
|
end
|
130
161
|
|
162
|
+
def file_field(attribute = nil, options = {})
|
163
|
+
options = { name: tag_name_for(attribute),
|
164
|
+
errors: errors(attribute),
|
165
|
+
errorIcon: error_icon,
|
166
|
+
type: 'file',
|
167
|
+
**options
|
168
|
+
}
|
169
|
+
if @object.present? && attribute.present?
|
170
|
+
options[:label] ||= I18n.t(attribute,
|
171
|
+
scope: "activerecord.attributes.#{@object.class.name.downcase}")
|
172
|
+
|
173
|
+
attachment = @object.send(attribute)
|
174
|
+
if attachment.present?
|
175
|
+
options['incommingFile'] = {
|
176
|
+
name: attachment.filename,
|
177
|
+
size: attachment.send('byte_size'),
|
178
|
+
type: attachment.content_type
|
179
|
+
}
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
Asbru::Components::Savage.send "#{Asbru.config.form_builder_prefix}_element",
|
184
|
+
**options
|
185
|
+
end
|
186
|
+
|
187
|
+
|
131
188
|
def collection_radio_buttons(attribute,
|
132
189
|
collection,
|
133
190
|
value_method,
|
@@ -217,5 +274,13 @@ module Asbru
|
|
217
274
|
def error_icon
|
218
275
|
Asbru.config.default_form_error_icon
|
219
276
|
end
|
277
|
+
|
278
|
+
def tag_name_for(method, multiple = false)
|
279
|
+
name = ActionView::Helpers::Tags::TextField.new(object_name,
|
280
|
+
method, {})
|
281
|
+
.send(:tag_name)
|
282
|
+
name += '[]' if multiple
|
283
|
+
name
|
284
|
+
end
|
220
285
|
end
|
221
286
|
end
|
data/lib/asbru/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asbru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stev-0
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|