asbru 0.0.11 → 0.0.14

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: 45ab6b9c6737f74c9bc7b395f1bd7df468feb923ccdc07b09f51ddd9d39c90fd
4
- data.tar.gz: ef4da4d80683a0bfb4a24701ce22d4f2bb231f2c6b8f530e048cc3bfa372118a
3
+ metadata.gz: fd4c1c21cfc657365e3104fd7b9eb887d9c6345338fa9e36d0e96f9eacce0b56
4
+ data.tar.gz: d8af286deb359f0faf17874965bba84f7b611b2d36232996ecafd1a84e204f58
5
5
  SHA512:
6
- metadata.gz: c924577583ce3eeb2734aa77d90c13de7a3866b7a0626f737c7015151cca29c05d307c131bf3c624092d1232257caa9db8adaa3832eed5f03d8fcf1aa697d960
7
- data.tar.gz: f600444f70190663de4c021da4bc0f353aec551be1b151cbfab95754c0bf32d1d12b273ab5a886c5238006d7d00a52b2081fd97a701f44903a01065c0944cd54
6
+ metadata.gz: 2cd056d9f3b78fd898029be1442b8fba37f83b299879005b82ddd4c258465e7dcd4f8fa34da827182ab0723919afaab0708563ee2b31dce5dbffdb22800719ed
7
+ data.tar.gz: b5f9e669395c09a13dea89ac12065a810b88ab6cdc22e58560d89fe668fc619cf347c142c58c605b91258eeb65536f6aac43bb2461aa6153346d328e830338ac
@@ -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
- _options,
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,79 @@ 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
+ attachmentDeletionKey: tag_name_for("_delete_#{attribute}"),
168
+ **options
169
+ }
170
+
171
+ if @object.present? && attribute.present?
172
+ options[:label] ||= I18n.t(attribute,
173
+ scope: "activerecord.attributes.#{@object.class.name.downcase}")
174
+
175
+ attachment = @object.send(attribute)
176
+ if attachment.present?
177
+ options['incommingFile'] = {
178
+ name: attachment.filename,
179
+ size: attachment.send('byte_size'),
180
+ type: attachment.content_type
181
+ }
182
+ end
183
+ end
184
+
185
+ Asbru::Components::Savage.send "#{Asbru.config.form_builder_prefix}_element",
186
+ **options
187
+ end
188
+
189
+
131
190
  def collection_radio_buttons(attribute,
132
191
  collection,
133
192
  value_method,
@@ -217,5 +276,13 @@ module Asbru
217
276
  def error_icon
218
277
  Asbru.config.default_form_error_icon
219
278
  end
279
+
280
+ def tag_name_for(method, multiple = false)
281
+ name = ActionView::Helpers::Tags::TextField.new(object_name,
282
+ method, {})
283
+ .send(:tag_name)
284
+ name += '[]' if multiple
285
+ name
286
+ end
220
287
  end
221
288
  end
data/lib/asbru/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Asbru
2
- VERSION = '0.0.11'
2
+ VERSION = '0.0.14'
3
3
  end
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.11
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stev-0
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-14 00:00:00.000000000 Z
11
+ date: 2022-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails